Flutter – Gestures

Gestures are to interact with applications. You can use it for touch-base devices in applications. You can perform touch on your mobile applications like physical interaction for swiping, taping, etc. You can also use it for gaming and other features of applications. 

There are many types of gestures: 
  • Tap: Touching the surface of the physical device.
  • Double Tap: Tapping twice in a short time.
  • Drag: Touching the surface of the device with a fingertip and moving on the physical device.
  • Flick: Simple to drag on the device.
  • Pinch: Pinching the surface of the device using two fingers.
  • Zoom: Opposite of pinching.

The GestureDetector widget in Flutter is for detecting physical touch. In this case, the widget is supposed to experience a gesture.

List of GestureDetector events:
Tap
  • onTap
  • onTapCancel
  • onTapUp
  • onTapDown
Double tap
  • onDoubleTap
Long press
  • onLongPress
Vertical drag
  • onVerticalDragStart
  • onVerticallDragUpdate
  • onVerticalDragEnd
Horizontal drag
  • onHorizontalDragStart
  • onHorizontalDragUpdate
  • onHorizontalDragEnd
Pan
  • onPanStart
  • onPanUpdate
  • onPanEnd
Example of Gesturedetector

void main() {

runApp(const MyApp());

}

class MyApp extends StatelessWidget {

const MyApp({Key? key}) : super(key: key);

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(title: const Text('Test Page')),

body: GestureDetector(

onTap: () {

print('onTap called!');

},

onPanDown: (details) {

print('onPanDown called!');

},

onDoubleTap: () {

print('onDoubleTap called!');

},

child: const TextField(

decoration: InputDecoration(hintText: 'Write something...'),

minLines: 15,

maxLines: 15,

),

),

);

}

}

Happy coding!


365Bloggy May 13, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive