Unverified Commit 600a3a74 authored by Jussi Lahdenniemi's avatar Jussi Lahdenniemi Committed by GitHub

Fix to DrawerController: Call the callback when drawer opened/closed with a fling. (#52593)

parent 778c2ce9
......@@ -436,9 +436,13 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
switch (Directionality.of(context)) {
case TextDirection.rtl:
_controller.fling(velocity: -visualVelocity);
if (widget.drawerCallback != null)
widget.drawerCallback(visualVelocity < 0.0);
break;
case TextDirection.ltr:
_controller.fling(velocity: visualVelocity);
if (widget.drawerCallback != null)
widget.drawerCallback(visualVelocity > 0.0);
break;
}
} else if (_controller.value < 0.5) {
......
......@@ -166,4 +166,53 @@ void main() {
await tester.pumpAndSettle();
expect(find.byType(Drawer), findsNothing);
});
testWidgets('Open/close drawers by flinging', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
drawer: Drawer(
child: Container(
child: const Text('start drawer'),
),
),
endDrawer: Drawer(
child: Container(
child: const Text('end drawer'),
),
),
),
),
);
// In the beginning, drawers are closed
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
expect(state.isDrawerOpen, equals(false));
expect(state.isEndDrawerOpen, equals(false));
final Size size = tester.getSize(find.byType(Scaffold));
// A fling from the left opens the start drawer
await tester.flingFrom(Offset(0, size.height / 2), const Offset(80, 0), 500);
await tester.pumpAndSettle();
expect(state.isDrawerOpen, equals(true));
expect(state.isEndDrawerOpen, equals(false));
// Now, a fling from the right closes the drawer
await tester.flingFrom(Offset(size.width - 1, size.height / 2), const Offset(-80, 0), 500);
await tester.pumpAndSettle();
expect(state.isDrawerOpen, equals(false));
expect(state.isEndDrawerOpen, equals(false));
// Another fling from the right opens the end drawer
await tester.flingFrom(Offset(size.width - 1, size.height / 2), const Offset(-80, 0), 500);
await tester.pumpAndSettle();
expect(state.isDrawerOpen, equals(false));
expect(state.isEndDrawerOpen, equals(true));
// And a fling from the left closes it
await tester.flingFrom( Offset(0, size.height / 2), const Offset(80, 0), 500);
await tester.pumpAndSettle();
expect(state.isDrawerOpen, equals(false));
expect(state.isEndDrawerOpen, equals(false));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment