当前位置:网站首页>Flutter Getting Started and Advanced Tour (7) GestureDetector
Flutter Getting Started and Advanced Tour (7) GestureDetector
2022-08-09 13:24:00 【Xie Dong_】
引言:
GestureDetector在Flutter中负责处理跟用户的简单手势交互,GestureDetectorControl without images show,Just detection of user input gesture,并作出相应的处理,包括点击、拖动和缩放.Many controls useGestureDetectorTo provide other controls callback,比如IconButton、RaisedButton和FloatingActionButton控件有onPressed回调,当用户点击控件时触发回调,当用户点击控件时触发回调.
我们来一起看下GestureDetector的构造方法:
GestureDetector({
Key key,
this.child,
this.onTapDown,
this.onTapUp,
this.onTap,
this.onTapCancel,
this.onDoubleTap,
this.onLongPress,
this.onLongPressUp,
this.onVerticalDragDown,
this.onVerticalDragStart,
this.onVerticalDragUpdate,
this.onVerticalDragEnd,
this.onVerticalDragCancel,
this.onHorizontalDragDown,
this.onHorizontalDragStart,
this.onHorizontalDragUpdate,
this.onHorizontalDragEnd,
this.onHorizontalDragCancel,
this.onForcePressStart,
this.onForcePressPeak,
this.onForcePressUpdate,
this.onForcePressEnd,
this.onPanDown,
this.onPanStart,
this.onPanUpdate,
this.onPanEnd,
this.onPanCancel,
this.onScaleStart,
this.onScaleUpdate,
this.onScaleEnd,
this.behavior,
this.excludeFromSemantics = false
})
从构造方法中,我们看出GestureDetectorCallback constructor defined in a variety of events,还有一个child属性,这就意味着我们可以利用GestureDetector包裹本身不支持点击回调事件的Widget赋予它们点击回调能力,像Text、ImageWe can't useRaisedButtonAs direct toText、Image绑定onPress回调,但是我们可以借助GestureDetector完成这一操作.
As shown in figure I giveTextGiven the various events interaction:
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: new MyApp()));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Gestures"),
),
body: new Center(
child: new GestureDetector(
child: new Text("I was given the ability to click on the touch...",style: new TextStyle(fontSize: 20.0),),
onTap: () {
print("------onTap");
},
onDoubleTap: () {
print("------onDoubleTap");
},
onLongPress: () {
print("-----onLongPress");
},
onVerticalDragStart: (details){
print("In the vertical direction starting position:"+details.globalPosition.toString());
}, onVerticalDragEnd: (details){
print("At the end of the vertical position:"+details.primaryVelocity.toString());
},
)),
);
}
}
我们在logThe command line crawl to the interaction of the callback events:
边栏推荐
- 苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
- 世界第4疯狂的科学家,在103岁生日那天去世了
- Go-based web access parameters
- 随机快排时间复杂度是N平方?
- 在“Extend the Omniverse”比赛中构建用于 3D 世界的工具
- Resolved IndentationError: unindent does not match any oute r indentation Level
- 又有大厂员工连续加班倒下/ 百度搜狗取消快照/ 马斯克生父不为他骄傲...今日更多新鲜事在此...
- Simple understanding of ThreadLocal
- 单面线路板与精密多层PCB线路板区别有哪些?
- WeChat Mini Program Payment and Refund Overall Process
猜你喜欢
放下手机吧:实验表明花20分钟思考和上网冲浪同样快乐
Say goodbye to the AI era of hand looms
苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
ABAP 面试题:如何使用 ABAP 编程语言的 System CALL 接口,直接执行 ABAP 服务器所在操作系统的 shell 命令?
The grep command Shell regular expressions, the three musketeers
Flutter入门进阶之旅(七)GestureDetector
告别手摇织布机的AI时代
中科院打脸谷歌:普通电脑追上量子优越性,几小时搞定原本要一万年的计算...
Flutter Getting Started and Advanced Tour (4) Text Input Widget TextField
World's 4th mad scientist dies on his 103rd birthday
随机推荐
Flutter入门进阶之旅(六)Layout Widget
大佬们,请教一下,我看官方文档中,sqlserver cdc只支持2012版之后的,对于sqlser
腾讯欲成育碧最大股东/ 米哈游招NLP内容生成研究员/ AI发现四千余物种濒临灭绝...今日更多新鲜事在此...
The redis library cannot be imported
张朝阳对话俞敏洪:一边是手推物理公式,一边是古诗信手拈来
【TKE】GR+VPC-CNI混用模式下未产品化功能配置
MongoDB-查询中$all的用法介绍
Do you know the difference between comments, keywords, and identifiers?
李开复花上千万投的缝纫机器人,团队出自大疆
单面线路板与精密多层PCB线路板区别有哪些?
史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!...
Flutter Getting Started and Advanced Tour (4) Text Input Widget TextField
箭头函数和普通函数的常见区别
Blocking, non-blocking, multiplexing, synchronous, asynchronous, BIO, NIO, AIO all in one pot
HAproxy: load balancing
报告:想学AI的学生数量已涨200%,老师都不够用了
基于STM32+铂电阻设计的测温仪
Too much volume... Tencent was asked on the side that the memory was full, what would happen?
已解决IndentationError: unindent does not match any oute r indentation Level
Flutter入门进阶之旅(二)Hello Flutter