letsar / flutter_slidable

A Flutter implementation of slidable list item with directional slide actions.
MIT License
2.73k stars 592 forks source link

How can I close Slidable if I don't use SlidableAction(autoColose=true) #424

Open KhaiHOK38 opened 1 year ago

KhaiHOK38 commented 1 year ago

Slidable( enabled: isEnableSlidable, closeOnScroll: isCloseSlid, key: const ValueKey(0), endActionPane: ActionPane( dragDismissible: isCloseSlid, motion: const BehindMotion(), children: actionButton( status: widget.leaveRequest.status, leaveRequest: widget.leaveRequest, context: context), ), child: LeaveCardWidget( leaveRequest: widget.leaveRequest, isHaveAction: isEnableSlidable, ), ),

alanrubin commented 1 year ago

You can use Slidable.of(context)?.close() to close it. Make sure you use the context beneath the SlidableAction action, for example:

SlidableAction(
  autoClose: false,
  onPressed: (BuildContext context) async {
    final slidableController = Slidable.of(context);

    await showDialog<String>(
      context: context,
      builder: (BuildContext slContext) =>
          CancelBookingConfirmationDialog(
        onConfirm: () {
          print(">Confirm booking!");
        },
        onCancel: () {
          // Close slidable control
          slidableController?.close();
        },
      ),
    );
  },
  backgroundColor: ColorTheme.rufous,
  foregroundColor: Colors.white,
  label: t.app.cancelBooking,
),
chuvanhoang888 commented 1 year ago

You can use CustomSlidableAction instead of SlideableAction