Swipeable constructor

const Swipeable({
  1. required Key key,
  2. required Widget child,
  3. required SwipeDirectionCallback onSwipe,
  4. Widget? background,
  5. Widget? secondaryBackground,
  6. ConfirmSwipeCallback? confirmSwipe,
  7. SwipeDirection direction = SwipeDirection.horizontal,
  8. Map<SwipeDirection, double> dismissThresholds = const <SwipeDirection, double>{},
  9. double maxOffset = 0.4,
  10. Duration movementDuration = const Duration(milliseconds: 200),
  11. double crossAxisEndOffset = 0.0,
  12. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  13. Set<PointerDeviceKind> allowedPointerKinds = const {PointerDeviceKind.invertedStylus, PointerDeviceKind.stylus, PointerDeviceKind.touch},
})

Creates a widget that calls a function when swiped.

The key argument must not be null because Swipeables are commonly used in lists and removed from the list when dismissed. Without keys, the default behavior is to sync widgets based on their index in the list, which means the item after the dismissed item would be synced with the state of the dismissed item. Using keys causes the widgets to sync according to their keys and avoids this pitfall.

Implementation

const Swipeable({
  required Key key,
  required this.child,
  required this.onSwipe,
  this.background,
  this.secondaryBackground,
  this.confirmSwipe,
  this.direction = SwipeDirection.horizontal,
  this.dismissThresholds = const <SwipeDirection, double>{},
  this.maxOffset = 0.4,
  this.movementDuration = const Duration(milliseconds: 200),
  this.crossAxisEndOffset = 0.0,
  this.dragStartBehavior = DragStartBehavior.start,
  this.allowedPointerKinds = const {
    PointerDeviceKind.invertedStylus,
    PointerDeviceKind.stylus,
    PointerDeviceKind.touch
  },
})  : assert(secondaryBackground == null || background != null),
      super(key: key);