当前位置:网站首页>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:
边栏推荐
- 基于CAP组件实现补偿事务与幂等性保障
- AI篮球裁判火了,走步算得特别准,就问哈登慌不慌
- 史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!...
- Flutter入门进阶之旅(八)Button Widget
- Intra-group reverse order adjustment of K nodes
- WeChat side: what is consistent hashing, usage scenarios, and what problems does it solve?
- 在“Extend the Omniverse”比赛中构建用于 3D 世界的工具
- ERP不规范,同事两行泪 (转载非原创)
- 1-hour live broadcast recruitment order: industry big names share dry goods, and enterprise registration opens丨qubit·viewpoint
- 位图与位运算
猜你喜欢
win10编译x264库(也有生成好的lib文件)
Flutter入门进阶之旅(七)GestureDetector
[Microservice ~ Remote Call] Integrate RestTemplate, WebClient, Feign
Common gadgets of Shell (sort, uniq, tr, cut)
鹅厂机器狗花式穿越10m梅花桩:前空翻、单桩跳、起身作揖...全程不打一个趔趄...
Go Affair, How to Become a Gopher and Find a Go Job in 7 Days, Part 1
MongoDB-查询中$all的用法介绍
Flutter入门进阶之旅(六)Layout Widget
西湖大学教授怎么看AI制药革命?|量子位智库圆桌实录
h264 protocol
随机推荐
曼城推出可检测情绪的智能围巾,把球迷给整迷惑了
MySQL principle and optimization of Group By optimization techniques
About the handling of variable parameters in the Retrofit network request URL
曲鸟全栈UI自动化教学(八):框架代码讲解和进一步优化
听声辨物,这是AI视觉该干的???|ECCV 2022
ABAP 报表中如何以二进制方式上传本地文件试读版
保存Simulink仿真模型为图片或者PDF的方法
批量读取word docx文件指定表格内容,保存在excel文件中
中断系统结构及中断控制详解
注:检测到当前使用的ADB不是HBuilder内置或自定义ADB:PID为:9544进程名称为:adb.exe 路径为:c:\users\administrator\appdata\local\and
2022 Niu Ke Duo School (6) M. Z-Game on grid
无需精子卵子子宫体外培育胚胎,Cell论文作者这番话让网友们炸了
Flutter入门进阶之旅(六)Layout Widget
Customize VIEW to realize in-app message reminder to rotate up and down
Win10 compiles the x264 library (there are also generated lib files)
【Untitled】
Here comes the question: Can I successfully apply for 8G memory on a machine with 4GB physical memory?
Blocking, non-blocking, multiplexing, synchronous, asynchronous, BIO, NIO, AIO all in one pot
#Internet of Things essay#Xiaoxiong pie equipment development actual combat
Resolved IndentationError: unindent does not match any oute r indentation Level