当前位置:网站首页>[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 )
边栏推荐
- 暑期第一周总结
- Redis分布式锁故障,我忍不住想爆粗...
- 如何防止你的 jar 被反编译?
- VictoriaMetrics 简介
- Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
- China's crude oil heater market trend report, technological innovation and market forecast
- pyqt圖片解碼 編碼後加載圖片
- 关于测试用例
- [use of pointer and pointer and array]
- *C语言期末课程设计*——通讯录管理系统(完整项目+源代码+详细注释)
猜你喜欢

6 pyspark Library

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

kernel_ uaf

MySQL learning record (4)

Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me

MySQL learning record (7)

Huawei Hongmeng watch achieves fireworks display effect on New Year's Eve

Structure array, pointer and function and application cases

【零基础一】Navicat下载链接

Basic knowledge of tree and binary tree (detailed illustration)
随机推荐
MySQL learning record (1)
Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
Golang embeds variables in strings
3DES (deSede) encryption CBC mode pkcs7padding filling Base64 encoding key 24byte iv8byte
[use of pointer and pointer and array]
Off chip ADC commissioning record
Research Report on market supply and demand and strategy of microplate instrument industry in China
How is LinkedList added?
A river of spring water flows eastward
[shutter] statefulwidget component (create statefulwidget component | materialapp component | scaffold component)
Jar package startup failed -mysql modify the default port number / set password free enter
MySQL learning record (4)
Who do you want to open a stock account? Is it safe to open a mobile account?
Accounting regulations and professional ethics [19]
D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
China plastic box market trend report, technological innovation and market forecast
Construction and maintenance of business websites [9]
Cloud computing technology [2]
Construction and maintenance of business website [1]
Accounting regulations and professional ethics [17]