Slidable

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

PropertyTypeDescription
groupTagstringGroups related slidable widgets together for coordinated behavior
enabledbooleanEnables or disables the slidable functionality. Defaults to true
closeOnScrollbooleanDetermines if the slidable should close when scrolling. Defaults to true
directionAxisSets the slide direction (horizontal or vertical). Defaults to horizontal
dragStartBehaviorDragStartBehaviorDetermines when dragging starts (down or start). Defaults to down
useTextDirectionbooleanRespects the text direction for RTL/LTR layouts. Defaults to true
startDrawerobjectConfiguration for the start (left/top) action pane
endDrawerobjectConfiguration for the end (right/bottom) action pane
childWidgetThe main content widget that will be slidable

Drawer Configuration

Each drawer (start/end) can be configured with the following properties:

Options

PropertyTypeDescription
extentRatiodoubleRatio of the screen width that the drawer can extend to. Defaults to 0.25
motionstringType of motion animation (scroll, stretch, behind, drawer)
openThresholddouble?Threshold for when the drawer should fully open
closeThresholddouble?Threshold for when the drawer should close

Dismissible Options

Each drawer can be made dismissible with these configuration options:

PropertyTypeDescription
dismissThresholddoubleThreshold at which dismissal is triggered. Defaults to 0.75
dismissalDurationMsintDuration of the dismiss animation in milliseconds. Defaults to 300
resizeDurationMsintDuration of the resize animation after dismissal. Defaults to 300
motionstringDismissal animation type (inversedDrawer, drawer, behind, scroll, stretch)
onDismissedActionCallback function executed when the drawer is dismissed

Action Properties

Each action in the drawer can have the following properties:

PropertyTypeDescription
iconIconDataThe icon to display for the action
labelstringText label for the action
backgroundColorColorBackground color of the action button. Defaults to blue
foregroundColorColorColor of the icon and text. Defaults to white
paddingEdgeInsetsPadding around the action button. Defaults to EdgeInsets.zero
spacingdoubleSpace between the icon and label. Defaults to 4.0
autoClosebooleanWhether to close the drawer after action is triggered. Defaults to true
flexintFlex value for action width distribution. Defaults to 1
borderRadiusBorderRadiusBorder radius of the action button. Defaults to BorderRadius.zero
onTapActionCallback function to execute when the action is tapped

Box Styles (Inherited)

This widget also inherits these styles:

PropertyTypeDescription
margininteger/stringMargin with CSS-style notation (1 to 4 integers) e.g. margin: 5 20 5
paddinginteger/stringPadding with CSS-style notation (1 to 4 integers) e.g. padding: 5 20 5
backgroundColorColorThe background color of this widget.
backgroundImageBackgroundImageThe background image of this widget.
backgroundGradientGradientThe background gradient of this widget.
borderBorderThe border of this widget.
shadowShadowThe shadow of this widget
clipContentbooleanSome 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.
widthintegerThe width of this widget.
heightintegerThe height of this widget.
borderRadiusstring or integerThe border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0.
borderColorinteger or stringSets 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.
borderWidthintegerThickness of the border. Minimum value should be 0.
shadowColorinteger or stringSets 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.
shadowOffsetarrayThe 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.
shadowRadiusstring or integerThe border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0.
shadowStylestringThe blur style to apply on the shadow: normal, solid, outer, inner.

Base Styles (Inherited)

This widget also inherits these base styles:

PropertyTypeDescription
visiblebooleanToggle a widget visibility on/off. Note that an invisible widget will not occupy UI space, unless the visibilityTransitionDuration is specified.
visibilityTransitionDurationnumberSpecify 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.
elevationintegerThe 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)
elevationShadowColorColorThe shadow color for the elevation.
elevationBorderRadiusinteger / stringIf the widget has a borderRadius, this should be changed to have the same value. Use with CSS-like notation (1 to 4 integers).
alignmentAlignmentAlign this widget relative to its parent.
stackPositionTopintegerThe distance of the child's top edge from the top of the stack. This is applicable only for Stack's children.
stackPositionBottomintegerThe distance that the child's bottom edge from the bottom of the stack. This is applicable only for Stack's children.
stackPositionLeftintegerThe distance that the child's left edge from the left of the stack. This is applicable only for Stack's children.
stackPositionRightintegerThe distance that the child's right edge from the right of the stack. This is applicable only for Stack's children.
captureWebPointerbooleanApplicable 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:

  1. scroll: A basic sliding motion
  2. stretch: Adds a stretching effect while sliding
  3. behind: Reveals the actions from behind the main content
  4. drawer: Classic drawer-style sliding animation

Dismissible Motion Types

For dismissible drawers, five types of motion animations are available:

  1. inversedDrawer: Reversed drawer-style animation (default)
  2. drawer: Standard drawer animation
  3. behind: Reveals content from behind
  4. scroll: Scrolls with the gesture
  5. stretch: Stretches during dismissal

By utilizing these properties and configurations, you can create intuitive swipe-based interactions in your application using the Slidable widget.