@@ -584,6 +584,17 @@ class SlidableDrawerDelegate extends SlidableStackDelegate {
584584 }
585585}
586586
587+ /// A controller that keep tracks of the active [SlidableState] and close
588+ /// the previous one.
589+ class SlidableController {
590+ SlidableState _activeState;
591+ SlidableState get activeState => _activeState;
592+ set activeState (SlidableState value) {
593+ _activeState? .close ();
594+ _activeState = value;
595+ }
596+ }
597+
587598/// A widget that can be slid in both direction of the specified axis.
588599///
589600/// If the direction is [Axis.horizontal] , this widget can be slid to the left or to the right,
@@ -619,6 +630,7 @@ class Slidable extends StatefulWidget {
619630 bool closeOnScroll = true ,
620631 bool enabled = true ,
621632 SlideToDismissDelegate slideToDismissDelegate,
633+ SlidableController controller,
622634 }) : this .builder (
623635 key: key,
624636 child: child,
@@ -633,6 +645,7 @@ class Slidable extends StatefulWidget {
633645 closeOnScroll: closeOnScroll,
634646 enabled: enabled,
635647 slideToDismissDelegate: slideToDismissDelegate,
648+ controller: controller,
636649 );
637650
638651 /// Creates a widget that can be slid.
@@ -663,6 +676,7 @@ class Slidable extends StatefulWidget {
663676 this .closeOnScroll = true ,
664677 this .enabled = true ,
665678 this .slideToDismissDelegate,
679+ this .controller,
666680 }) : assert (delegate != null ),
667681 assert (direction != null ),
668682 assert (
@@ -684,6 +698,9 @@ class Slidable extends StatefulWidget {
684698 /// The widget below this widget in the tree.
685699 final Widget child;
686700
701+ /// The controller that tracks the active [Slidable] and keep only one open.
702+ final SlidableController controller;
703+
687704 /// A delegate that builds slide actions that appears when the child has been dragged
688705 /// down or to the right.
689706 final SlideActionDelegate actionDelegate;
@@ -869,6 +886,7 @@ class SlidableState extends State<Slidable>
869886 _actionsMoveController.dispose ();
870887 _resizeController? .dispose ();
871888 _removeScrollingNotifierListener ();
889+ widget.controller? .activeState = null ;
872890 super .dispose ();
873891 }
874892
@@ -910,6 +928,7 @@ class SlidableState extends State<Slidable>
910928
911929 void _handleDragStart (DragStartDetails details) {
912930 _dragUnderway = true ;
931+ widget.controller? .activeState = this ;
913932 _dragExtent = _actionsMoveController.value *
914933 _actionsDragAxisExtent *
915934 _dragExtent.sign;
@@ -923,6 +942,10 @@ class SlidableState extends State<Slidable>
923942 }
924943
925944 void _handleDragUpdate (DragUpdateDetails details) {
945+ if (widget.controller != null && widget.controller.activeState != this ) {
946+ return ;
947+ }
948+
926949 final double delta = details.primaryDelta;
927950 _dragExtent += delta;
928951 setState (() {
@@ -935,6 +958,10 @@ class SlidableState extends State<Slidable>
935958 }
936959
937960 void _handleDragEnd (DragEndDetails details) {
961+ if (widget.controller != null && widget.controller.activeState != this ) {
962+ return ;
963+ }
964+
938965 _dragUnderway = false ;
939966 final double velocity = details.primaryVelocity;
940967 final bool shouldOpen = velocity.sign == _dragExtent.sign;
0 commit comments