RawGestureDetector class

A widget that detects gestures described by the given gesture factories.

For common gestures, use a GestureRecognizer. RawGestureDetector is useful primarily when developing your own gesture recognizers.

Configuring the gesture recognizers requires a carefully constructed map, as described in gestures and as shown in the example below.

Sample code

This example shows how to hook up a TapGestureRecognizer. It assumes that the code is being used inside a State object with a _last field that is then displayed as the child of the gesture detector.

new RawGestureDetector(
  gestures: <Type, GestureRecognizerFactory>{
    TapGestureRecognizer: new GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
      () => new TapGestureRecognizer(),
      (TapGestureRecognizer instance) {
          ..onTapDown = (TapDownDetails details) { setState(() { _last = 'down'; }); }
          ..onTapUp = (TapUpDetails details) { setState(() { _last = 'up'; }); }
          ..onTap = () { setState(() { _last = 'tap'; }); }
          ..onTapCancel = () { setState(() { _last = 'cancel'; }); };
  child: new Container(width: 300.0, height: 300.0, color: Colors.yellow, child: new Text(_last)),

See also:

  • GestureDetector, a less flexible but much simpler widget that does the same thing.
  • Listener, a widget that reports raw pointer events.
  • GestureRecognizer, the class that you extend to create a custom gesture recognizer.


RawGestureDetector({Key key, Widget child, Map<Type, GestureRecognizerFactory<GestureRecognizer>> gestures: const {}, HitTestBehavior behavior, bool excludeFromSemantics: false })
Creates a widget that detects gestures. [...]


behavior HitTestBehavior
How this gesture detector should behave during hit testing.
child Widget
The widget below this widget in the tree. [...]
excludeFromSemantics bool
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.
gestures Map<Type, GestureRecognizerFactory<GestureRecognizer>>
The gestures that this widget will attempt to recognize. [...]
hashCode int
The hash code for this object. [...]
read-only, inherited
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


createState() RawGestureDetectorState
Creates the mutable state for this widget at a given location in the tree. [...]
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by toStringDeep. [...]
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this object.
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this node and its descendants. [...]
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A short, textual description of this widget.


operator ==(dynamic other) bool
The equality operator. [...]