Slidable Widget
The Slidable
widget enables you to create swipeable items with customizable action panes on both sides. This widget is particularly useful for implementing swipe-to-action functionality, such as swipe-to-delete, swipe-to-edit, or any other custom actions in your application.
Key Properties and Features
- Dual Action Panes: Support for both start (left) and end (right) action panes
- Customizable Actions: Each action pane can contain multiple actions with customizable icons, labels, and colors
- Motion Options: Various motion types available including scroll, stretch, behind, and drawer animations
- Dismissible Support: Optional swipe-to-dismiss functionality with customizable behavior
- Group Management: Group related slidables together using the
groupTag
property - Directional Support: Supports both horizontal and vertical sliding
- Accessibility: Respects text direction for RTL/LTR layouts
Properties
Property | Type | Description |
---|---|---|
groupTag | string | Groups related slidable widgets together for coordinated behavior |
enabled | boolean | Enables or disables the slidable functionality. Defaults to true |
closeOnScroll | boolean | Determines if the slidable should close when scrolling. Defaults to true |
direction | Axis | Sets the slide direction (horizontal or vertical ). Defaults to horizontal |
dragStartBehavior | DragStartBehavior | Determines when dragging starts (down or start ). Defaults to down |
useTextDirection | boolean | Respects the text direction for RTL/LTR layouts. Defaults to true |
startDrawer | object | Configuration for the start (left/top) action pane |
endDrawer | object | Configuration for the end (right/bottom) action pane |
child | Widget | The main content widget that will be slidable |
Drawer Configuration
Each drawer (start/end) can be configured with the following properties:
Options
Property | Type | Description |
---|---|---|
extentRatio | double | Ratio of the screen width that the drawer can extend to. Defaults to 0.25 |
motion | string | Type of motion animation (scroll , stretch , behind , drawer ) |
openThreshold | double? | Threshold for when the drawer should fully open |
closeThreshold | double? | Threshold for when the drawer should close |
Dismissible Options
Each drawer can be made dismissible with these configuration options:
Property | Type | Description |
---|---|---|
dismissThreshold | double | Threshold at which dismissal is triggered. Defaults to 0.75 |
dismissalDurationMs | int | Duration of the dismiss animation in milliseconds. Defaults to 300 |
resizeDurationMs | int | Duration of the resize animation after dismissal. Defaults to 300 |
motion | string | Dismissal animation type (inversedDrawer , drawer , behind , scroll , stretch ) |
onDismissed | Action | Callback function executed when the drawer is dismissed |
Action Properties
Each action in the drawer can have the following properties:
Property | Type | Description |
---|---|---|
icon | IconData | The icon to display for the action |
label | string | Text label for the action |
backgroundColor | Color | Background color of the action button. Defaults to blue |
foregroundColor | Color | Color of the icon and text. Defaults to white |
padding | EdgeInsets | Padding around the action button. Defaults to EdgeInsets.zero |
spacing | double | Space between the icon and label. Defaults to 4.0 |
autoClose | boolean | Whether to close the drawer after action is triggered. Defaults to true |
flex | int | Flex value for action width distribution. Defaults to 1 |
borderRadius | BorderRadius | Border radius of the action button. Defaults to BorderRadius.zero |
onTap | Action | Callback function to execute when the action is tapped |
Box Styles (Inherited)
This widget also inherits these styles:
Property | Type | Description |
---|---|---|
margin | integer/string | Margin with CSS-style notation (1 to 4 integers) e.g. margin: 5 20 5 |
padding | integer/string | Padding with CSS-style notation (1 to 4 integers) e.g. padding: 5 20 5 |
backgroundColor | Color | The background color of this widget. |
backgroundImage | BackgroundImage | The background image of this widget. |
backgroundGradient | Gradient | The background gradient of this widget. |
border | Border | The border of this widget. |
shadow | Shadow | The shadow of this widget |
clipContent | boolean | Some widgets (such as Image) may bleed through the container when borderRadius is set. Use this to apply a clipping to ensure this does not happen. |
width | integer | The width of this widget. |
height | integer | The height of this widget. |
borderRadius | string or integer | The border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0. |
borderColor | integer or string | Sets the border color, starting with '0xFF' for full opacity. Possible values: transparent, black, blue, white, red, grey, teal, amber, pink, purple, yellow, green, brown, cyan, indigo, lime, orange. |
borderWidth | integer | Thickness of the border. Minimum value should be 0. |
shadowColor | integer or string | Sets the box shadow color starting with '0xFF' for full opacity. Possible values: transparent, black, blue, white, red, grey, teal, amber, pink, purple, yellow, green, brown, cyan, indigo, lime, orange. |
shadowOffset | array | The values in the array define the horizontal and vertical offset of the shadow. Example: if the shadowOffset is set to [2, 4], the shadow will be offset by 2 pixels horizontally and 4 pixels vertically from its original position. |
shadowRadius | string or integer | The border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0. |
shadowStyle | string | The blur style to apply on the shadow: normal, solid, outer, inner. |
Base Styles (Inherited)
This widget also inherits these base styles:
Property | Type | Description |
---|---|---|
visible | boolean | Toggle a widget visibility on/off. Note that an invisible widget will not occupy UI space, unless the visibilityTransitionDuration is specified. |
visibilityTransitionDuration | number | Specify the duration in seconds when a widget animates between visible and not visible state. Note that setting this value will cause the widget to still occupy the UI space even when it is not visible. |
elevation | integer | The z-coordinate at which to place this material relative to its parent. A non-zero value will show a shadow, with its size relative to the elevation value. (Minimum: 0, Maximum: 24) |
elevationShadowColor | Color | The shadow color for the elevation. |
elevationBorderRadius | integer / string | If the widget has a borderRadius, this should be changed to have the same value. Use with CSS-like notation (1 to 4 integers). |
alignment | Alignment | Align this widget relative to its parent. |
stackPositionTop | integer | The distance of the child's top edge from the top of the stack. This is applicable only for Stack's children. |
stackPositionBottom | integer | The distance that the child's bottom edge from the bottom of the stack. This is applicable only for Stack's children. |
stackPositionLeft | integer | The distance that the child's left edge from the left of the stack. This is applicable only for Stack's children. |
stackPositionRight | integer | The distance that the child's right edge from the right of the stack. This is applicable only for Stack's children. |
captureWebPointer | boolean | Applicable for Web only. When overlaying widgets on top of certain HTML container (e.g., Maps), the mouse click is captured by the HTML container, causing issue interacting with the widget. Use this to capture and maintain the mouse pointer on your widget. |
Example Usage
Slidable:
styles:
direction: horizontal
closeOnScroll: true
dragStartBehavior: start
useTextDirection: true
startDrawer:
options:
extentRatio: 0.001 # we can keep the extent ratio small so that dismissible action looks smooth
openThreshold: 0.25
motion: behind
dismissible:
dismissThreshold: 0.75
dismissalDurationMs: 300
resizeDurationMs: 300
motion: inversedDrawer
onDismissed:
showToast:
message: Item dismissed
endDrawer:
children:
- icon: star
label: Favorite
backgroundColor: yellow
onTap:
showToast:
message: Added to favorites
child:
Container:
padding: 16
child:
Text: "Swipe me left or right"
Motion Types
Drawer Motion Types
The Slidable widget supports four types of drawer motion animations:
- scroll: A basic sliding motion
- stretch: Adds a stretching effect while sliding
- behind: Reveals the actions from behind the main content
- drawer: Classic drawer-style sliding animation
Dismissible Motion Types
For dismissible drawers, five types of motion animations are available:
- inversedDrawer: Reversed drawer-style animation (default)
- drawer: Standard drawer animation
- behind: Reveals content from behind
- scroll: Scrolls with the gesture
- stretch: Stretches during dismissal
By utilizing these properties and configurations, you can create intuitive swipe-based interactions in your application using the Slidable widget.