当前位置:网站首页>[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)
[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)
2022-07-02 21:41:00 【Programmer community】
List of articles
- One 、Flutter Click event handling
- Two 、GestureDetector Description of common events
- 3、 ... and 、 Complete code example
- Four 、 Related resources
One 、Flutter Click event handling
Flutter The component of click event processing is GestureDetector Components ;
GestureDetector Options that can be set in the component , In the optional arguments in the constructor , Most of them are callback method setting fields ;
class GestureDetector extends StatelessWidget {
GestureDetector({
Key key, this.child, this.onTapDown, // Press down this.onTapUp, // lift this.onTap, // single click this.onTapCancel, // Click Cancel this.onSecondaryTapDown, this.onSecondaryTapUp, this.onSecondaryTapCancel, this.onDoubleTap, // double-click this.onLongPress, // Long press this.onLongPressStart, this.onLongPressMoveUpdate, this.onLongPressUp, this.onLongPressEnd, 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, this.dragStartBehavior = DragStartBehavior.start, })}GestureDetector Component usage :
- Set various callback events : stay onXxx Field to set various callback events , The field type is void Function() Type of ;
- Action component : stay child Field sets the main component of gesture detection , That is, which component's gesture event is monitored ;
// Gesture detection component GestureDetector( // Click event onTap: (){
print(" double-click "); }, // Double-click the event onDoubleTap: (){
print(" double-click "); }, // Long press event , ()=> Method name ( parameter list ) You can call back an existing method onLongPress: () => _longPress(), // Click Cancel onTapCancel: (){
print(" Click Cancel "); }, // Click to press onTapDown: (e){
print(" Click to press "); }, // Click to lift onTapUp: (e){
print(" Click to lift "); }, // Action component of gesture detection , Monitor various gestures on the component child: Container( // The sub components are centered alignment: Alignment.center, // padding padding: EdgeInsets.all(100), // Background decoration decoration: BoxDecoration( color: Colors.green, ), child: Text( " Gesture detection ", style: TextStyle( fontSize: 50, color: Colors.red, ), ), ),)Two 、GestureDetector Description of common events
GestureDetector Description of common events :
- onTap : Click events ;
- onDoubleTap : Double-click the event ;
- onLongPress : Long press event ;
- onTapCancel : Click event cancel , A complete click event by pressing , lift form , If it has not been released after pressing , It becomes a long press operation , Click the event to cancel automatically ; If it slides out after pressing child Components , It will automatically become a click to cancel event ;
- onTapDown : Click press event ;
- onTapUp : Click lift event ;
3、 ... and 、 Complete code example
Complete code example :
import 'package:flutter/material.dart';class GesturePage extends StatefulWidget {
@override _GesturePageState createState() => _GesturePageState();}class _GesturePageState extends State<GesturePage> {
@override Widget build(BuildContext context) {
return MaterialApp( // Set the theme theme: ThemeData( primarySwatch: Colors.amber, ), // Set the body component home: Scaffold( // Set the title bar appBar: AppBar( title: Text(" Gesture detection "), // Back to button settings leading: GestureDetector( // Click the event callback function onTap: (){
// Exit the current interface Navigator.pop(context); }, // Back button icon child: Icon(Icons.arrow_back), ), ), // level / Tile components vertically body: FractionallySizedBox( // Tile horizontally widthFactor: 1, // Frame layout child: Stack( children: <Widget>[ // Vertical linear layout Column( children: <Widget>[ // Gesture detection component GestureDetector( // Click event onTap: (){
print(" double-click "); }, // Double-click the event onDoubleTap: (){
print(" double-click "); }, // Long press event , ()=> Method name ( parameter list ) You can call back an existing method onLongPress: () => _longPress(), // Click Cancel onTapCancel: (){
print(" Click Cancel "); }, // Click to press onTapDown: (e){
print(" Click to press "); }, // Click to lift onTapUp: (e){
print(" Click to lift "); }, // Action component of gesture detection , Monitor various gestures on the component child: Container( // The sub components are centered alignment: Alignment.center, // padding padding: EdgeInsets.all(100), // Background decoration decoration: BoxDecoration( color: Colors.green, ), child: Text( " Gesture detection ", style: TextStyle( fontSize: 50, color: Colors.red, ), ), ), ) ], ) ], ), ), ), ); } /// Long press event void _longPress(){
print(" Long press "); }}Operation effect display :

Print the results :
2021-03-02 20:26:54.072 15660-15678/com.example.flutter_cmd I/flutter: Click to press 2021-03-02 20:26:54.073 15660-15678/com.example.flutter_cmd I/flutter: Click to lift 2021-03-02 20:26:54.073 15660-15678/com.example.flutter_cmd I/flutter: double-click 2021-03-02 20:26:58.229 15660-15678/com.example.flutter_cmd I/flutter: Click to press 2021-03-02 20:26:58.229 15660-15678/com.example.flutter_cmd I/flutter: Click to lift 2021-03-02 20:26:58.229 15660-15678/com.example.flutter_cmd I/flutter: double-click 2021-03-02 20:26:59.279 15660-15678/com.example.flutter_cmd I/flutter: Click to press 2021-03-02 20:26:59.682 15660-15678/com.example.flutter_cmd I/flutter: Click Cancel 2021-03-02 20:26:59.682 15660-15678/com.example.flutter_cmd I/flutter: Long press 2021-03-02 20:27:02.233 15660-15678/com.example.flutter_cmd I/flutter: Click to press 2021-03-02 20:27:02.284 15660-15678/com.example.flutter_cmd I/flutter: Click Cancel 2021-03-02 20:27:02.634 15660-15678/com.example.flutter_cmd I/flutter: Long press 2021-03-02 20:27:04.465 15660-15678/com.example.flutter_cmd I/flutter: Click to press 2021-03-02 20:27:04.465 15660-15678/com.example.flutter_cmd I/flutter: Click to lift 2021-03-02 20:27:04.465 15660-15678/com.example.flutter_cmd I/flutter: double-click Four 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- Flutter Developing documents : https://flutter.cn/docs ( Strongly recommend )
- official GitHub Address : https://github.com/flutter
- Flutter The Chinese community : https://flutter.cn/
- Flutter Practical tutorial : https://flutter.cn/docs/cookbook
- Flutter CodeLab : https://codelabs.flutter-io.cn/
- Dart Chinese document : https://dart.cn/
- Dart Developer website : https://api.dart.dev/
- Flutter Chinese net ( unofficial , The translation is very good ) : https://flutterchina.club/ , http://flutter.axuer.com/docs/
- Flutter Related issues : https://flutterchina.club/faq/ ( It is recommended to watch it at the introductory stage )
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_cmd ( Keep updating with the progress of the blog , There may not be the source code of this blog )
Blog source snapshot : https://download.csdn.net/download/han1202012/15484718 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Construction and maintenance of business websites [10]
- Gbase8s database type
- Market trend report, technical innovation and market forecast of China's Micro pliers
- Construction and maintenance of business websites [4]
- Codeworks global round 19 (CF 1637) a ~ e problem solution
- China plastic bottle and container market trend report, technological innovation and market forecast
- Plastic granule Industry Research Report - market status analysis and development prospect forecast
- Browser - clean up the cache of JS in the page
- pyqt图片解码 编码后加载图片
- Construction and maintenance of business website [5]
猜你喜欢
![[dynamic planning] p1220: interval DP: turn off the street lights](/img/b6/405e29ca88fac40caee669a3b7893f.jpg)
[dynamic planning] p1220: interval DP: turn off the street lights

26 FPS video super-resolution model DAP! Output 720p Video Online
![[shutter] statefulwidget component (image component | textfield component)](/img/4b/8e54607939989f994303ce5d922331.gif)
[shutter] statefulwidget component (image component | textfield component)
![[question brushing diary] classic questions of dynamic planning](/img/31/fcd8230f809d6178f11e7095c1ef94.jpg)
[question brushing diary] classic questions of dynamic planning

Report on investment development and strategic recommendations of China's vibration isolator market, 2022-2027

The neo4j skill tree was officially released to help you easily master the neo4j map database

Etcd Raft 协议

发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
![[zero foundation I] Navicat download link](/img/23/e7808884152eeaf186fe756d6adac6.png)
[zero foundation I] Navicat download link
![[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)](/img/80/215499c66243d5a4453d8e6206c012.jpg)
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)
随机推荐
Market trend report, technical innovation and market forecast of China's Micro pliers
Go web programming practice (1) -- basic syntax of go language
Adding data to the head or tail of the rar file can still decompress normally
Analyze comp-206 advanced UNIX utils
[question brushing diary] classic questions of dynamic planning
Get weekday / day of week for datetime column of dataframe - get weekday / day of week for datetime column of dataframe
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)
How to test the process of restoring backup files?
Accounting regulations and professional ethics [17]
D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
[shutter] shutter layout component (physicalmodel component)
*C语言期末课程设计*——通讯录管理系统(完整项目+源代码+详细注释)
In depth research and investment feasibility report on the global and China active vibration isolation market 2022-2028
[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)
Baidu sued a company called "Ciba screen"
China microporous membrane filtration market trend report, technological innovation and market forecast
Pyqt picture decodes and encodes and loads pictures
Download vagrant box file locally from Atlas and configuring it
Spend more time with your computer on this special holiday, HHH
I drew a Gu ailing with characters!