SwipeDetector class
Detects user swipes.
Attempts to recognize swipes that correspond to its non-null callbacks.
Widget build(BuildContext context) {
return Scaffold(
body: SwipeDetector(
onSwipe: (direction) {
setState(() {
_swipeHistory.insert(0, direction);
if (_swipeHistory.length > _swipeHistoryLimit) {
_swipeHistory.removeLast();
}
});
},
child: Container(
color: Colors.yellow.shade600,
padding: const EdgeInsets.all(16),
child: const Text(
'Swipe me!',
),
),
),
);
}
{@end-tool}
Debugging
To see how large the hit test box of a SwipeDetector is for debugging purposes, set debugPaintPointersEnabled to true.
See also:
- GestureDetector, a widget that is used to detect gestures.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SwipeDetector
Constructors
- SwipeDetector({Key? key, HitTestBehavior? behavior, void onSwipe(SwipeDirection direction, Offset offset)?, void onSwipeUp(Offset offset)?, void onSwipeDown(Offset offset)?, void onSwipeLeft(Offset offset)?, void onSwipeRight(Offset offset)?, bool liveFeedback = false, required Widget child})
-
Creates a SwipeDetector which can be used to detects user swipes.
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
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- liveFeedback → bool
-
If true, the callbacks are called every time the gesture gets updated
and provide an Offset value in each callback.
final
- onSwipe → (void Function(SwipeDirection direction, Offset offset)?)
-
Called when the user has swiped in a particular direction.
final
- onSwipeDown → (void Function(Offset offset)?)
-
Called when the user has swiped downwards.
final
- onSwipeLeft → (void Function(Offset offset)?)
-
Called when the user has swiped to the left.
final
- onSwipeRight → (void Function(Offset offset)?)
-
Called when the user has swiped to the right.
final
- onSwipeUp → (void Function(Offset offset)?)
-
Called when the user has swiped upwards.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → _SwipeDetectorState -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent 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 DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
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 ==(
Object other) → bool -
The equality operator.
inherited