diff --git a/packages/flutter/test/material/persistent_bottom_sheet_test.dart b/packages/flutter/test/material/persistent_bottom_sheet_test.dart index 58e13f6e9a7..4b1d3b7740e 100644 --- a/packages/flutter/test/material/persistent_bottom_sheet_test.dart +++ b/packages/flutter/test/material/persistent_bottom_sheet_test.dart @@ -689,4 +689,96 @@ void main() { await tester.pump(); expect(find.byType(BottomSheet), findsNothing); }); + + // Regression test for https://github.com/flutter/flutter/issues/6451 + testWidgets( + 'Check back gesture with a persistent bottom sheet showing', + (WidgetTester tester) async { + final GlobalKey containerKey1 = GlobalKey(); + final GlobalKey containerKey2 = GlobalKey(); + final routes = { + '/': (_) => Scaffold(key: containerKey1, body: const Text('Home')), + '/sheet': (_) => PersistentBottomSheetTest(key: containerKey2), + }; + + await tester.pumpWidget(MaterialApp(routes: routes)); + + Navigator.pushNamed(containerKey1.currentContext!, '/sheet'); + + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + + expect(find.text('Home'), findsNothing); + expect(find.text('Sheet'), isOnstage); + + // Drag from left edge to invoke the gesture. We should go back. + TestGesture gesture = await tester.startGesture(const Offset(5.0, 100.0)); + await gesture.moveBy(const Offset(500.0, 0.0)); + await gesture.up(); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + + Navigator.pushNamed(containerKey1.currentContext!, '/sheet'); + + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + + expect(find.text('Home'), findsNothing); + expect(find.text('Sheet'), isOnstage); + + // Show the bottom sheet. + final PersistentBottomSheetTestState sheet = containerKey2.currentState!; + sheet.showBottomSheet(); + + await tester.pump(const Duration(seconds: 1)); + + // Drag from left edge to invoke the gesture. Nothing should happen. + gesture = await tester.startGesture(const Offset(5.0, 100.0)); + await gesture.moveBy(const Offset(500.0, 0.0)); + await gesture.up(); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + + expect(find.text('Home'), findsNothing); + expect(find.text('Sheet'), isOnstage); + + // Sheet did not call setState (since the gesture did nothing). + expect(sheet.setStateCalled, isFalse); + }, + variant: const TargetPlatformVariant({ + TargetPlatform.iOS, + TargetPlatform.macOS, + }), + ); +} + +class PersistentBottomSheetTest extends StatefulWidget { + const PersistentBottomSheetTest({super.key}); + + @override + PersistentBottomSheetTestState createState() => PersistentBottomSheetTestState(); +} + +class PersistentBottomSheetTestState extends State { + final GlobalKey _scaffoldKey = GlobalKey(); + + bool setStateCalled = false; + + void showBottomSheet() { + _scaffoldKey.currentState! + .showBottomSheet((BuildContext context) { + return const Text('bottomSheet'); + }) + .closed + .whenComplete(() { + setState(() { + setStateCalled = true; + }); + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold(key: _scaffoldKey, body: const Text('Sheet')); + } } diff --git a/packages/flutter/test/widgets/page_transitions_test.dart b/packages/flutter/test/widgets/page_transitions_test.dart index 8118ec61bb2..f4010af1d9c 100644 --- a/packages/flutter/test/widgets/page_transitions_test.dart +++ b/packages/flutter/test/widgets/page_transitions_test.dart @@ -8,44 +8,11 @@ import 'package:flutter_test/flutter_test.dart'; class TestOverlayRoute extends OverlayRoute { TestOverlayRoute({super.settings}); @override - Iterable createOverlayEntries() sync* { - yield OverlayEntry(builder: _build); - } + Iterable createOverlayEntries() => [OverlayEntry(builder: _build)]; Widget _build(BuildContext context) => const Text('Overlay'); } -class PersistentBottomSheetTest extends StatefulWidget { - const PersistentBottomSheetTest({super.key}); - - @override - PersistentBottomSheetTestState createState() => PersistentBottomSheetTestState(); -} - -class PersistentBottomSheetTestState extends State { - final GlobalKey _scaffoldKey = GlobalKey(); - - bool setStateCalled = false; - - void showBottomSheet() { - _scaffoldKey.currentState! - .showBottomSheet((BuildContext context) { - return const Text('bottomSheet'); - }) - .closed - .whenComplete(() { - setState(() { - setStateCalled = true; - }); - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold(key: _scaffoldKey, body: const Text('Sheet')); - } -} - void main() { testWidgets('Check onstage/offstage handling around transitions', (WidgetTester tester) async { final GlobalKey containerKey1 = GlobalKey(); @@ -136,16 +103,16 @@ void main() { final GlobalKey containerKey2 = GlobalKey(); const kHeroTag = 'hero'; final routes = { - '/': (_) => Scaffold( + '/': (_) => SizedBox( key: containerKey1, - body: const ColoredBox( + child: const ColoredBox( color: Color(0xff00ffff), child: Hero(tag: kHeroTag, child: Text('Home')), ), ), - '/settings': (_) => Scaffold( + '/settings': (_) => SizedBox( key: containerKey2, - body: Container( + child: Container( padding: const EdgeInsets.all(100.0), color: const Color(0xffff00ff), child: const Hero(tag: kHeroTag, child: Text('Settings')), @@ -205,8 +172,8 @@ void main() { final GlobalKey containerKey1 = GlobalKey(); final GlobalKey containerKey2 = GlobalKey(); final routes = { - '/': (_) => Scaffold(key: containerKey1, body: const Text('Home')), - '/settings': (_) => Scaffold(key: containerKey2, body: const Text('Settings')), + '/': (_) => SizedBox(key: containerKey1, child: const Text('Home')), + '/settings': (_) => SizedBox(key: containerKey2, child: const Text('Settings')), }; await tester.pumpWidget(MaterialApp(routes: routes)); @@ -249,67 +216,6 @@ void main() { }), ); - // Tests bug https://github.com/flutter/flutter/issues/6451 - testWidgets( - 'Check back gesture with a persistent bottom sheet showing', - (WidgetTester tester) async { - final GlobalKey containerKey1 = GlobalKey(); - final GlobalKey containerKey2 = GlobalKey(); - final routes = { - '/': (_) => Scaffold(key: containerKey1, body: const Text('Home')), - '/sheet': (_) => PersistentBottomSheetTest(key: containerKey2), - }; - - await tester.pumpWidget(MaterialApp(routes: routes)); - - Navigator.pushNamed(containerKey1.currentContext!, '/sheet'); - - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - - expect(find.text('Home'), findsNothing); - expect(find.text('Sheet'), isOnstage); - - // Drag from left edge to invoke the gesture. We should go back. - TestGesture gesture = await tester.startGesture(const Offset(5.0, 100.0)); - await gesture.moveBy(const Offset(500.0, 0.0)); - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - - Navigator.pushNamed(containerKey1.currentContext!, '/sheet'); - - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - - expect(find.text('Home'), findsNothing); - expect(find.text('Sheet'), isOnstage); - - // Show the bottom sheet. - final sheet = containerKey2.currentState! as PersistentBottomSheetTestState; - sheet.showBottomSheet(); - - await tester.pump(const Duration(seconds: 1)); - - // Drag from left edge to invoke the gesture. Nothing should happen. - gesture = await tester.startGesture(const Offset(5.0, 100.0)); - await gesture.moveBy(const Offset(500.0, 0.0)); - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - - expect(find.text('Home'), findsNothing); - expect(find.text('Sheet'), isOnstage); - - // Sheet did not call setState (since the gesture did nothing). - expect(sheet.setStateCalled, isFalse); - }, - variant: const TargetPlatformVariant({ - TargetPlatform.iOS, - TargetPlatform.macOS, - }), - ); - testWidgets('Test completed future', (WidgetTester tester) async { final routes = { '/': (_) => const Center(child: Text('home')), @@ -318,9 +224,14 @@ void main() { await tester.pumpWidget(MaterialApp(routes: routes)); - final PageRoute route = MaterialPageRoute( + final PageRoute route = PageRouteBuilder( settings: const RouteSettings(name: '/page'), - builder: (BuildContext context) => const Center(child: Text('page')), + pageBuilder: + ( + BuildContext context, + Animation animation, + Animation secondaryAnimation, + ) => const Center(child: Text('page')), ); var popCount = 0;