当前位置:网站首页>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:
边栏推荐
- Common gadgets of Shell (sort, uniq, tr, cut)
- 告别手摇织布机的AI时代
- 【HCIP持续更新】IS-IS协议原理与配置
- 脱光衣服待着就能减肥,当真有这好事?
- 用 API Factory 产品生成 API 文档
- Apexsqlrecover cannot connect to database
- Flutter入门进阶之旅(三)Text Widgets
- 2022 Niu Ke Duo School (6) M. Z-Game on grid
- MySQL principle and optimization of Group By optimization techniques
- 苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
猜你喜欢
数字化转型之支撑保障单元
AQS Synchronization Component - FutureTask Analysis and Use Cases
工作任务统计
h264协议
金融业“限薪令”出台/ 软银出售过半阿里持仓/ DeepMind新实验室成立... 今日更多新鲜事在此...
两分钟录音就可秒变语言通!火山语音音色复刻技术如何修炼而成?
基于STM32+铂电阻设计的测温仪
2022 Niu Ke Duo School (6) M. Z-Game on grid
Simple understanding of ThreadLocal
Ten minutes to teach you how to use VitePress to build and deploy a personal blog site
随机推荐
报告:想学AI的学生数量已涨200%,老师都不够用了
如何修改data work上jdbc驱动的版本
Flutter入门进阶之旅(三)Text Widgets
Intra-group reverse order adjustment of K nodes
The new features of ABP 6.0.0 - rc. 1
WebView injects Js code to realize large image adaptive screen click image preview details
#物联网征文#小熊派设备开发实战
基于STM32+铂电阻设计的测温仪
Adalvo收购其首个品牌产品Onsolis
Fragment中嵌套ViewPager数据空白页异常问题分析
Common gadgets of Shell (sort, uniq, tr, cut)
Resolved IndentationError: unindent does not match any oute r indentation Level
Scala 高阶(七):集合内容汇总(上篇)
Two minutes recording can pass by second language!The volcano how to practice and become voice tone reproduction technology?
Use RecyclerView to implement three-level collapsed list
The redis library cannot be imported
Data Mining-05
Extract EventBus encapsulation to base class using annotations
Flutter入门进阶之旅(四)文本输入Widget TextField
大佬们,请教一下,我看官方文档中,sqlserver cdc只支持2012版之后的,对于sqlser