当前位置:网站首页>[shutter] shutter gesture interaction (small ball following the movement of fingers)
[shutter] shutter gesture interaction (small ball following the movement of fingers)
2022-07-02 22:05:00 【Programmer community】
List of articles
- One 、Flutter gesture - A small ball that moves with your fingers
- 3、 ... and 、 Complete code example
- 3、 ... and 、 Related resources
One 、Flutter gesture - A small ball that moves with your fingers
Set the spherical coordinate variable : among currentX Is the distance from the left boundary , currentY Is the distance from the right boundary ;
/// Current ball x coordinate double currentX = 0; /// Current ball y coordinate double currentY = 0;The position of the ball : The ball is in Stack In the frame layout Positioned Components , Its left and top The field value sets its coordinates , They correspond to each other currentX and currentY value ;
// Pellet Positioned( /// The current position left: currentX, top: currentY,)Monitoring events : monitor GestureDetector Component's onPanUpdate event , The callback method is void Function(DragUpdateDetails details) Type of Method , It can be downloaded from DragUpdateDetails Get the current x , y The moving distance of , This distance needs to be accumulated with the previous distance , To get accurate coordinate values ;
Call... In the callback method setState Method , Modify member variables currentX and currentY , To modify Positioned Location of components , In order to achieve the goal of small ball movement ;
/// Gesture detection component child: GestureDetector( /// Mobile operating onPanUpdate: (e){
setState(() {
// e You can only get delta value , Need to accumulate step by step currentX += e.delta.dx; currentY += e.delta.dy; }); },)Code example :
// Pellet Positioned( /// The current position left: currentX, top: currentY, /// Gesture detection component child: GestureDetector( /// Mobile operating onPanUpdate: (e){
setState(() {
// e You can only get delta value , Need to accumulate step by step currentX += e.delta.dx; currentY += e.delta.dy; }); }, // Black ball child: Container( width: 40, height: 40, decoration: BoxDecoration( color: Colors.black, borderRadius: BorderRadius.circular(20), ), ), ),),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> {
/// Current ball x coordinate double currentX = 0; /// Current ball y coordinate double currentY = 0; @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, ), ), ), ) ], ), // Pellet Positioned( /// The current position left: currentX, top: currentY, /// Gesture detection component child: GestureDetector( /// Mobile operating onPanUpdate: (e){
setState(() {
// e You can only get delta value , Need to accumulate step by step currentX += e.delta.dx; currentY += e.delta.dy; }); }, // Black ball child: Container( width: 40, height: 40, decoration: BoxDecoration( color: Colors.black, borderRadius: BorderRadius.circular(20), ), ), ),), ], ), ), ), ); } /// Long press event void _longPress(){
print(" Long press "); }}Running effect :

3、 ... and 、 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 distributed lock failure, I can't help but want to burst
- SQL必需掌握的100个重要知识点:使用游标
- MySQL learning record (3)
- [shutter] shutter page Jump (route | navigator | page close)
- : last child does not take effect
- Sql service intercepts string
- "New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
- Free open source web version of xshell [congratulations on a happy new year]
- D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
- How to center the positioned text horizontally and vertically
猜你喜欢

Daily book - low code you must understand in the era of digital transformation
![[use of pointer and pointer and array]](/img/dd/8017215c54aebcdf5c67e46e795d3b.jpg)
[use of pointer and pointer and array]
![[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)](/img/fa/5c1b6c16d9aabd13e9a4f7c7b9c7da.jpg)
[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)

#include<>和#include“”的区别

Technical solution of vision and manipulator calibration system

What is it that makes you tremble? Those without fans can learn

"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
![[shutter] shutter layout component (physicalmodel component)](/img/6a/f8161fb7c8e9012456622f1920da64.gif)
[shutter] shutter layout component (physicalmodel component)

Introduction to victoriametrics

情感计算与理解研究发展概述
随机推荐
Evolution of messaging and streaming systems under the native tide of open source cloud
MySQL learning record (3)
Les trois principaux points de douleur traités par servicemesh
MySQL learning record (4)
情感计算与理解研究发展概述
Cardinality sorting (detailed illustration)
An overview of the development of affective computing and understanding research
图像基础概念与YUV/RGB深入理解
ServiceMesh主要解决的三大痛點
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
LightGBM原理及天文数据中的应用
From personal heroes to versatile developers, the era of programmer 3.0 is coming
加了定位的文字如何水平垂直居中
[shutter] shutter layout component (wrap component | expanded component)
pyqt圖片解碼 編碼後加載圖片
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
记录一下微信、QQ、微博分享web网页功能
A specially designed loss is used to deal with data sets with unbalanced categories
Baidu sued a company called "Ciba screen"