How to close slidable on tap of anywhere on the screen outside Slidable widget
I want to close slidable even if click bottom tab or something on spp bar
I am also facing same problem.
me too
Same issue occurred, if anyone resolved please comment ans.
flutter_swipe_action_cell, i have you this library
this code work for me, you guys will like it:
import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart';
void main() { runApp(const MyApp()); }
class MyApp extends StatelessWidget { const MyApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( home: SlidableOwner( child: Scaffold( appBar: AppBar( elevation: 0, title: const Text('Slidable from outside'), ), body: SlidableAutoCloseBehavior( closeWhenOpened: true, closeWhenTapped: true, child: ListView.builder( itemCount: 10, itemBuilder: (context, index) { return MyTile(index: index); }, ), ), ), ), ); } }
class MyText extends StatelessWidget { final int index;
const MyText({ super.key, required this.index, });
@override Widget build(BuildContext context) { return Slidable( closeOnScroll: true, endActionPane: const ActionPane( dragDismissible: false, motion: ScrollMotion(), children: [ SlidableAction( backgroundColor: Color(0xFFe0e0e0), icon: Icons.remove_circle_outline_outlined, autoClose: true, onPressed: null, ) ], ), child: SlidableOwnerTarget( id: index, child: Container( padding: const EdgeInsets.all(24), child: Text("HuyKaiser"), ), ), ); } }
class SlidableOwnerScope extends InheritedWidget { final SlidableOwnerState state;
const SlidableOwnerScope({ super.key, required super.child, required this.state, });
@override bool updateShouldNotify(SlidableOwnerScope oldWidget) { return false; } }
class SlidableOwner extends StatefulWidget { final Widget child;
const SlidableOwner({ super.key, required this.child, });
@override State<SlidableOwner> createState() => SlidableOwnerState();
static SlidableOwnerState of(BuildContext context) { return context.getInheritedWidgetOfExactType<SlidableOwnerScope>()!.state; } }
class SlidableOwnerState extends State<SlidableOwner> { final _controllers = <Object, SlidableController>{};
@override Widget build(BuildContext context) { return SlidableOwnerScope( state: this, child: widget.child, ); }
Future
if (controller == null) return;
return controller.close();
}
Future
class SlidableOwnerTarget extends StatefulWidget { final Widget child; final Object id;
const SlidableOwnerTarget({ super.key, required this.child, required this.id, });
@override State<SlidableOwnerTarget> createState() => _SlidableOwnerTargetState(); }
class _SlidableOwnerTargetState extends State<SlidableOwnerTarget> { late SlidableOwnerState _slidableOwnerState;
@override void didChangeDependencies() { super.didChangeDependencies();
_slidableOwnerState = SlidableOwner.of(context);
_slidableOwnerState._controllers[widget.id] = Slidable.of(context)!;
}
@override void dispose() { super.dispose(); _slidableOwnerState._controllers.remove(widget.id); }
@override Widget build(BuildContext context) { return widget.child; } }
still relevant