Junior
What gestures can be handled in Flutter?
sobes.tech AI
Answer from AI
In Flutter, the following gestures can be handled using widgets like GestureDetector and others:
-
Taps:
onTap: Simple tap.onDoubleTap: Double tap.onLongPress: Long press.onTapDown: Tap at the moment of contact.onTapUp: Release after tap.onTapCancel: Cancel tap.
-
Dragging (Draggable):
onVerticalDragStart: Start of vertical drag.onVerticalDragUpdate: Updating vertical drag.onVerticalDragEnd: End of vertical drag.onHorizontalDragStart: Start of horizontal drag.onHorizontalDragUpdate: Updating horizontal drag.onHorizontalDragEnd: End of horizontal drag.onPanStart: Start of any pan.onPanUpdate: Updating any pan.onPanEnd: End of any pan.
-
Scale (Zoom):
onScaleStart: Start of scaling.onScaleUpdate: Updating scaling.onScaleEnd: End of scaling.
-
Other gestures:
onForcePressStart: Start of force press (supported on some devices).onForcePressPeak: Peak of force press.onForcePressUpdate: Updating force press.onForcePressEnd: End of force press.
Example of using GestureDetector:
import 'package:flutter/material.dart';
class MyGestureWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
print('Tap!');
},
onDoubleTap: () {
print('Double tap!');
},
onLongPress: () {
print('Long press!');
},
child: Container(
color: Colors.blue,
width: 100,
height: 100,
child: Center(
child: Text('Press me'),
),
),
);
}
}