当前位置:网站首页>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:
边栏推荐
- 链表噩梦之一?5000多字带你弄清它的来龙去脉
- Two minutes recording can pass by second language!The volcano how to practice and become voice tone reproduction technology?
- AI篮球裁判火了,走步算得特别准,就问哈登慌不慌
- 西湖大学教授怎么看AI制药革命?|量子位智库圆桌实录
- The redis library cannot be imported
- 二叉树的序列化和反序列化
- The core key points of microservice architecture
- Say goodbye to the AI era of hand looms
- The latest interview summary in 20022 brought by Ali senior engineer is too fragrant
- 激光熔覆在农机修复强化中的应用及研究方向
猜你喜欢

h264协议

API调用,API传参,面向对接开发,你真的会写接口文档吗?

基于CAP组件实现补偿事务与幂等性保障

注释、关键字、标识符的区别你知道吗?

Resolved IndentationError: unindent does not match any oute r indentation Level

How to upload local file trial version in binary mode in ABAP report

Flutter入门进阶之旅(六)Layout Widget

又有大厂员工连续加班倒下/ 百度搜狗取消快照/ 马斯克生父不为他骄傲...今日更多新鲜事在此...

LeetCode #101. Symmetric Binary Tree

国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...
随机推荐
注释、关键字、标识符的区别你知道吗?
两个链表相加
Extract EventBus encapsulation to base class using annotations
Go-based web access parameters
Fragment中嵌套ViewPager数据空白页异常问题分析
Say goodbye to the AI era of hand looms
Introduction to Flutter advanced trip Dialog&Toast (10)
MySQL 原理与优化,Group By 优化 技巧
FFmpeg库在win10上配置使用(不配置libx264)
ansible-cmdb友好展示ansible收集主机信息
LeetCode #101. Symmetric Binary Tree
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
告别手摇织布机的AI时代
基于CAP组件实现补偿事务与幂等性保障
Scala 高阶(七):集合内容汇总(上篇)
关于Retrofit网络请求URL中含有可变参数的处理
鹅厂机器狗花式穿越10m梅花桩:前空翻、单桩跳、起身作揖...全程不打一个趔趄...
造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片
900页数学论文证明旋转的黑洞不会爆炸,丘成桐:30多年来广义相对论首次重大突破...
The new features of ABP 6.0.0 - rc. 1