首页 > 其他分享 >Flutter Gestures

Flutter Gestures

时间:2023-01-02 21:35:41浏览次数:41  
标签:code screen Gestures print Card widgets Flutter gesture

Learn to handle Flutter gestures like tap, press, long press, drags, etc. It is very important to know the actions of user.
Gestures are physical action and movement on the app screen with the purpose to give command or control the app. It is very important feature to interact with users. Some of the examples of gestures are:

sliding the lock screen.
Tap on mobile screen
Holding touch on the button.

Different types of Gestures:
Tap: It is a touching screen with a fingertip for very short time and releasing it instantly. This gesture contains the following events:

onTapDown
onTapUp
onTap
onTapCancel

Double Tap: It is touching screen and releasing it instantly two times with a fingertip. This gesture contains the following events:

onDoubleTap
Press: It is pressing screen with a fingertip for short time. This gesture contains the following events:

onPressed
Long Press: It is touching the screen with a fingertip for a long time. This gesture contains the following events:

onLongPress

Drag: It is pressing on any component on app screen and move it from one location to another location. This gesture contains the following events:

onHorizontalDragStart
onHorizontalDragUpdate
onHorizontalDragEnd
onVerticalDragStart
onVerticalDragStart
onVerticalDragStart

How to detect Gestures:
On app, you may need to respond to users according to their actions. For example, we need to execute some blocks of code on button press and give output to the user. In Flutter, some widgets have default gesture responder parameters on which we need to pass the sets of code-block. For example, FlatButton widgets has onLongPress and onPressed parameters on which we can assign code block or any method to execute.

FlatButton(
  onLongPress: (){
   //sets of code to execture after button long press
    print("Button is long pressed.");
  },
  onPressed: (){
    //sets of code to execute after button press
     print("Button is pressed");
  }, 
  child: Text("Press Button"),
)

This is the way you can put code block to the gesture listener parameter of widgets, but the problem will arise when widget has no such parameters. For example, you have an image on app and want to respond whenever user taps on it. Flutter has some widgets to respond to the gestures from users. You simply need to wrap the non-interactive widgets with such gesture detector widgets.

  1. GestureDetector( )

GestureDetector() widget helps to detect wide variety of gestures from users. Suppose you need to respond to the user when every they tap on card or any images. Simply wrap such widgets with GestureDetector() and place sets of code-blocks on its gesture listener parameter like an example below:

GestureDetector( 
          child: Card( 
            child: Text("Click on Me"),
          ),

          onTap: (){
              print("Card is tapped.");
          },

          onDoubleTap: ()=> print("Card is double tapped."),

          onLongPress: (){
             print("Card is long pressed.");
          },
)
  1. InkResponse()

InkResponse() widgets help to detect some sorts of gestures and it creates splash effects on screen touch. Wrap non-interactive widgets with InkResponse() to make them interactive like below:

InkResponse( 
          child: Card( 
            child: Text("Click on Me"),
          ),

          onTap: (){
              print("Card is tapped.");
          },

          onDoubleTap: ()=> print("Card is double tapped."),

          onLongPress: (){
             print("Card is long pressed.");
          },
 )

标签:code,screen,Gestures,print,Card,widgets,Flutter,gesture
From: https://www.cnblogs.com/ukzq/p/17020559.html

相关文章

  • Flutter Widgets
    LearnthebasicconceptofFlutterwidgetsanddifferentwaysofuseittomakeuserinterface.InFlutter,almosteverythingisawidget.Inthistutorial,yo......
  • Flutter 陈航 11-生命周期 WidgetsBindingObserver
    本文地址目录目录目录11|提到生命周期,我们是在说什么?State生命周期生命周期流程图生命周期的三个阶段创建更新销毁注意!!!常见场景的生命周期生命周期方法总结测试代码S......
  • Flutter异常监控 - 壹 | 从Zone说起
    开启掘金成长之旅!这是我参与「掘金日新计划·12月更文挑战」的第3天,点击查看活动详情如果你正需要处理Flutter异常捕获,那么恭喜你,找对地了,这里从根源上给你准备了Flutt......
  • 第144期:flutter的导航和路由
    封面图那些封控做核酸的日子,仿佛还在昨天。这几天核酸检测点撤掉之后,仿佛疫情根本没有发生过一样~导航和路由Flutter提供了一个完整的用于在屏幕之间导航和处理深层链接的系......
  • 第145期:Flutter中的状态
    封面图窗外是一所小学,这两天那座教学楼的墙上多了个校训,我总是把【脚踏实地】看成【实训基地】~状态管理对于经常写​​Vue​​​和​​React​​项目的同学来说,状态管理这个......
  • 第143期:flutter中的资源和图片
    封面图下个季度的目标是把前端监控相关的内容梳理出来,梳理出来之后可能会在公司内部做个分享~Flutter应用程序既括代码也包括一些其他的资产,我们通常这些资产为资源。有时候......
  • 第142期:flutter的状态组件和状态管理
    封面图我们在看电影的时候,往往只关注某个主演的角色,其实那些小角色的表演,远远比主演角色的表演要丰富~场景怎样才能在我们的flutter应用中对用户输入做出响应?比如我们有个图......
  • Flutter异常监控 - 贰 | 框架Catcher原理分析
    前言在给Flutter应用做异常监控的时候,一开始我是拒绝滴,如果不考虑FlutterEngine和native侧的监控,用我另一篇文章中不得不知道的Flutter异常捕获知识点提到的方......
  • 记Flutter执行flutter doctor --android-licenses时出现错误
    错误描述今天刚刚安装好Flutter,执行了$flutterdoctor结果如图所示,出现一个Android令牌状态不可知的错误。根据提示信息,执行如下的命令,$flutterdoctor--android-......
  • Flutter 实现 “真” 3D 动画效果,用纯代码实现立体 Dash 和 3D Logo
    我正在参加「创意开发投稿大赛」详情请看:​​掘金创意开发大赛来了!​​本篇将给你带来更加炫酷动画效果,最后教你如何通过纯代码实现一只立体的Flutter的吉祥物Dash和3......