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.

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

Constructors

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

Properties

behavior HitTestBehavior
How this gesture detector should behave during hit testing. [...]
final
child Widget
The widget below this widget in the tree. [...]
final
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.
final
gestures Map<Type, GestureRecognizerFactory<GestureRecognizer>>
The gestures that this widget will attempt to recognize. [...]
final
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

Methods

createState() RawGestureDetectorState
Creates the mutable state for this widget at a given location in the tree. [...]
override
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
inherited
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. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this object.
inherited
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this node and its descendants. [...]
inherited
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a one-line detailed description of the object. [...]
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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