GestureDetector is a widget that detects gestures. If the child property of GestureDetector is not empty, GestureDetector sets its size to the size of the child.
If the child property is empty, it sets its size to the size of the parent component
We have different type of gestures, below are few of them
onTapDown,
onTapUp,
onTap,
onTapCancel,
onForcePressPeak,
onForcePressUpdate,
onForcePressEnd,
onPanDown,
onPanStart,
onPanUpdate,
onPanEnd,
onPanCancel,
onScaleStart,
onScaleUpdate,
onScaleEnd
onSecondaryTapDown,
onSecondaryTapUp,
onSecondaryTapCancel,
onDoubleTap,
onLongPress,
onLongPressStart,
onLongPressMoveUpdate,
onLongPressUp,
onLongPressEnd,
Example
class GesterDetectorWidget extends StatelessWidget{ GlobalKey<ScaffoldState>_scaffoldstate=GlobalKey(); @override Widget build(BuildContext context) { // TODO: implement build return MaterialApp( home: Scaffold( key: _scaffoldstate, appBar: AppBar(title:Text("Card Widget"),backgroundColor: Colors.pink,), body: Container( child: GestureDetector( child: Center( child: Container( color: Colors.pink, child: Padding( padding: const EdgeInsets.all(8.0), child: Text("Gesture Me",style: TextStyle(fontSize: 20,color: Colors.white),), ), )), onTap: (){ _scaffoldstate.currentState.showSnackBar(SnackBar(content: Text("onTap Event"))); }, onDoubleTap: (){ _scaffoldstate.currentState.showSnackBar(SnackBar(content: Text("onDoubleTap Event"))); }, onLongPress: (){ _scaffoldstate.currentState.showSnackBar(SnackBar(content: Text("onLongPress Event"))); }, ), ) ) ); } } |