Swipeable class
A widget that can be swiped in a specified direction.
The Swipeable
widget allows its child to be swiped by the user in a
specified direction.
It provides options for customizing the swipe behavior, including the ability to specify a background widget that appears during the swipe, callbacks for handling swipe completion, and more.
Example usage:
Swipeable(
child: Container(
height: 100,
width: 200,
color: Colors.blue,
child: Center(
child: Text('Swipe me'),
),
),
backgroundBuilder: (context, details) {
final direction = details.direction;
return Container(
color: Colors.red,
child: Center(
child: Text(
direction == SwipeDirection.left ? 'Swipe left' : 'Swipe right',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
);
},
onSwiped: (direction) {
if (direction == SwipeDirection.left) {
// Handle left swipe
} else if (direction == SwipeDirection.right) {
// Handle right swipe
}
},
direction: SwipeDirection.horizontal,
swipeThreshold: 0.4,
movementDuration: Duration(milliseconds: 200),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- Swipeable
Constructors
- Swipeable({required Key? key, required Widget child, BackgroundWidgetBuilder? backgroundBuilder, SwipeDirectionCallback? onSwiped, SwipeDirection direction = SwipeDirection.horizontal, double swipeThreshold = 0.4, Duration movementDuration = const Duration(milliseconds: 200), DragStartBehavior dragStartBehavior = DragStartBehavior.start, HitTestBehavior behavior = HitTestBehavior.opaque})
-
Creates a widget that can be swiped .
const
Properties
- backgroundBuilder → BackgroundWidgetBuilder?
-
A widget that is stacked behind the child. If secondaryBackground is also
specified then this widget only appears when the child has been dragged
down or to the right.
final
- behavior → HitTestBehavior
-
How to behave during hit tests.
final
- child → Widget
-
The widget below this widget in the tree.
final
- direction → SwipeDirection
-
The direction in which the widget can be swiped.
final
- dragStartBehavior → DragStartBehavior
-
Determines the way that drag start behavior is handled.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- movementDuration → Duration
-
Defines the duration for card to come back to original position.
final
- onSwiped → SwipeDirectionCallback?
-
Called when the widget has been successfully swiped based on the
direction and swipeThreshold.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- swipeThreshold → double
-
The offset threshold the item has to be dragged in order to be considered
swiped.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → _SwipeableState -
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