当前位置:网站首页>Flutter入门进阶之旅(七)GestureDetector
Flutter入门进阶之旅(七)GestureDetector
2022-08-09 12:04:00 【谢栋_】
引言:
GestureDetector在Flutter中负责处理跟用户的简单手势交互,GestureDetector控件没有图像展示,只是检测用户输入的手势,并作出相应的处理,包括点击、拖动和缩放。许多控件使用GestureDetector为其他控件提供回调,比如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
})
从构造方法中,我们看出GestureDetector构造方法里定义各种事件回调,还有一个child属性,这就意味着我们可以利用GestureDetector包裹本身不支持点击回调事件的Widget赋予它们点击回调能力,像Text、Image我们就不能像使用RaisedButton一样直接给Text、Image绑定onPress回调,但是我们可以借助GestureDetector完成这一操作。
如图我给Text赋予了各种事件交互:
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("我被赋予了点击触摸能力...",style: new TextStyle(fontSize: 20.0),),
onTap: () {
print("------onTap");
},
onDoubleTap: () {
print("------onDoubleTap");
},
onLongPress: () {
print("-----onLongPress");
},
onVerticalDragStart: (details){
print("在垂直方向开始位置:"+details.globalPosition.toString());
}, onVerticalDragEnd: (details){
print("在垂直方向结束位置:"+details.primaryVelocity.toString());
},
)),
);
}
}
我们在log命令行抓取到的各种回调事件的交互:
边栏推荐
- 读写分离后,性能居然提升100%了呀
- Scala Advanced (7): Collection Content Summary (Part 1)
- 超越CLIP的多模态模型,只需不到1%的训练数据!南加大最新研究来了
- OpenSSF的开源软件风险评估工具:Scorecards
- Double pointer - the role of char **, int **
- Two minutes recording can pass by second language!The volcano how to practice and become voice tone reproduction technology?
- 26、管道参数替换命令xargs
- Too much volume... Tencent was asked on the side that the memory was full, what would happen?
- MongoDB-查询中$all的用法介绍
- 报告:想学AI的学生数量已涨200%,老师都不够用了
猜你喜欢
已解决IndentationError: unindent does not match any oute r indentation Level
[Microservice ~ Remote Call] Integrate RestTemplate, WebClient, Feign
00后写个暑假作业,被监控成这笔样
Shell正则表达式,三剑客之grep命令
微信一面:一致性哈希是什么,使用场景,解决了什么问题?
两分钟录音就可秒变语言通!火山语音音色复刻技术如何修炼而成?
李开复花上千万投的缝纫机器人,团队出自大疆
API调用,API传参,面向对接开发,你真的会写接口文档吗?
智驾科技完成C1轮融资,此前2轮已融4.5亿元
MySQL principle and optimization of Group By optimization techniques
随机推荐
阿里高工带来的20022最新面试总结太香了
How should the acceptance criteria for R&D requirements be written?| Agile Practices
信息系统项目管理师必背核心考点(六十三)项目组合管理的主要过程&DIPP分析
一甲子,正青春,CCF创建六十周年庆典在苏州举行
告别手摇织布机的AI时代
ansible-cmdb友好展示ansible收集主机信息
李开复花上千万投的缝纫机器人,团队出自大疆
苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
8、IDEA提交代码出现: Fetch failed fatal: Could not read from remote repository
Recommend a free 50-hour AI computing platform
HAproxy:负载均衡
微服务架构的核心关键点
实验记录:搭建网络过程
#物联网征文#小熊派设备开发实战
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
Django cannot link mysql database
proto3-2 syntax
Senior told me that the giant MySQL is through SSH connection
标准C语言学习总结14
The redis library cannot be imported