A widget that detects gestures. If you want your widget to respond on user interaction simply wrap the widget within GestureDetector
widget and assign the callback method to its particular arguments.
By default a GestureDetector with an invisible child ignores touches; this behavior can be controlled with behavior
.
GestureDetector also listens for accessibility events and maps them to the callbacks. To ignore accessibility events, set excludeFromSemantics
to true.
Container( alignment: FractionalOffset.center, color: Colors.white, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Padding( padding: const EdgeInsets.all(8.0), child: Icon( Icons.lightbulb_outline, color: _lights ? Colors.yellow.shade600 : Colors.black, size: 60, ), ), GestureDetector( onTap: () { setState(() { _lights = true; }); }, child: Container( color: Colors.yellow.shade600, padding: const EdgeInsets.all(8), child: const Text('TURN LIGHTS ON'), ), ), ], ), )
Here are some arguments you can use:
behavior
: How this gesture detector should behave during hit testing.excludeFromSemantics
: Whether to exclude these gestures from the semantics tree. For example, the long-press gesture for showing a tooltip is excluded because the tooltip itself is included in the semantics tree directly and so having a gesture to show it would result in duplication of information.Here are some popular guesture are listed below:
onTap
: A tap with a primary button has occurred.onDoubleTap
: The user has tapped the screen with a primary button at the same location twice in quick succession.onLongPress
: Called when a long press gesture with a primary button has been recognized.onLongPressEnd
: A pointer that has triggered a long-press with a primary button has stopped contacting the screen.To know more guesture click here.