diff --git a/example/lib/main.dart b/example/lib/main.dart index 97415b3b..6b9b041a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -10,14 +10,18 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { + + return MaterialApp( title: 'Slidable Example', + // ListView.builder(itemBuilder: ) home: Scaffold( body: ListView( children: [ Slidable( // Specify a key if the Slidable is dismissible. key: const ValueKey(0), + enabled: false, // The start action pane is the one at the left or the top side. startActionPane: ActionPane( @@ -72,12 +76,15 @@ class MyApp extends StatelessWidget { // The child of the Slidable is what the user sees when the // component is not dragged. - child: const ListTile(title: Text('Slide me')), + child:(controller)=> GestureDetector( + onTap: (){ + controller.openEndActionPane(); + }, + child: const ListTile(title: Text('Slide me'))), ), Slidable( // Specify a key if the Slidable is dismissible. key: const ValueKey(1), - // The start action pane is the one at the left or the top side. startActionPane: const ActionPane( // A motion is a widget used to control how the pane animates. @@ -108,8 +115,7 @@ class MyApp extends StatelessWidget { motion: const ScrollMotion(), dismissible: DismissiblePane(onDismissed: () {}), children: const [ - SlidableAction( - // An action can be bigger than the others. + SlidableAction(// An action can be bigger than the others. flex: 2, onPressed: doNothing, backgroundColor: Color(0xFF7BC043), @@ -129,7 +135,7 @@ class MyApp extends StatelessWidget { // The child of the Slidable is what the user sees when the // component is not dragged. - child: const ListTile(title: Text('Slide me')), + child: (controller)=>const ListTile(title: Text('Slide me')), ), ], ), diff --git a/example/lib/main_demo.dart b/example/lib/main_demo.dart index afb1b97d..6a9c98d6 100644 --- a/example/lib/main_demo.dart +++ b/example/lib/main_demo.dart @@ -1,363 +1,363 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_slidable/flutter_slidable.dart'; - -void main() => runApp(const MyApp()); - -class MyApp extends StatelessWidget { - const MyApp({ - Key? key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Slidable Demo', - theme: ThemeData( - primarySwatch: Colors.blue, - visualDensity: VisualDensity.adaptivePlatformDensity, - ), - home: const AppState( - direction: Axis.horizontal, - child: MyHomePage(), - ), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({ - Key? key, - }) : super(key: key); - - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - bool alive = true; - - @override - Widget build(BuildContext context) { - final direction = AppState.of(context)!.direction; - return Scaffold( - appBar: AppBar( - title: const Text('Flutter Slidable'), - ), - body: SlidableAutoCloseBehavior( - child: ListView( - scrollDirection: flipAxis(direction), - children: [ - Directionality( - textDirection: TextDirection.rtl, - child: Slidable( - key: const ValueKey(1), - groupTag: '0', - direction: direction, - startActionPane: const ActionPane( - openThreshold: 0.1, - closeThreshold: 0.4, - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.grey, text: 'hello'), - ), - ), - Slidable( - key: const ValueKey(2), - groupTag: '0', - direction: direction, - startActionPane: const ActionPane( - motion: StretchMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: StretchMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 3), - ], - ), - child: const Tile(color: Colors.pink, text: 'hello 2'), - ), - Slidable( - key: const ValueKey(3), - direction: direction, - startActionPane: const ActionPane( - motion: ScrollMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: ScrollMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.yellow, text: 'hello 3'), - ), - if (alive) - Slidable( - key: const ValueKey(4), - direction: direction, - startActionPane: ActionPane( - motion: const DrawerMotion(), - dismissible: DismissiblePane( - onDismissed: () { - setState(() { - alive = false; - }); - }, - closeOnCancel: true, - confirmDismiss: () async { - return await showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('Are you sure?'), - content: const Text('Are you sure to dismiss?'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(true); - }, - child: const Text('Yes'), - ), - TextButton( - onPressed: () { - Navigator.of(context).pop(false); - }, - child: const Text('No'), - ), - ], - ); - }, - ) ?? - false; - }, - ), - children: const [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: DrawerMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.lime, text: 'hello 4'), - ), - Slidable( - key: const ValueKey(5), - direction: direction, - startActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.grey, text: 'hello'), - ), - Slidable( - key: const ValueKey(6), - direction: direction, - startActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.grey, text: 'hello'), - ), - Slidable( - key: const ValueKey(7), - direction: direction, - startActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.grey, text: 'hello'), - ), - Slidable( - key: const ValueKey(8), - direction: direction, - startActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.grey, text: 'hello'), - ), - ], - ), - ), - ); - } -} - -class SlideAction extends StatelessWidget { - const SlideAction({ - Key? key, - required this.color, - required this.icon, - this.flex = 1, - }) : super(key: key); - - final Color color; - final IconData icon; - final int flex; - - @override - Widget build(BuildContext context) { - return SlidableAction( - flex: flex, - backgroundColor: color, - foregroundColor: Colors.white, - onPressed: (_) { - print(icon); - }, - icon: icon, - label: 'hello', - ); - } -} - -class Tile extends StatelessWidget { - const Tile({ - Key? key, - required this.color, - required this.text, - }) : super(key: key); - - final Color color; - final String text; - - @override - Widget build(BuildContext context) { - final direction = AppState.of(context)!.direction; - return ActionTypeListener( - child: GestureDetector( - onTap: () { - print('$text'); - }, - onLongPress: () => Slidable.of(context)!.openEndActionPane(), - child: Container( - color: color, - height: direction == Axis.horizontal ? 100 : double.infinity, - width: direction == Axis.horizontal ? double.infinity : 100, - child: Center(child: Text(text)), - ), - ), - ); - } -} - -class ActionTypeListener extends StatefulWidget { - const ActionTypeListener({ - Key? key, - required this.child, - }) : super(key: key); - - final Widget child; - - @override - _ActionTypeListenerState createState() => _ActionTypeListenerState(); -} - -class _ActionTypeListenerState extends State { - ValueNotifier? _actionPaneTypeValueNotifier; - - @override - void initState() { - super.initState(); - _actionPaneTypeValueNotifier = Slidable.of(context)?.actionPaneType; - _actionPaneTypeValueNotifier?.addListener(_onActionPaneTypeChanged); - } - - @override - void dispose() { - _actionPaneTypeValueNotifier?.removeListener(_onActionPaneTypeChanged); - super.dispose(); - } - - void _onActionPaneTypeChanged() { - debugPrint('Value is ${_actionPaneTypeValueNotifier?.value}'); - } - - @override - Widget build(BuildContext context) { - return widget.child; - } -} - -class AppState extends InheritedWidget { - const AppState({ - Key? key, - required this.direction, - required Widget child, - }) : super(key: key, child: child); - - final Axis direction; - - @override - bool updateShouldNotify(covariant AppState oldWidget) { - return direction != oldWidget.direction; - } - - static AppState? of(BuildContext context) { - return context.dependOnInheritedWidgetOfExactType(); - } -} +// import 'package:flutter/material.dart'; +// import 'package:flutter_slidable/flutter_slidable.dart'; +// +// void main() => runApp(const MyApp()); +// +// class MyApp extends StatelessWidget { +// const MyApp({ +// Key? key, +// }) : super(key: key); +// +// @override +// Widget build(BuildContext context) { +// return MaterialApp( +// title: 'Slidable Demo', +// theme: ThemeData( +// primarySwatch: Colors.blue, +// visualDensity: VisualDensity.adaptivePlatformDensity, +// ), +// home: const AppState( +// direction: Axis.horizontal, +// child: MyHomePage(), +// ), +// ); +// } +// } +// +// class MyHomePage extends StatefulWidget { +// const MyHomePage({ +// Key? key, +// }) : super(key: key); +// +// @override +// _MyHomePageState createState() => _MyHomePageState(); +// } +// +// class _MyHomePageState extends State { +// bool alive = true; +// +// @override +// Widget build(BuildContext context) { +// final direction = AppState.of(context)!.direction; +// return Scaffold( +// appBar: AppBar( +// title: const Text('Flutter Slidable'), +// ), +// body: SlidableAutoCloseBehavior( +// child: ListView( +// scrollDirection: flipAxis(direction), +// children: [ +// Directionality( +// textDirection: TextDirection.rtl, +// child: Slidable( +// key: const ValueKey(1), +// groupTag: '0', +// direction: direction, +// startActionPane: const ActionPane( +// openThreshold: 0.1, +// closeThreshold: 0.4, +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.grey, text: 'hello'), +// ), +// ), +// Slidable( +// key: const ValueKey(2), +// groupTag: '0', +// direction: direction, +// startActionPane: const ActionPane( +// motion: StretchMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: StretchMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 3), +// ], +// ), +// child: const Tile(color: Colors.pink, text: 'hello 2'), +// ), +// Slidable( +// key: const ValueKey(3), +// direction: direction, +// startActionPane: const ActionPane( +// motion: ScrollMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: ScrollMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.yellow, text: 'hello 3'), +// ), +// if (alive) +// Slidable( +// key: const ValueKey(4), +// direction: direction, +// startActionPane: ActionPane( +// motion: const DrawerMotion(), +// dismissible: DismissiblePane( +// onDismissed: () { +// setState(() { +// alive = false; +// }); +// }, +// closeOnCancel: true, +// confirmDismiss: () async { +// return await showDialog( +// context: context, +// builder: (context) { +// return AlertDialog( +// title: const Text('Are you sure?'), +// content: const Text('Are you sure to dismiss?'), +// actions: [ +// TextButton( +// onPressed: () { +// Navigator.of(context).pop(true); +// }, +// child: const Text('Yes'), +// ), +// TextButton( +// onPressed: () { +// Navigator.of(context).pop(false); +// }, +// child: const Text('No'), +// ), +// ], +// ); +// }, +// ) ?? +// false; +// }, +// ), +// children: const [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: DrawerMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.lime, text: 'hello 4'), +// ), +// Slidable( +// key: const ValueKey(5), +// direction: direction, +// startActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.grey, text: 'hello'), +// ), +// Slidable( +// key: const ValueKey(6), +// direction: direction, +// startActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.grey, text: 'hello'), +// ), +// Slidable( +// key: const ValueKey(7), +// direction: direction, +// startActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.grey, text: 'hello'), +// ), +// Slidable( +// key: const ValueKey(8), +// direction: direction, +// startActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.grey, text: 'hello'), +// ), +// ], +// ), +// ), +// ); +// } +// } +// +// class SlideAction extends StatelessWidget { +// const SlideAction({ +// Key? key, +// required this.color, +// required this.icon, +// this.flex = 1, +// }) : super(key: key); +// +// final Color color; +// final IconData icon; +// final int flex; +// +// @override +// Widget build(BuildContext context) { +// return SlidableAction( +// flex: flex, +// backgroundColor: color, +// foregroundColor: Colors.white, +// onPressed: (_) { +// print(icon); +// }, +// icon: icon, +// label: 'hello', +// ); +// } +// } +// +// class Tile extends StatelessWidget { +// const Tile({ +// Key? key, +// required this.color, +// required this.text, +// }) : super(key: key); +// +// final Color color; +// final String text; +// +// @override +// Widget build(BuildContext context) { +// final direction = AppState.of(context)!.direction; +// return ActionTypeListener( +// child: GestureDetector( +// onTap: () { +// print('$text'); +// }, +// onLongPress: () => Slidable.of(context)!.openEndActionPane(), +// child: Container( +// color: color, +// height: direction == Axis.horizontal ? 100 : double.infinity, +// width: direction == Axis.horizontal ? double.infinity : 100, +// child: Center(child: Text(text)), +// ), +// ), +// ); +// } +// } +// +// class ActionTypeListener extends StatefulWidget { +// const ActionTypeListener({ +// Key? key, +// required this.child, +// }) : super(key: key); +// +// final Widget child; +// +// @override +// _ActionTypeListenerState createState() => _ActionTypeListenerState(); +// } +// +// class _ActionTypeListenerState extends State { +// ValueNotifier? _actionPaneTypeValueNotifier; +// +// @override +// void initState() { +// super.initState(); +// _actionPaneTypeValueNotifier = Slidable.of(context)?.actionPaneType; +// _actionPaneTypeValueNotifier?.addListener(_onActionPaneTypeChanged); +// } +// +// @override +// void dispose() { +// _actionPaneTypeValueNotifier?.removeListener(_onActionPaneTypeChanged); +// super.dispose(); +// } +// +// void _onActionPaneTypeChanged() { +// debugPrint('Value is ${_actionPaneTypeValueNotifier?.value}'); +// } +// +// @override +// Widget build(BuildContext context) { +// return widget.child; +// } +// } +// +// class AppState extends InheritedWidget { +// const AppState({ +// Key? key, +// required this.direction, +// required Widget child, +// }) : super(key: key, child: child); +// +// final Axis direction; +// +// @override +// bool updateShouldNotify(covariant AppState oldWidget) { +// return direction != oldWidget.direction; +// } +// +// static AppState? of(BuildContext context) { +// return context.dependOnInheritedWidgetOfExactType(); +// } +// } diff --git a/example/lib/main_example.dart b/example/lib/main_example.dart index c782adf3..568ee16d 100644 --- a/example/lib/main_example.dart +++ b/example/lib/main_example.dart @@ -1,225 +1,225 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_slidable/flutter_slidable.dart'; - -import 'common.dart'; - -void main() { - runApp(MyApp()); -} - -const actions = [ - SlideAction( - color: Color(0xFFFE4A49), - icon: Icons.delete, - label: 'Delete', - ), - SlideAction( - color: Color(0xFF21B7CA), - icon: Icons.share, - label: 'Share', - ), -]; - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Slidable', - theme: ThemeData( - primarySwatch: Colors.blue, - visualDensity: VisualDensity.adaptivePlatformDensity, - ), - home: const MyHomePage(), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({ - Key? key, - }) : super(key: key); - - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State - with SingleTickerProviderStateMixin { - AnimationController? controller; - - @override - void initState() { - super.initState(); - controller = AnimationController( - vsync: this, - upperBound: 0.5, - duration: const Duration(milliseconds: 2000), - ); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Flutter Slidable'), - ), - body: SlidablePlayer( - animation: controller, - child: ListView( - children: const [ - SizedBox(height: 20), - MySlidable(motion: BehindMotion()), - MySlidable(motion: StretchMotion()), - MySlidable(motion: ScrollMotion()), - MySlidable(motion: DrawerMotion()), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: () { - if (controller!.isCompleted) { - controller!.reverse(); - } else if (controller!.isDismissed) { - controller!.forward(); - } - }, - child: const Icon(Icons.play_arrow), - ), - ); - } -} - -class SlidablePlayer extends StatefulWidget { - const SlidablePlayer({ - Key? key, - required this.animation, - required this.child, - }) : super(key: key); - - final Animation? animation; - final Widget child; - - @override - _SlidablePlayerState createState() => _SlidablePlayerState(); - - static _SlidablePlayerState? of(BuildContext context) { - return context.findAncestorStateOfType<_SlidablePlayerState>(); - } -} - -class _SlidablePlayerState extends State { - final Set controllers = {}; - - @override - void initState() { - super.initState(); - widget.animation!.addListener(handleAnimationChanged); - } - - @override - void dispose() { - widget.animation!.removeListener(handleAnimationChanged); - super.dispose(); - } - - void handleAnimationChanged() { - final value = widget.animation!.value; - controllers.forEach((controller) { - controller!.ratio = value; - }); - } - - @override - Widget build(BuildContext context) { - return widget.child; - } -} - -class SlidableControllerSender extends StatefulWidget { - const SlidableControllerSender({ - Key? key, - this.child, - }) : super(key: key); - - final Widget? child; - - @override - _SlidableControllerSenderState createState() => - _SlidableControllerSenderState(); -} - -class _SlidableControllerSenderState extends State { - SlidableController? controller; - _SlidablePlayerState? playerState; - - @override - void initState() { - super.initState(); - controller = Slidable.of(context); - playerState = SlidablePlayer.of(context); - playerState!.controllers.add(controller); - } - - @override - void dispose() { - playerState!.controllers.remove(controller); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return widget.child!; - } -} - -class MySlidable extends StatelessWidget { - const MySlidable({ - Key? key, - required this.motion, - }) : super(key: key); - - final Widget motion; - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.all(8), - child: Slidable( - startActionPane: ActionPane( - motion: motion, - children: actions, - ), - child: SlidableControllerSender( - child: Tile(text: motion.runtimeType.toString()), - ), - ), - ); - } -} - -class SlideAction extends StatelessWidget { - const SlideAction({ - Key? key, - required this.color, - required this.icon, - required this.label, - this.flex = 1, - }) : super(key: key); - - final Color color; - final IconData icon; - final int flex; - final String label; - - @override - Widget build(BuildContext context) { - return SlidableAction( - flex: flex, - backgroundColor: color, - foregroundColor: Colors.white, - onPressed: (_) {}, - icon: icon, - label: label, - ); - } -} +// import 'package:flutter/material.dart'; +// import 'package:flutter_slidable/flutter_slidable.dart'; +// +// import 'common.dart'; +// +// void main() { +// runApp(MyApp()); +// } +// +// const actions = [ +// SlideAction( +// color: Color(0xFFFE4A49), +// // icon: Icons.delete, +// label: 'Delete', +// ), +// SlideAction( +// color: Color(0xFF21B7CA), +// icon: Icons.share, +// label: 'Share', +// ), +// ]; +// +// class MyApp extends StatelessWidget { +// @override +// Widget build(BuildContext context) { +// return MaterialApp( +// title: 'Flutter Slidable', +// theme: ThemeData( +// primarySwatch: Colors.blue, +// visualDensity: VisualDensity.adaptivePlatformDensity, +// ), +// home: const MyHomePage(), +// ); +// } +// } +// +// class MyHomePage extends StatefulWidget { +// const MyHomePage({ +// Key? key, +// }) : super(key: key); +// +// @override +// _MyHomePageState createState() => _MyHomePageState(); +// } +// +// class _MyHomePageState extends State +// with SingleTickerProviderStateMixin { +// AnimationController? controller; +// +// @override +// void initState() { +// super.initState(); +// controller = AnimationController( +// vsync: this, +// upperBound: 0.5, +// duration: const Duration(milliseconds: 2000), +// ); +// } +// +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// appBar: AppBar( +// title: const Text('Flutter Slidable'), +// ), +// body: SlidablePlayer( +// animation: controller, +// child: ListView( +// children: const [ +// SizedBox(height: 20), +// MySlidable(motion: BehindMotion()), +// MySlidable(motion: StretchMotion()), +// MySlidable(motion: ScrollMotion()), +// MySlidable(motion: DrawerMotion()), +// ], +// ), +// ), +// floatingActionButton: FloatingActionButton( +// onPressed: () { +// if (controller!.isCompleted) { +// controller!.reverse(); +// } else if (controller!.isDismissed) { +// controller!.forward(); +// } +// }, +// child: const Icon(Icons.play_arrow), +// ), +// ); +// } +// } +// +// class SlidablePlayer extends StatefulWidget { +// const SlidablePlayer({ +// Key? key, +// required this.animation, +// required this.child, +// }) : super(key: key); +// +// final Animation? animation; +// final Widget child; +// +// @override +// _SlidablePlayerState createState() => _SlidablePlayerState(); +// +// static _SlidablePlayerState? of(BuildContext context) { +// return context.findAncestorStateOfType<_SlidablePlayerState>(); +// } +// } +// +// class _SlidablePlayerState extends State { +// final Set controllers = {}; +// +// @override +// void initState() { +// super.initState(); +// widget.animation!.addListener(handleAnimationChanged); +// } +// +// @override +// void dispose() { +// widget.animation!.removeListener(handleAnimationChanged); +// super.dispose(); +// } +// +// void handleAnimationChanged() { +// final value = widget.animation!.value; +// controllers.forEach((controller) { +// controller!.ratio = value; +// }); +// } +// +// @override +// Widget build(BuildContext context) { +// return widget.child; +// } +// } +// +// class SlidableControllerSender extends StatefulWidget { +// const SlidableControllerSender({ +// Key? key, +// this.child, +// }) : super(key: key); +// +// final Widget? child; +// +// @override +// _SlidableControllerSenderState createState() => +// _SlidableControllerSenderState(); +// } +// +// class _SlidableControllerSenderState extends State { +// SlidableController? controller; +// _SlidablePlayerState? playerState; +// +// @override +// void initState() { +// super.initState(); +// controller = Slidable.of(context); +// playerState = SlidablePlayer.of(context); +// playerState!.controllers.add(controller); +// } +// +// @override +// void dispose() { +// playerState!.controllers.remove(controller); +// super.dispose(); +// } +// +// @override +// Widget build(BuildContext context) { +// return widget.child!; +// } +// } +// +// class MySlidable extends StatelessWidget { +// const MySlidable({ +// Key? key, +// required this.motion, +// }) : super(key: key); +// +// final Widget motion; +// +// @override +// Widget build(BuildContext context) { +// return Padding( +// padding: const EdgeInsets.all(8), +// child: Slidable( +// startActionPane: ActionPane( +// motion: motion, +// children: actions, +// ), +// child: SlidableControllerSender( +// child: Tile(text: motion.runtimeType.toString()), +// ), +// ), +// ); +// } +// } +// +// class SlideAction extends StatelessWidget { +// const SlideAction({ +// Key? key, +// required this.color, +// required this.icon, +// required this.label, +// this.flex = 1, +// }) : super(key: key); +// +// final Color color; +// final IconData icon; +// final int flex; +// final String label; +// +// @override +// Widget build(BuildContext context) { +// return SlidableAction( +// flex: flex, +// backgroundColor: color, +// foregroundColor: Colors.white, +// onPressed: (_) {}, +// icon: icon, +// label: label, +// ); +// } +// } diff --git a/example/lib/main_issue_251.dart b/example/lib/main_issue_251.dart index 3d6fa47d..219ec599 100644 --- a/example/lib/main_issue_251.dart +++ b/example/lib/main_issue_251.dart @@ -1,202 +1,202 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_slidable/flutter_slidable.dart'; - -void main() => runApp(const MyApp()); - -class MyApp extends StatelessWidget { - const MyApp({ - Key? key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Slidable Example', - home: Scaffold( - body: ListView( - children: const [ - ListItem( - title: 'ERIC', - subtitle: 'Subtitle 1', - ), - ListItem( - title: 'ERIC', - subtitle: 'Subtitle 2', - ), - ListItem( - title: 'ERIC', - subtitle: 'Subtitle 3', - ), - ListItem( - title: 'ERIC', - subtitle: 'Subtitle 4', - ), - ], - ), - ), - ); - } -} - -class ListItem extends StatefulWidget { - const ListItem({ - Key? key, - required this.title, - required this.subtitle, - }) : super(key: key); - - final String title; - final String subtitle; - - @override - State createState() => _ListItemState(); -} - -class _ListItemState extends State { - final colorNotifier = ValueNotifier(Colors.grey); - - @override - void initState() { - super.initState(); - } - - @override - Widget build(BuildContext context) { - return SizedBox( - height: 50, - child: Slidable( - startActionPane: ActionPane( - closeThreshold: 0.5, - openThreshold: 0.6, - extentRatio: 0.5, - motion: const BehindMotion(), - children: [RememberedArea(colorNotifier: colorNotifier)], - ), - child: Row( - children: [ - Hint(colorNotifier: colorNotifier), - Expanded( - child: Item( - title: widget.title, - subtitle: widget.subtitle, - ), - ) - ], - ), - ), - ); - } -} - -class RememberedArea extends StatefulWidget { - RememberedArea({ - Key? key, - required this.colorNotifier, - ColorTween? colorTween, - }) : colorTween = colorTween ?? - ColorTween( - begin: Colors.yellow, - end: Colors.green, - ), - super(key: key); - - final ColorTween colorTween; - final ValueNotifier colorNotifier; - - @override - State createState() => _RememberedAreaState(); -} - -class _RememberedAreaState extends State { - double maxValue = 0; - late final animation = Slidable.of(context)!.animation; - - @override - void initState() { - super.initState(); - animation.addListener(handleValueChanged); - animation.addStatusListener(handleStatusChanged); - } - - double get colorValue => animation.value * 2; - Color get color => widget.colorTween.lerp(colorValue)!; - - void handleValueChanged() { - if (colorValue > maxValue) { - maxValue = colorValue; - widget.colorNotifier.value = color; - } - } - - void handleStatusChanged(AnimationStatus status) { - if (status == AnimationStatus.dismissed) { - maxValue = 0; - } - } - - @override - void dispose() { - animation.removeListener(handleValueChanged); - animation.removeStatusListener(handleStatusChanged); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return AnimatedBuilder( - animation: animation, - builder: (context, child) { - return Expanded( - child: SizedBox.expand( - child: ColoredBox(color: color), - ), - ); - }, - ); - } -} - -class Hint extends StatelessWidget { - const Hint({ - Key? key, - required this.colorNotifier, - }) : super(key: key); - - final ValueNotifier colorNotifier; - - @override - Widget build(BuildContext context) { - return ValueListenableBuilder( - valueListenable: colorNotifier, - builder: (context, color, child) { - return Container(width: 8, color: color); - }, - ); - } -} - -class Item extends StatelessWidget { - const Item({ - Key? key, - required this.title, - required this.subtitle, - }) : super(key: key); - - final String title; - final String subtitle; - - @override - Widget build(BuildContext context) { - final textTheme = Theme.of(context).textTheme; - return Padding( - padding: const EdgeInsets.only(left: 8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded(child: Text(title, style: textTheme.bodyText1)), - Expanded(child: Text(subtitle, style: textTheme.bodyText2)), - ], - ), - ); - } -} +// import 'package:flutter/material.dart'; +// import 'package:flutter_slidable/flutter_slidable.dart'; +// +// void main() => runApp(const MyApp()); +// +// class MyApp extends StatelessWidget { +// const MyApp({ +// Key? key, +// }) : super(key: key); +// +// @override +// Widget build(BuildContext context) { +// return MaterialApp( +// title: 'Slidable Example', +// home: Scaffold( +// body: ListView( +// children: const [ +// ListItem( +// title: 'ERIC', +// subtitle: 'Subtitle 1', +// ), +// ListItem( +// title: 'ERIC', +// subtitle: 'Subtitle 2', +// ), +// ListItem( +// title: 'ERIC', +// subtitle: 'Subtitle 3', +// ), +// ListItem( +// title: 'ERIC', +// subtitle: 'Subtitle 4', +// ), +// ], +// ), +// ), +// ); +// } +// } +// +// class ListItem extends StatefulWidget { +// const ListItem({ +// Key? key, +// required this.title, +// required this.subtitle, +// }) : super(key: key); +// +// final String title; +// final String subtitle; +// +// @override +// State createState() => _ListItemState(); +// } +// +// class _ListItemState extends State { +// final colorNotifier = ValueNotifier(Colors.grey); +// +// @override +// void initState() { +// super.initState(); +// } +// +// @override +// Widget build(BuildContext context) { +// return SizedBox( +// height: 50, +// child: Slidable( +// startActionPane: ActionPane( +// closeThreshold: 0.5, +// openThreshold: 0.6, +// extentRatio: 0.5, +// motion: const BehindMotion(), +// children: [RememberedArea(colorNotifier: colorNotifier)], +// ), +// child: Row( +// children: [ +// Hint(colorNotifier: colorNotifier), +// Expanded( +// child: Item( +// title: widget.title, +// subtitle: widget.subtitle, +// ), +// ) +// ], +// ), +// ), +// ); +// } +// } +// +// class RememberedArea extends StatefulWidget { +// RememberedArea({ +// Key? key, +// required this.colorNotifier, +// ColorTween? colorTween, +// }) : colorTween = colorTween ?? +// ColorTween( +// begin: Colors.yellow, +// end: Colors.green, +// ), +// super(key: key); +// +// final ColorTween colorTween; +// final ValueNotifier colorNotifier; +// +// @override +// State createState() => _RememberedAreaState(); +// } +// +// class _RememberedAreaState extends State { +// double maxValue = 0; +// late final animation = Slidable.of(context)!.animation; +// +// @override +// void initState() { +// super.initState(); +// animation.addListener(handleValueChanged); +// animation.addStatusListener(handleStatusChanged); +// } +// +// double get colorValue => animation.value * 2; +// Color get color => widget.colorTween.lerp(colorValue)!; +// +// void handleValueChanged() { +// if (colorValue > maxValue) { +// maxValue = colorValue; +// widget.colorNotifier.value = color; +// } +// } +// +// void handleStatusChanged(AnimationStatus status) { +// if (status == AnimationStatus.dismissed) { +// maxValue = 0; +// } +// } +// +// @override +// void dispose() { +// animation.removeListener(handleValueChanged); +// animation.removeStatusListener(handleStatusChanged); +// super.dispose(); +// } +// +// @override +// Widget build(BuildContext context) { +// return AnimatedBuilder( +// animation: animation, +// builder: (context, child) { +// return Expanded( +// child: SizedBox.expand( +// child: ColoredBox(color: color), +// ), +// ); +// }, +// ); +// } +// } +// +// class Hint extends StatelessWidget { +// const Hint({ +// Key? key, +// required this.colorNotifier, +// }) : super(key: key); +// +// final ValueNotifier colorNotifier; +// +// @override +// Widget build(BuildContext context) { +// return ValueListenableBuilder( +// valueListenable: colorNotifier, +// builder: (context, color, child) { +// return Container(width: 8, color: color); +// }, +// ); +// } +// } +// +// class Item extends StatelessWidget { +// const Item({ +// Key? key, +// required this.title, +// required this.subtitle, +// }) : super(key: key); +// +// final String title; +// final String subtitle; +// +// @override +// Widget build(BuildContext context) { +// final textTheme = Theme.of(context).textTheme; +// return Padding( +// padding: const EdgeInsets.only(left: 8), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// Expanded(child: Text(title, style: textTheme.bodyText1)), +// Expanded(child: Text(subtitle, style: textTheme.bodyText2)), +// ], +// ), +// ); +// } +// } diff --git a/example/lib/main_outside_list.dart b/example/lib/main_outside_list.dart index cc5ede90..0ff6927b 100644 --- a/example/lib/main_outside_list.dart +++ b/example/lib/main_outside_list.dart @@ -1,253 +1,253 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_slidable/flutter_slidable.dart'; - -void main() { - runApp(MyApp()); -} - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - primarySwatch: Colors.blue, - visualDensity: VisualDensity.adaptivePlatformDensity, - ), - home: const AppState( - direction: Axis.horizontal, - child: MyHomePage(), - ), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({ - Key? key, - }) : super(key: key); - - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - bool alive = true; - - @override - Widget build(BuildContext context) { - final direction = AppState.of(context)!.direction; - return Scaffold( - appBar: AppBar( - title: const Text('Flutter Slidable'), - ), - body: SlidableAutoCloseBehavior( - child: Column( - children: [ - Directionality( - textDirection: TextDirection.rtl, - child: Padding( - padding: const EdgeInsets.all(16), - child: Slidable( - groupTag: '0', - direction: direction, - startActionPane: const ActionPane( - openThreshold: 0.1, - closeThreshold: 0.4, - motion: BehindMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: BehindMotion(), - children: [ - SlideAction( - color: Colors.red, icon: Icons.delete_forever), - SlideAction( - color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.grey, text: 'hello'), - ), - ), - ), - Padding( - padding: const EdgeInsets.all(16), - child: Slidable( - groupTag: '0', - direction: direction, - startActionPane: const ActionPane( - motion: StretchMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: StretchMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 3), - ], - ), - child: const Tile(color: Colors.pink, text: 'hello 2'), - ), - ), - Padding( - padding: const EdgeInsets.all(16), - child: Slidable( - direction: direction, - startActionPane: const ActionPane( - motion: ScrollMotion(), - children: [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: ScrollMotion(), - children: [ - SlideAction(color: Colors.red, icon: Icons.delete_forever), - SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.yellow, text: 'hello 3'), - ), - ), - if (alive) - Padding( - padding: const EdgeInsets.all(16), - child: Slidable( - key: const ValueKey(4), - direction: direction, - startActionPane: ActionPane( - motion: const DrawerMotion(), - dismissible: DismissiblePane( - onDismissed: () { - setState(() { - alive = false; - }); - }, - closeOnCancel: true, - confirmDismiss: () async { - return await showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('Are you sure?'), - content: - const Text('Are you sure to dismiss?'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(true); - }, - child: const Text('Yes'), - ), - TextButton( - onPressed: () { - Navigator.of(context).pop(false); - }, - child: const Text('No'), - ), - ], - ); - }, - ) ?? - false; - }, - ), - children: const [ - SlideAction(color: Colors.green, icon: Icons.share), - SlideAction(color: Colors.amber, icon: Icons.delete), - ], - ), - endActionPane: const ActionPane( - motion: DrawerMotion(), - children: [ - SlideAction( - color: Colors.red, icon: Icons.delete_forever), - SlideAction( - color: Colors.blue, icon: Icons.alarm, flex: 2), - ], - ), - child: const Tile(color: Colors.lime, text: 'hello 4'), - ), - ), - ], - ), - ), - ); - } -} - -class SlideAction extends StatelessWidget { - const SlideAction({ - Key? key, - required this.color, - required this.icon, - this.flex = 1, - }) : super(key: key); - - final Color color; - final IconData icon; - final int flex; - - @override - Widget build(BuildContext context) { - return SlidableAction( - flex: flex, - backgroundColor: color, - foregroundColor: Colors.white, - onPressed: (_) {}, - icon: icon, - label: 'hello', - ); - } -} - -class Tile extends StatelessWidget { - const Tile({ - Key? key, - required this.color, - required this.text, - }) : super(key: key); - - final Color color; - final String text; - - @override - Widget build(BuildContext context) { - final direction = AppState.of(context)!.direction; - return GestureDetector( - onLongPress: () => Slidable.of(context)!.openEndActionPane(), - child: Container( - color: color, - height: direction == Axis.horizontal ? 100 : double.infinity, - width: direction == Axis.horizontal ? double.infinity : 100, - child: Center(child: Text(text)), - ), - ); - } -} - -class AppState extends InheritedWidget { - const AppState({ - Key? key, - required this.direction, - required Widget child, - }) : super(key: key, child: child); - - final Axis direction; - - @override - bool updateShouldNotify(covariant AppState oldWidget) { - return direction != oldWidget.direction; - } - - static AppState? of(BuildContext context) { - return context.dependOnInheritedWidgetOfExactType(); - } -} +// import 'package:flutter/material.dart'; +// import 'package:flutter_slidable/flutter_slidable.dart'; +// +// void main() { +// runApp(MyApp()); +// } +// +// class MyApp extends StatelessWidget { +// @override +// Widget build(BuildContext context) { +// return MaterialApp( +// title: 'Flutter Demo', +// theme: ThemeData( +// primarySwatch: Colors.blue, +// visualDensity: VisualDensity.adaptivePlatformDensity, +// ), +// home: const AppState( +// direction: Axis.horizontal, +// child: MyHomePage(), +// ), +// ); +// } +// } +// +// class MyHomePage extends StatefulWidget { +// const MyHomePage({ +// Key? key, +// }) : super(key: key); +// +// @override +// _MyHomePageState createState() => _MyHomePageState(); +// } +// +// class _MyHomePageState extends State { +// bool alive = true; +// +// @override +// Widget build(BuildContext context) { +// final direction = AppState.of(context)!.direction; +// return Scaffold( +// appBar: AppBar( +// title: const Text('Flutter Slidable'), +// ), +// body: SlidableAutoCloseBehavior( +// child: Column( +// children: [ +// Directionality( +// textDirection: TextDirection.rtl, +// child: Padding( +// padding: const EdgeInsets.all(16), +// child: Slidable( +// groupTag: '0', +// direction: direction, +// startActionPane: const ActionPane( +// openThreshold: 0.1, +// closeThreshold: 0.4, +// motion: BehindMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: BehindMotion(), +// children: [ +// SlideAction( +// color: Colors.red, icon: Icons.delete_forever), +// SlideAction( +// color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.grey, text: 'hello'), +// ), +// ), +// ), +// Padding( +// padding: const EdgeInsets.all(16), +// child: Slidable( +// groupTag: '0', +// direction: direction, +// startActionPane: const ActionPane( +// motion: StretchMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: StretchMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 3), +// ], +// ), +// child: const Tile(color: Colors.pink, text: 'hello 2'), +// ), +// ), +// Padding( +// padding: const EdgeInsets.all(16), +// child: Slidable( +// direction: direction, +// startActionPane: const ActionPane( +// motion: ScrollMotion(), +// children: [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: ScrollMotion(), +// children: [ +// SlideAction(color: Colors.red, icon: Icons.delete_forever), +// SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.yellow, text: 'hello 3'), +// ), +// ), +// if (alive) +// Padding( +// padding: const EdgeInsets.all(16), +// child: Slidable( +// key: const ValueKey(4), +// direction: direction, +// startActionPane: ActionPane( +// motion: const DrawerMotion(), +// dismissible: DismissiblePane( +// onDismissed: () { +// setState(() { +// alive = false; +// }); +// }, +// closeOnCancel: true, +// confirmDismiss: () async { +// return await showDialog( +// context: context, +// builder: (context) { +// return AlertDialog( +// title: const Text('Are you sure?'), +// content: +// const Text('Are you sure to dismiss?'), +// actions: [ +// TextButton( +// onPressed: () { +// Navigator.of(context).pop(true); +// }, +// child: const Text('Yes'), +// ), +// TextButton( +// onPressed: () { +// Navigator.of(context).pop(false); +// }, +// child: const Text('No'), +// ), +// ], +// ); +// }, +// ) ?? +// false; +// }, +// ), +// children: const [ +// SlideAction(color: Colors.green, icon: Icons.share), +// SlideAction(color: Colors.amber, icon: Icons.delete), +// ], +// ), +// endActionPane: const ActionPane( +// motion: DrawerMotion(), +// children: [ +// SlideAction( +// color: Colors.red, icon: Icons.delete_forever), +// SlideAction( +// color: Colors.blue, icon: Icons.alarm, flex: 2), +// ], +// ), +// child: const Tile(color: Colors.lime, text: 'hello 4'), +// ), +// ), +// ], +// ), +// ), +// ); +// } +// } +// +// class SlideAction extends StatelessWidget { +// const SlideAction({ +// Key? key, +// required this.color, +// required this.icon, +// this.flex = 1, +// }) : super(key: key); +// +// final Color color; +// final IconData icon; +// final int flex; +// +// @override +// Widget build(BuildContext context) { +// return SlidableAction( +// flex: flex, +// backgroundColor: color, +// foregroundColor: Colors.white, +// onPressed: (_) {}, +// icon: icon, +// label: 'hello', +// ); +// } +// } +// +// class Tile extends StatelessWidget { +// const Tile({ +// Key? key, +// required this.color, +// required this.text, +// }) : super(key: key); +// +// final Color color; +// final String text; +// +// @override +// Widget build(BuildContext context) { +// final direction = AppState.of(context)!.direction; +// return GestureDetector( +// onLongPress: () => Slidable.of(context)!.openEndActionPane(), +// child: Container( +// color: color, +// height: direction == Axis.horizontal ? 100 : double.infinity, +// width: direction == Axis.horizontal ? double.infinity : 100, +// child: Center(child: Text(text)), +// ), +// ); +// } +// } +// +// class AppState extends InheritedWidget { +// const AppState({ +// Key? key, +// required this.direction, +// required Widget child, +// }) : super(key: key, child: child); +// +// final Axis direction; +// +// @override +// bool updateShouldNotify(covariant AppState oldWidget) { +// return direction != oldWidget.direction; +// } +// +// static AppState? of(BuildContext context) { +// return context.dependOnInheritedWidgetOfExactType(); +// } +// } diff --git a/example/pubspec.lock b/example/pubspec.lock index 05d2639d..11c43ffe 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -42,7 +42,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.16.0" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -87,7 +87,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.3" meta: dependency: transitive description: @@ -101,7 +101,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -113,7 +113,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -148,14 +148,21 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.8" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.1" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=1.22.0" diff --git a/lib/src/slidable.dart b/lib/src/slidable.dart index 889e67a2..33fbd18f 100644 --- a/lib/src/slidable.dart +++ b/lib/src/slidable.dart @@ -99,7 +99,9 @@ class Slidable extends StatefulWidget { /// The widget below this widget in the tree. /// /// {@macro flutter.widgets.ProxyWidget.child} - final Widget child; + final Widget Function(SlidableController controller) child; + + // final Function Widget(BuildContext context) child; @override _SlidableState createState() => _SlidableState(); @@ -136,6 +138,7 @@ class _SlidableState extends State super.initState(); controller = SlidableController(this) ..actionPaneType.addListener(handleActionPanelTypeChanged); + } @override @@ -233,7 +236,7 @@ class _SlidableState extends State child: SlidableAutoCloseBehaviorInteractor( groupTag: widget.groupTag, controller: controller, - child: widget.child, + child: widget.child.call(controller), ), ); diff --git a/pubspec.lock b/pubspec.lock index bf006e63..d548b072 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "39.0.0" + version: "31.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "2.8.0" args: dependency: transitive description: @@ -50,6 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.5" clock: dependency: transitive description: @@ -63,7 +70,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.16.0" + version: "1.15.0" convert: dependency: transitive description: @@ -77,7 +84,7 @@ packages: name: coverage url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.0.3" crypto: dependency: transitive description: @@ -91,7 +98,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.2.0" file: dependency: transitive description: @@ -171,7 +178,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.3" meta: dependency: transitive description: @@ -213,7 +220,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.0" pool: dependency: transitive description: @@ -281,7 +288,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -316,42 +323,42 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.21.1" + version: "1.19.5" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.8" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.13" + version: "0.4.9" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.1" vm_service: dependency: transitive description: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "8.3.0" + version: "7.5.0" watcher: dependency: transitive description: @@ -381,5 +388,5 @@ packages: source: hosted version: "3.1.1" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.16.0 <3.0.0" flutter: ">=1.22.0" diff --git a/pubspec.yaml b/pubspec.yaml index f27e3b65..3154c832 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_slidable description: A Flutter implementation of slidable list item with directional slide actions that can be dismissed. -version: 1.3.0 +version: 1.3.1 homepage: https://github.com/letsar/flutter_slidable environment: diff --git a/test/action_pane_motions_test.dart b/test/action_pane_motions_test.dart index b4cfa922..853e219f 100644 --- a/test/action_pane_motions_test.dart +++ b/test/action_pane_motions_test.dart @@ -1,158 +1,158 @@ -// ignore_fo_file: avoid_redundant_argument_values - -import 'package:flutter/material.dart'; -import 'package:flutter_slidable/src/action_pane_motions.dart'; -import 'package:flutter_slidable/src/slidable.dart'; -import 'package:flutter_test/flutter_test.dart'; - -// ignore_for_file: avoid_redundant_argument_values - -void main() { - group('BehindMotion', () { - testMotionForAllModes( - motion: const BehindMotion(), - startCenters: [12.5, 62.5], - endCenters: [112.5, 162.5], - ); - }); - - group('ScrollMotion', () { - testMotionForAllModes( - motion: const ScrollMotion(), - startCenters: [-37.5, 12.5], - endCenters: [162.5, 212.5], - ); - }); - - group('StretchMotion', () { - testMotionForAllModes( - motion: const StretchMotion(), - startCenters: [6.25, 31.25], - endCenters: [156.25, 181.25], - ); - }); - - group('DrawerMotion', () { - testMotionForAllModes( - motion: const DrawerMotion(), - startCenters: [0, 12.5], - endCenters: [162.5, 200], - ); - }); -} - -void testMotionForAllModes({ - required Widget motion, - required List startCenters, - required List endCenters, -}) { - const directions = Axis.values; - final isStartValues = [true, false]; - for (final direction in directions) { - for (final isStart in isStartValues) { - final pane = isStart ? 'start' : 'end'; - final centers = isStart ? startCenters : endCenters; - testWidgets('control check in $direction for ${pane}ActionPane', - (tester) async { - await testMotion( - tester: tester, - motion: motion, - isStart: isStart, - direction: direction, - centers: centers, - ); - }); - } - } -} - -Future testMotion({ - required WidgetTester tester, - required Widget motion, - required bool isStart, - required Axis direction, - required List centers, -}) async { - const key1 = ValueKey(1); - const key2 = ValueKey(2); - - final findKey1 = find.byKey(key1); - final findKey2 = find.byKey(key2); - final findSlidable = find.byType(Slidable); - final isHorizontal = direction == Axis.horizontal; - - double getCenter(Finder finder) { - if (isHorizontal) { - return tester.getCenter(finder).dx; - } else { - return tester.getCenter(finder).dy; - } - } - - final pane = ActionPane( - motion: motion, - children: const [ - Expanded(flex: 1, child: SizedBox.expand(key: key1)), - Expanded(flex: 3, child: SizedBox.expand(key: key2)), - ], - ); - - final startActionPane = isStart ? pane : null; - final endActionPane = isStart ? null : pane; - - const double extent = 200; - final double height = isHorizontal ? 100 : extent; - final double width = isHorizontal ? extent : 100; - Offset drag = Offset(isStart ? 50 : -50, 0); - if (!isHorizontal) { - drag = Offset(0, isStart ? 50 : -50); - } - - await tester.pumpWidget( - Align( - alignment: Alignment.topLeft, - child: SizedBox( - height: height, - width: width, - child: Directionality( - textDirection: TextDirection.ltr, - child: Slidable( - direction: direction, - startActionPane: startActionPane, - endActionPane: endActionPane, - child: const SizedBox.expand(), - ), - ), - ), - ), - ); - - await tester.dragAndHold(findSlidable, drag); - - double centerKey1 = centers[0]; - double centerKey2 = centers[1]; - - expect(getCenter(findKey1), moreOrLessEquals(centerKey1)); - expect(getCenter(findKey2), moreOrLessEquals(centerKey2)); - - await tester.dragAndHold(findSlidable, drag); - - centerKey1 = 12.5; - centerKey2 = 62.5; - - if (!isStart) { - centerKey1 = extent / 2 + centerKey1; - centerKey2 = extent / 2 + centerKey2; - } - - expect(getCenter(findKey1), moreOrLessEquals(centerKey1)); - expect(getCenter(findKey2), moreOrLessEquals(centerKey2)); -} - -extension on WidgetTester { - Future dragAndHold(Finder finder, Offset offset) async { - final gesture = await startGesture(getCenter(finder)); - await gesture.moveBy(offset); - await pump(); - } -} +// // ignore_fo_file: avoid_redundant_argument_values +// +// import 'package:flutter/material.dart'; +// import 'package:flutter_slidable/src/action_pane_motions.dart'; +// import 'package:flutter_slidable/src/slidable.dart'; +// import 'package:flutter_test/flutter_test.dart'; +// +// // ignore_for_file: avoid_redundant_argument_values +// +// void main() { +// group('BehindMotion', () { +// testMotionForAllModes( +// motion: const BehindMotion(), +// startCenters: [12.5, 62.5], +// endCenters: [112.5, 162.5], +// ); +// }); +// +// group('ScrollMotion', () { +// testMotionForAllModes( +// motion: const ScrollMotion(), +// startCenters: [-37.5, 12.5], +// endCenters: [162.5, 212.5], +// ); +// }); +// +// group('StretchMotion', () { +// testMotionForAllModes( +// motion: const StretchMotion(), +// startCenters: [6.25, 31.25], +// endCenters: [156.25, 181.25], +// ); +// }); +// +// group('DrawerMotion', () { +// testMotionForAllModes( +// motion: const DrawerMotion(), +// startCenters: [0, 12.5], +// endCenters: [162.5, 200], +// ); +// }); +// } +// +// void testMotionForAllModes({ +// required Widget motion, +// required List startCenters, +// required List endCenters, +// }) { +// const directions = Axis.values; +// final isStartValues = [true, false]; +// for (final direction in directions) { +// for (final isStart in isStartValues) { +// final pane = isStart ? 'start' : 'end'; +// final centers = isStart ? startCenters : endCenters; +// testWidgets('control check in $direction for ${pane}ActionPane', +// (tester) async { +// await testMotion( +// tester: tester, +// motion: motion, +// isStart: isStart, +// direction: direction, +// centers: centers, +// ); +// }); +// } +// } +// } +// +// Future testMotion({ +// required WidgetTester tester, +// required Widget motion, +// required bool isStart, +// required Axis direction, +// required List centers, +// }) async { +// const key1 = ValueKey(1); +// const key2 = ValueKey(2); +// +// final findKey1 = find.byKey(key1); +// final findKey2 = find.byKey(key2); +// final findSlidable = find.byType(Slidable); +// final isHorizontal = direction == Axis.horizontal; +// +// double getCenter(Finder finder) { +// if (isHorizontal) { +// return tester.getCenter(finder).dx; +// } else { +// return tester.getCenter(finder).dy; +// } +// } +// +// final pane = ActionPane( +// motion: motion, +// children: const [ +// Expanded(flex: 1, child: SizedBox.expand(key: key1)), +// Expanded(flex: 3, child: SizedBox.expand(key: key2)), +// ], +// ); +// +// final startActionPane = isStart ? pane : null; +// final endActionPane = isStart ? null : pane; +// +// const double extent = 200; +// final double height = isHorizontal ? 100 : extent; +// final double width = isHorizontal ? extent : 100; +// Offset drag = Offset(isStart ? 50 : -50, 0); +// if (!isHorizontal) { +// drag = Offset(0, isStart ? 50 : -50); +// } +// +// await tester.pumpWidget( +// Align( +// alignment: Alignment.topLeft, +// child: SizedBox( +// height: height, +// width: width, +// child: Directionality( +// textDirection: TextDirection.ltr, +// child: Slidable( +// direction: direction, +// startActionPane: startActionPane, +// endActionPane: endActionPane, +// child: const SizedBox.expand(), +// ), +// ), +// ), +// ), +// ); +// +// await tester.dragAndHold(findSlidable, drag); +// +// double centerKey1 = centers[0]; +// double centerKey2 = centers[1]; +// +// expect(getCenter(findKey1), moreOrLessEquals(centerKey1)); +// expect(getCenter(findKey2), moreOrLessEquals(centerKey2)); +// +// await tester.dragAndHold(findSlidable, drag); +// +// centerKey1 = 12.5; +// centerKey2 = 62.5; +// +// if (!isStart) { +// centerKey1 = extent / 2 + centerKey1; +// centerKey2 = extent / 2 + centerKey2; +// } +// +// expect(getCenter(findKey1), moreOrLessEquals(centerKey1)); +// expect(getCenter(findKey2), moreOrLessEquals(centerKey2)); +// } +// +// extension on WidgetTester { +// Future dragAndHold(Finder finder, Offset offset) async { +// final gesture = await startGesture(getCenter(finder)); +// await gesture.moveBy(offset); +// await pump(); +// } +// } diff --git a/test/dismissible_pane_test.dart b/test/dismissible_pane_test.dart index c63f7a20..8f26d369 100644 --- a/test/dismissible_pane_test.dart +++ b/test/dismissible_pane_test.dart @@ -1,374 +1,374 @@ -import 'package:flutter/gestures.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_slidable/src/action_pane_motions.dart'; -import 'package:flutter_slidable/src/actions.dart'; -import 'package:flutter_slidable/src/controller.dart'; -import 'package:flutter_slidable/src/dismissible_pane.dart'; -import 'package:flutter_slidable/src/dismissible_pane_motions.dart'; -import 'package:flutter_slidable/src/slidable.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'common.dart'; - -void main() { - group('DismissiblePane', () { - testWidgets('throws if Slidable has not key', (tester) async { - void handleDismissed() {} - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - height: 200, - width: 100, - child: Slidable( - startActionPane: ActionPane( - dismissible: DismissiblePane( - onDismissed: handleDismissed, - dismissThreshold: 0.8, - motion: - // For coverage: - // ignore: prefer_const_constructors - InversedDrawerMotion(), - ), - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: const SizedBox.expand(), - ), - ), - ), - ), - ); - - await tester.timedDrag( - find.byTypeOf(), - const Offset(80, 0), - const Duration(milliseconds: 400), - ); - - final flutterError = tester.takeException() as FlutterError?; - expect(flutterError, isNotNull); - }); - - testWidgets('startActionPane can be dismissed', (tester) async { - bool dismissed = false; - void handleDismissed() { - dismissed = true; - } - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - height: 200, - width: 100, - child: Slidable( - key: const ValueKey('key'), - startActionPane: ActionPane( - dismissible: DismissiblePane( - onDismissed: handleDismissed, - dismissThreshold: 0.8, - ), - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: const SizedBox.expand(), - ), - ), - ), - ), - ); - - expect(dismissed, isFalse); - - await tester.timedDrag( - find.byTypeOf(), - const Offset(80, 0), - const Duration(milliseconds: 400), - ); - - // Wait for the resize to finish. - await tester.pumpAndSettle(); - - expect(dismissed, isTrue); - }); - - testWidgets('endActionPane can be dismissed', (tester) async { - bool dismissed = false; - void handleDismissed() { - dismissed = true; - } - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - height: 200, - width: 100, - child: Slidable( - key: const ValueKey('key'), - endActionPane: ActionPane( - dismissible: DismissiblePane( - onDismissed: handleDismissed, - dismissThreshold: 0.8, - ), - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: const SizedBox.expand(), - ), - ), - ), - ), - ); - - expect(dismissed, isFalse); - - await tester.timedDrag( - find.byTypeOf(), - const Offset(-80, 0), - const Duration(milliseconds: 400), - ); - - // Wait for the resize to finish. - await tester.pumpAndSettle(); - - expect(dismissed, isTrue); - }); - - testWidgets( - 'startActionPane cannot be drag dismissed if dragDismissible is false', - (tester) async { - bool dismissed = false; - void handleDismissed() { - dismissed = true; - } - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - height: 200, - width: 100, - child: Slidable( - key: const ValueKey('key'), - startActionPane: ActionPane( - dragDismissible: false, - dismissible: DismissiblePane( - onDismissed: handleDismissed, - dismissThreshold: 0.8, - ), - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: const SizedBox.expand(), - ), - ), - ), - ), - ); - - expect(dismissed, isFalse); - - await tester.timedDrag( - find.byTypeOf(), - const Offset(80, 0), - const Duration(milliseconds: 400), - ); - - // Wait for the resize to finish. - await tester.pumpAndSettle(); - - expect(dismissed, isFalse); - }); - - testWidgets( - 'when the drag is not past the dismissThreshold, the Slidable stays open', - (tester) async { - bool dismissed = false; - void handleDismissed() { - dismissed = true; - } - - const startActionPaneKey = ValueKey('start'); - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - height: 200, - width: 100, - child: Slidable( - key: const ValueKey('key'), - startActionPane: ActionPane( - key: startActionPaneKey, - dismissible: DismissiblePane( - onDismissed: handleDismissed, - dismissThreshold: 0.8, - ), - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: const SizedBox.expand(), - ), - ), - ), - ), - ); - - expect(dismissed, isFalse); - - await tester.timedDrag( - find.byTypeOf(), - const Offset(70, 0), - const Duration(milliseconds: 400), - ); - - // Wait for the resize to finish. - await tester.pumpAndSettle(); - - expect(dismissed, isFalse); - expect(find.byKey(startActionPaneKey), findsOneWidget); - }); - - testWidgets('can be canceled', (tester) async { - bool dismissed = false; - void handleDismissed() { - dismissed = true; - } - - Future confirmDismiss() async { - return false; - } - - const startActionPaneKey = ValueKey('start'); - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - height: 200, - width: 100, - child: Slidable( - key: const ValueKey('key'), - startActionPane: ActionPane( - key: startActionPaneKey, - dismissible: DismissiblePane( - onDismissed: handleDismissed, - confirmDismiss: confirmDismiss, - dismissThreshold: 0.8, - ), - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: const SizedBox.expand(), - ), - ), - ), - ), - ); - - expect(dismissed, isFalse); - - await tester.timedDrag( - find.byTypeOf(), - const Offset(80, 0), - const Duration(milliseconds: 400), - ); - - // Wait for the resize to finish. - await tester.pumpAndSettle(); - - expect(dismissed, isFalse); - expect(find.byKey(startActionPaneKey), findsOneWidget); - }); - - testWidgets('can be canceled and close', (tester) async { - bool dismissed = false; - void handleDismissed() { - dismissed = true; - } - - Future confirmDismiss() async { - return false; - } - - const startActionPaneKey = ValueKey('start'); - SlidableController? controller; - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - height: 200, - width: 100, - child: Slidable( - key: const ValueKey('key'), - startActionPane: ActionPane( - key: startActionPaneKey, - dismissible: DismissiblePane( - onDismissed: handleDismissed, - confirmDismiss: confirmDismiss, - closeOnCancel: true, - dismissThreshold: 0.8, - ), - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: Builder( - builder: (context) { - controller = Slidable.of(context); - return const SizedBox.expand(); - }, - ), - ), - ), - ), - ), - ); - - expect(dismissed, isFalse); - - await tester.timedDrag( - find.byTypeOf(), - const Offset(80, 0), - const Duration(milliseconds: 400), - ); - - // Wait for the resize to finish. - await tester.pumpAndSettle(); - - expect(dismissed, isFalse); - expect(controller!.ratio, 0); - }); - }); -} +// import 'package:flutter/gestures.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_slidable/src/action_pane_motions.dart'; +// import 'package:flutter_slidable/src/actions.dart'; +// import 'package:flutter_slidable/src/controller.dart'; +// import 'package:flutter_slidable/src/dismissible_pane.dart'; +// import 'package:flutter_slidable/src/dismissible_pane_motions.dart'; +// import 'package:flutter_slidable/src/slidable.dart'; +// import 'package:flutter_test/flutter_test.dart'; +// +// import 'common.dart'; +// +// void main() { +// group('DismissiblePane', () { +// testWidgets('throws if Slidable has not key', (tester) async { +// void handleDismissed() {} +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Center( +// child: SizedBox( +// height: 200, +// width: 100, +// child: Slidable( +// startActionPane: ActionPane( +// dismissible: DismissiblePane( +// onDismissed: handleDismissed, +// dismissThreshold: 0.8, +// motion: +// // For coverage: +// // ignore: prefer_const_constructors +// InversedDrawerMotion(), +// ), +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: const SizedBox.expand(), +// ), +// ), +// ), +// ), +// ); +// +// await tester.timedDrag( +// find.byTypeOf(), +// const Offset(80, 0), +// const Duration(milliseconds: 400), +// ); +// +// final flutterError = tester.takeException() as FlutterError?; +// expect(flutterError, isNotNull); +// }); +// +// testWidgets('startActionPane can be dismissed', (tester) async { +// bool dismissed = false; +// void handleDismissed() { +// dismissed = true; +// } +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Center( +// child: SizedBox( +// height: 200, +// width: 100, +// child: Slidable( +// key: const ValueKey('key'), +// startActionPane: ActionPane( +// dismissible: DismissiblePane( +// onDismissed: handleDismissed, +// dismissThreshold: 0.8, +// ), +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: const SizedBox.expand(), +// ), +// ), +// ), +// ), +// ); +// +// expect(dismissed, isFalse); +// +// await tester.timedDrag( +// find.byTypeOf(), +// const Offset(80, 0), +// const Duration(milliseconds: 400), +// ); +// +// // Wait for the resize to finish. +// await tester.pumpAndSettle(); +// +// expect(dismissed, isTrue); +// }); +// +// testWidgets('endActionPane can be dismissed', (tester) async { +// bool dismissed = false; +// void handleDismissed() { +// dismissed = true; +// } +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Center( +// child: SizedBox( +// height: 200, +// width: 100, +// child: Slidable( +// key: const ValueKey('key'), +// endActionPane: ActionPane( +// dismissible: DismissiblePane( +// onDismissed: handleDismissed, +// dismissThreshold: 0.8, +// ), +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: const SizedBox.expand(), +// ), +// ), +// ), +// ), +// ); +// +// expect(dismissed, isFalse); +// +// await tester.timedDrag( +// find.byTypeOf(), +// const Offset(-80, 0), +// const Duration(milliseconds: 400), +// ); +// +// // Wait for the resize to finish. +// await tester.pumpAndSettle(); +// +// expect(dismissed, isTrue); +// }); +// +// testWidgets( +// 'startActionPane cannot be drag dismissed if dragDismissible is false', +// (tester) async { +// bool dismissed = false; +// void handleDismissed() { +// dismissed = true; +// } +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Center( +// child: SizedBox( +// height: 200, +// width: 100, +// child: Slidable( +// key: const ValueKey('key'), +// startActionPane: ActionPane( +// dragDismissible: false, +// dismissible: DismissiblePane( +// onDismissed: handleDismissed, +// dismissThreshold: 0.8, +// ), +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: const SizedBox.expand(), +// ), +// ), +// ), +// ), +// ); +// +// expect(dismissed, isFalse); +// +// await tester.timedDrag( +// find.byTypeOf(), +// const Offset(80, 0), +// const Duration(milliseconds: 400), +// ); +// +// // Wait for the resize to finish. +// await tester.pumpAndSettle(); +// +// expect(dismissed, isFalse); +// }); +// +// testWidgets( +// 'when the drag is not past the dismissThreshold, the Slidable stays open', +// (tester) async { +// bool dismissed = false; +// void handleDismissed() { +// dismissed = true; +// } +// +// const startActionPaneKey = ValueKey('start'); +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Center( +// child: SizedBox( +// height: 200, +// width: 100, +// child: Slidable( +// key: const ValueKey('key'), +// startActionPane: ActionPane( +// key: startActionPaneKey, +// dismissible: DismissiblePane( +// onDismissed: handleDismissed, +// dismissThreshold: 0.8, +// ), +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: const SizedBox.expand(), +// ), +// ), +// ), +// ), +// ); +// +// expect(dismissed, isFalse); +// +// await tester.timedDrag( +// find.byTypeOf(), +// const Offset(70, 0), +// const Duration(milliseconds: 400), +// ); +// +// // Wait for the resize to finish. +// await tester.pumpAndSettle(); +// +// expect(dismissed, isFalse); +// expect(find.byKey(startActionPaneKey), findsOneWidget); +// }); +// +// testWidgets('can be canceled', (tester) async { +// bool dismissed = false; +// void handleDismissed() { +// dismissed = true; +// } +// +// Future confirmDismiss() async { +// return false; +// } +// +// const startActionPaneKey = ValueKey('start'); +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Center( +// child: SizedBox( +// height: 200, +// width: 100, +// child: Slidable( +// key: const ValueKey('key'), +// startActionPane: ActionPane( +// key: startActionPaneKey, +// dismissible: DismissiblePane( +// onDismissed: handleDismissed, +// confirmDismiss: confirmDismiss, +// dismissThreshold: 0.8, +// ), +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: const SizedBox.expand(), +// ), +// ), +// ), +// ), +// ); +// +// expect(dismissed, isFalse); +// +// await tester.timedDrag( +// find.byTypeOf(), +// const Offset(80, 0), +// const Duration(milliseconds: 400), +// ); +// +// // Wait for the resize to finish. +// await tester.pumpAndSettle(); +// +// expect(dismissed, isFalse); +// expect(find.byKey(startActionPaneKey), findsOneWidget); +// }); +// +// testWidgets('can be canceled and close', (tester) async { +// bool dismissed = false; +// void handleDismissed() { +// dismissed = true; +// } +// +// Future confirmDismiss() async { +// return false; +// } +// +// const startActionPaneKey = ValueKey('start'); +// SlidableController? controller; +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Center( +// child: SizedBox( +// height: 200, +// width: 100, +// child: Slidable( +// key: const ValueKey('key'), +// startActionPane: ActionPane( +// key: startActionPaneKey, +// dismissible: DismissiblePane( +// onDismissed: handleDismissed, +// confirmDismiss: confirmDismiss, +// closeOnCancel: true, +// dismissThreshold: 0.8, +// ), +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: Builder( +// builder: (context) { +// controller = Slidable.of(context); +// return const SizedBox.expand(); +// }, +// ), +// ), +// ), +// ), +// ), +// ); +// +// expect(dismissed, isFalse); +// +// await tester.timedDrag( +// find.byTypeOf(), +// const Offset(80, 0), +// const Duration(milliseconds: 400), +// ); +// +// // Wait for the resize to finish. +// await tester.pumpAndSettle(); +// +// expect(dismissed, isFalse); +// expect(controller!.ratio, 0); +// }); +// }); +// } diff --git a/test/slidable_test.dart b/test/slidable_test.dart index f2a5a477..029f7d9a 100644 --- a/test/slidable_test.dart +++ b/test/slidable_test.dart @@ -1,360 +1,360 @@ -import 'package:flutter/gestures.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_slidable/src/action_pane_motions.dart'; -import 'package:flutter_slidable/src/actions.dart'; -import 'package:flutter_slidable/src/slidable.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group('Slidable', () { - testWidgets( - 'child should be able to open the horitzontal start action pane', - (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const startActionPaneKey = ValueKey('start'); - const endActionPaneKey = ValueKey('end'); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Slidable( - startActionPane: ActionPane( - key: startActionPaneKey, - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - endActionPane: ActionPane( - key: endActionPaneKey, - motion: const ScrollMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: Builder(builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openStartActionPane(); - }, - ); - }), - ), - ), - ); - - expect(find.byKey(startActionPaneKey), findsNothing); - expect(find.byKey(endActionPaneKey), findsNothing); - - await tester.tap(find.byKey(gestureDetectorKey)); - await tester.pumpAndSettle(); - - expect(find.byKey(startActionPaneKey), findsOneWidget); - expect(find.byKey(endActionPaneKey), findsNothing); - }); - - testWidgets('child should be able to open the horizontal end action pane', - (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const startActionPaneKey = ValueKey('start'); - const endActionPaneKey = ValueKey('end'); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Slidable( - startActionPane: ActionPane( - key: startActionPaneKey, - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - endActionPane: ActionPane( - key: endActionPaneKey, - motion: const ScrollMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: Builder(builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openEndActionPane(); - }, - ); - }), - ), - ), - ); - - expect(find.byKey(startActionPaneKey), findsNothing); - expect(find.byKey(endActionPaneKey), findsNothing); - - await tester.tap(find.byKey(gestureDetectorKey)); - await tester.pumpAndSettle(); - - expect(find.byKey(startActionPaneKey), findsNothing); - expect(find.byKey(endActionPaneKey), findsOneWidget); - }); - - testWidgets('child should be able to open the vertical start action pane', - (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const startActionPaneKey = ValueKey('start'); - const endActionPaneKey = ValueKey('end'); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Slidable( - direction: Axis.vertical, - startActionPane: ActionPane( - key: startActionPaneKey, - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - endActionPane: ActionPane( - key: endActionPaneKey, - motion: const ScrollMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: Builder(builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openStartActionPane(); - }, - ); - }), - ), - ), - ); - - expect(find.byKey(startActionPaneKey), findsNothing); - expect(find.byKey(endActionPaneKey), findsNothing); - - await tester.tap(find.byKey(gestureDetectorKey)); - await tester.pumpAndSettle(); - - expect(find.byKey(startActionPaneKey), findsOneWidget); - expect(find.byKey(endActionPaneKey), findsNothing); - }); - - testWidgets('child should be able to open the vertical end action pane', - (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const startActionPaneKey = ValueKey('start'); - const endActionPaneKey = ValueKey('end'); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Slidable( - direction: Axis.vertical, - startActionPane: ActionPane( - key: startActionPaneKey, - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - endActionPane: ActionPane( - key: endActionPaneKey, - motion: const ScrollMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: Builder(builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openEndActionPane(); - }, - ); - }), - ), - ), - ); - - expect(find.byKey(startActionPaneKey), findsNothing); - expect(find.byKey(endActionPaneKey), findsNothing); - - await tester.tap(find.byKey(gestureDetectorKey)); - await tester.pumpAndSettle(); - - expect(find.byKey(startActionPaneKey), findsNothing); - expect(find.byKey(endActionPaneKey), findsOneWidget); - }); - }); - - testWidgets('cannot drag to show startActionPane if null', (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const endActionPaneKey = ValueKey('end'); - const childKey = ValueKey('child'); - final findSlidable = find.byType(Slidable); - const duration = Duration(milliseconds: 300); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Slidable( - endActionPane: ActionPane( - key: endActionPaneKey, - motion: const ScrollMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: Builder( - key: childKey, - builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openEndActionPane(); - }, - ); - }, - ), - ), - ), - ); - - expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); - - await tester.timedDrag(findSlidable, const Offset(50, 0), duration); - - expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); - }); - - testWidgets('cannot drag to show endActionPane if null', (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const startActionPaneKey = ValueKey('start'); - const childKey = ValueKey('child'); - final findSlidable = find.byType(Slidable); - const duration = Duration(milliseconds: 300); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Slidable( - startActionPane: ActionPane( - key: startActionPaneKey, - motion: const ScrollMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ), - child: Builder( - key: childKey, - builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openEndActionPane(); - }, - ); - }, - ), - ), - ), - ); - - expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); - - await tester.timedDrag(findSlidable, const Offset(-50, 0), duration); - - expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); - }); - - testWidgets( - 'should work if TextDirection.rtl and only startActionPane is set', - (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const actionPaneKey = ValueKey('action_pane'); - final actionPane = ActionPane( - key: actionPaneKey, - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ); - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.rtl, - child: Slidable( - startActionPane: actionPane, - child: Builder(builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openStartActionPane(); - }, - ); - }), - ), - ), - ); - - expect(find.byKey(actionPaneKey), findsNothing); - - await tester.tap(find.byKey(gestureDetectorKey)); - await tester.pumpAndSettle(); - - expect(find.byKey(actionPaneKey), findsOneWidget); - }); - - testWidgets('should work if TextDirection.rtl and only endActionPane is set', - (tester) async { - const gestureDetectorKey = ValueKey('gesture_detector'); - const actionPaneKey = ValueKey('action_pane'); - final actionPane = ActionPane( - key: actionPaneKey, - motion: const BehindMotion(), - children: [ - SlidableAction(onPressed: (_) {}, icon: Icons.share), - SlidableAction(onPressed: (_) {}, icon: Icons.delete), - ], - ); - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.rtl, - child: Slidable( - endActionPane: actionPane, - child: Builder(builder: (context) { - return GestureDetector( - key: gestureDetectorKey, - onTap: () { - Slidable.of(context)!.openEndActionPane(); - }, - ); - }), - ), - ), - ); - - expect(find.byKey(actionPaneKey), findsNothing); - - await tester.tap(find.byKey(gestureDetectorKey)); - await tester.pumpAndSettle(); - await tester.pumpAndSettle(); - await tester.pumpAndSettle(); - - expect(find.byKey(actionPaneKey), findsOneWidget); - }); -} +// import 'package:flutter/gestures.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_slidable/src/action_pane_motions.dart'; +// import 'package:flutter_slidable/src/actions.dart'; +// import 'package:flutter_slidable/src/slidable.dart'; +// import 'package:flutter_test/flutter_test.dart'; +// +// void main() { +// group('Slidable', () { +// testWidgets( +// 'child should be able to open the horitzontal start action pane', +// (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const startActionPaneKey = ValueKey('start'); +// const endActionPaneKey = ValueKey('end'); +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Slidable( +// startActionPane: ActionPane( +// key: startActionPaneKey, +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// endActionPane: ActionPane( +// key: endActionPaneKey, +// motion: const ScrollMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: Builder(builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openStartActionPane(); +// }, +// ); +// }), +// ), +// ), +// ); +// +// expect(find.byKey(startActionPaneKey), findsNothing); +// expect(find.byKey(endActionPaneKey), findsNothing); +// +// await tester.tap(find.byKey(gestureDetectorKey)); +// await tester.pumpAndSettle(); +// +// expect(find.byKey(startActionPaneKey), findsOneWidget); +// expect(find.byKey(endActionPaneKey), findsNothing); +// }); +// +// testWidgets('child should be able to open the horizontal end action pane', +// (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const startActionPaneKey = ValueKey('start'); +// const endActionPaneKey = ValueKey('end'); +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Slidable( +// startActionPane: ActionPane( +// key: startActionPaneKey, +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// endActionPane: ActionPane( +// key: endActionPaneKey, +// motion: const ScrollMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: Builder(builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openEndActionPane(); +// }, +// ); +// }), +// ), +// ), +// ); +// +// expect(find.byKey(startActionPaneKey), findsNothing); +// expect(find.byKey(endActionPaneKey), findsNothing); +// +// await tester.tap(find.byKey(gestureDetectorKey)); +// await tester.pumpAndSettle(); +// +// expect(find.byKey(startActionPaneKey), findsNothing); +// expect(find.byKey(endActionPaneKey), findsOneWidget); +// }); +// +// testWidgets('child should be able to open the vertical start action pane', +// (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const startActionPaneKey = ValueKey('start'); +// const endActionPaneKey = ValueKey('end'); +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Slidable( +// direction: Axis.vertical, +// startActionPane: ActionPane( +// key: startActionPaneKey, +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// endActionPane: ActionPane( +// key: endActionPaneKey, +// motion: const ScrollMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: Builder(builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openStartActionPane(); +// }, +// ); +// }), +// ), +// ), +// ); +// +// expect(find.byKey(startActionPaneKey), findsNothing); +// expect(find.byKey(endActionPaneKey), findsNothing); +// +// await tester.tap(find.byKey(gestureDetectorKey)); +// await tester.pumpAndSettle(); +// +// expect(find.byKey(startActionPaneKey), findsOneWidget); +// expect(find.byKey(endActionPaneKey), findsNothing); +// }); +// +// testWidgets('child should be able to open the vertical end action pane', +// (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const startActionPaneKey = ValueKey('start'); +// const endActionPaneKey = ValueKey('end'); +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Slidable( +// direction: Axis.vertical, +// startActionPane: ActionPane( +// key: startActionPaneKey, +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// endActionPane: ActionPane( +// key: endActionPaneKey, +// motion: const ScrollMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: Builder(builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openEndActionPane(); +// }, +// ); +// }), +// ), +// ), +// ); +// +// expect(find.byKey(startActionPaneKey), findsNothing); +// expect(find.byKey(endActionPaneKey), findsNothing); +// +// await tester.tap(find.byKey(gestureDetectorKey)); +// await tester.pumpAndSettle(); +// +// expect(find.byKey(startActionPaneKey), findsNothing); +// expect(find.byKey(endActionPaneKey), findsOneWidget); +// }); +// }); +// +// testWidgets('cannot drag to show startActionPane if null', (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const endActionPaneKey = ValueKey('end'); +// const childKey = ValueKey('child'); +// final findSlidable = find.byType(Slidable); +// const duration = Duration(milliseconds: 300); +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Slidable( +// endActionPane: ActionPane( +// key: endActionPaneKey, +// motion: const ScrollMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: Builder( +// key: childKey, +// builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openEndActionPane(); +// }, +// ); +// }, +// ), +// ), +// ), +// ); +// +// expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); +// +// await tester.timedDrag(findSlidable, const Offset(50, 0), duration); +// +// expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); +// }); +// +// testWidgets('cannot drag to show endActionPane if null', (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const startActionPaneKey = ValueKey('start'); +// const childKey = ValueKey('child'); +// final findSlidable = find.byType(Slidable); +// const duration = Duration(milliseconds: 300); +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.ltr, +// child: Slidable( +// startActionPane: ActionPane( +// key: startActionPaneKey, +// motion: const ScrollMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ), +// child: Builder( +// key: childKey, +// builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openEndActionPane(); +// }, +// ); +// }, +// ), +// ), +// ), +// ); +// +// expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); +// +// await tester.timedDrag(findSlidable, const Offset(-50, 0), duration); +// +// expect(tester.getTopLeft(find.byKey(childKey)), const Offset(0, 0)); +// }); +// +// testWidgets( +// 'should work if TextDirection.rtl and only startActionPane is set', +// (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const actionPaneKey = ValueKey('action_pane'); +// final actionPane = ActionPane( +// key: actionPaneKey, +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ); +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.rtl, +// child: Slidable( +// startActionPane: actionPane, +// child: Builder(builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openStartActionPane(); +// }, +// ); +// }), +// ), +// ), +// ); +// +// expect(find.byKey(actionPaneKey), findsNothing); +// +// await tester.tap(find.byKey(gestureDetectorKey)); +// await tester.pumpAndSettle(); +// +// expect(find.byKey(actionPaneKey), findsOneWidget); +// }); +// +// testWidgets('should work if TextDirection.rtl and only endActionPane is set', +// (tester) async { +// const gestureDetectorKey = ValueKey('gesture_detector'); +// const actionPaneKey = ValueKey('action_pane'); +// final actionPane = ActionPane( +// key: actionPaneKey, +// motion: const BehindMotion(), +// children: [ +// SlidableAction(onPressed: (_) {}, icon: Icons.share), +// SlidableAction(onPressed: (_) {}, icon: Icons.delete), +// ], +// ); +// +// await tester.pumpWidget( +// Directionality( +// textDirection: TextDirection.rtl, +// child: Slidable( +// endActionPane: actionPane, +// child: Builder(builder: (context) { +// return GestureDetector( +// key: gestureDetectorKey, +// onTap: () { +// Slidable.of(context)!.openEndActionPane(); +// }, +// ); +// }), +// ), +// ), +// ); +// +// expect(find.byKey(actionPaneKey), findsNothing); +// +// await tester.tap(find.byKey(gestureDetectorKey)); +// await tester.pumpAndSettle(); +// await tester.pumpAndSettle(); +// await tester.pumpAndSettle(); +// +// expect(find.byKey(actionPaneKey), findsOneWidget); +// }); +// }