当前位置:网站首页>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:
边栏推荐
- 用场景定义硬件,英码科技破解“边缘计算”密码
- 世界第4疯狂的科学家,在103岁生日那天去世了
- 保存Simulink仿真模型为图片或者PDF的方法
- 8、IDEA提交代码出现: Fetch failed fatal: Could not read from remote repository
- 两个链表相加
- How to upload local file trial version in binary mode in ABAP report
- Scala Advanced (7): Collection Content Summary (Part 1)
- 造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片
- 关于Retrofit网络请求URL中含有可变参数的处理
- [Microservice ~ Remote Call] Integrate RestTemplate, WebClient, Feign
猜你喜欢
基于STM32+铂电阻设计的测温仪
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
Common gadgets of Shell (sort, uniq, tr, cut)
脱光衣服待着就能减肥,当真有这好事?
合并两个有序列表
自定义VIEW实现应用内消息提醒上下轮播
AI basketball referee, walking is special, ask harden care don't care
Flutter入门进阶之旅(六)Layout Widget
Win10 compiles the x264 library (there are also generated lib files)
2022年非一线IT行业就业前景?
随机推荐
注:检测到当前使用的ADB不是HBuilder内置或自定义ADB:PID为:9544进程名称为:adb.exe 路径为:c:\users\administrator\appdata\local\and
#物联网征文#小熊派设备开发实战
【TKE】GR+VPC-CNI混用模式下未产品化功能配置
Scala 高阶(七):集合内容汇总(上篇)
Manchester city launch emotional intelligence scarf can be detected, give the fans
GPT-3组合DALL·E,60秒内搞定游戏设定和原型动画!网友看后:这游戏想玩
2022年非一线IT行业就业前景?
基于STM32+铂电阻设计的测温仪
发明时代,「幂集创新」事关你我
win10编译x264库(也有生成好的lib文件)
一甲子,正青春,CCF创建六十周年庆典在苏州举行
十分钟教会你如何使用VitePress搭建及部署个人博客站点
水能自发变成“消毒水”,83岁斯坦福教授:揭示冬天容易得流感的部分原因...
h264 protocol
Do you know the difference between comments, keywords, and identifiers?
About the handling of variable parameters in the Retrofit network request URL
激光熔覆在农机修复强化中的应用及研究方向
ABAP 报表中如何以二进制方式上传本地文件试读版
The FFmpeg library is configured and used on win10 (libx264 is not configured)
Data Mining-05