Skip to content

Commit 329d54b

Browse files
Reduce reliance on Material in page_transitions_test.dart (#181467)
This PR reduces the reliance on Material in page_transitions_test.dart but does not entirely remove it. 1) Moves a test for persistent bottom sheet to the right file 2) Fixes a use of `sync*` (not sure why this is not caught by dev/bots/analyze.dart, that _does_ check for `sync*` cc @Piinks ) 3) Replaces some easy usages of Material widgets with its widget counterparts. The only thing that I did not yet fix is replacing `MaterialApp` in this file. That probably needs @victorsanni 's work on page transitions to be addressed first? Part of #177415 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent c58b729 commit 329d54b

2 files changed

Lines changed: 106 additions & 103 deletions

File tree

packages/flutter/test/material/persistent_bottom_sheet_test.dart

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,4 +689,96 @@ void main() {
689689
await tester.pump();
690690
expect(find.byType(BottomSheet), findsNothing);
691691
});
692+
693+
// Regression test for https://github.com/flutter/flutter/issues/6451
694+
testWidgets(
695+
'Check back gesture with a persistent bottom sheet showing',
696+
(WidgetTester tester) async {
697+
final GlobalKey<ScaffoldState> containerKey1 = GlobalKey();
698+
final GlobalKey<PersistentBottomSheetTestState> containerKey2 = GlobalKey();
699+
final routes = <String, WidgetBuilder>{
700+
'/': (_) => Scaffold(key: containerKey1, body: const Text('Home')),
701+
'/sheet': (_) => PersistentBottomSheetTest(key: containerKey2),
702+
};
703+
704+
await tester.pumpWidget(MaterialApp(routes: routes));
705+
706+
Navigator.pushNamed(containerKey1.currentContext!, '/sheet');
707+
708+
await tester.pump();
709+
await tester.pump(const Duration(seconds: 1));
710+
711+
expect(find.text('Home'), findsNothing);
712+
expect(find.text('Sheet'), isOnstage);
713+
714+
// Drag from left edge to invoke the gesture. We should go back.
715+
TestGesture gesture = await tester.startGesture(const Offset(5.0, 100.0));
716+
await gesture.moveBy(const Offset(500.0, 0.0));
717+
await gesture.up();
718+
await tester.pump();
719+
await tester.pump(const Duration(seconds: 1));
720+
721+
Navigator.pushNamed(containerKey1.currentContext!, '/sheet');
722+
723+
await tester.pump();
724+
await tester.pump(const Duration(seconds: 1));
725+
726+
expect(find.text('Home'), findsNothing);
727+
expect(find.text('Sheet'), isOnstage);
728+
729+
// Show the bottom sheet.
730+
final PersistentBottomSheetTestState sheet = containerKey2.currentState!;
731+
sheet.showBottomSheet();
732+
733+
await tester.pump(const Duration(seconds: 1));
734+
735+
// Drag from left edge to invoke the gesture. Nothing should happen.
736+
gesture = await tester.startGesture(const Offset(5.0, 100.0));
737+
await gesture.moveBy(const Offset(500.0, 0.0));
738+
await gesture.up();
739+
await tester.pump();
740+
await tester.pump(const Duration(seconds: 1));
741+
742+
expect(find.text('Home'), findsNothing);
743+
expect(find.text('Sheet'), isOnstage);
744+
745+
// Sheet did not call setState (since the gesture did nothing).
746+
expect(sheet.setStateCalled, isFalse);
747+
},
748+
variant: const TargetPlatformVariant(<TargetPlatform>{
749+
TargetPlatform.iOS,
750+
TargetPlatform.macOS,
751+
}),
752+
);
753+
}
754+
755+
class PersistentBottomSheetTest extends StatefulWidget {
756+
const PersistentBottomSheetTest({super.key});
757+
758+
@override
759+
PersistentBottomSheetTestState createState() => PersistentBottomSheetTestState();
760+
}
761+
762+
class PersistentBottomSheetTestState extends State<PersistentBottomSheetTest> {
763+
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
764+
765+
bool setStateCalled = false;
766+
767+
void showBottomSheet() {
768+
_scaffoldKey.currentState!
769+
.showBottomSheet((BuildContext context) {
770+
return const Text('bottomSheet');
771+
})
772+
.closed
773+
.whenComplete(() {
774+
setState(() {
775+
setStateCalled = true;
776+
});
777+
});
778+
}
779+
780+
@override
781+
Widget build(BuildContext context) {
782+
return Scaffold(key: _scaffoldKey, body: const Text('Sheet'));
783+
}
692784
}

packages/flutter/test/widgets/page_transitions_test.dart

Lines changed: 14 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,11 @@ import 'package:flutter_test/flutter_test.dart';
88
class TestOverlayRoute extends OverlayRoute<void> {
99
TestOverlayRoute({super.settings});
1010
@override
11-
Iterable<OverlayEntry> createOverlayEntries() sync* {
12-
yield OverlayEntry(builder: _build);
13-
}
11+
Iterable<OverlayEntry> createOverlayEntries() => [OverlayEntry(builder: _build)];
1412

1513
Widget _build(BuildContext context) => const Text('Overlay');
1614
}
1715

18-
class PersistentBottomSheetTest extends StatefulWidget {
19-
const PersistentBottomSheetTest({super.key});
20-
21-
@override
22-
PersistentBottomSheetTestState createState() => PersistentBottomSheetTestState();
23-
}
24-
25-
class PersistentBottomSheetTestState extends State<PersistentBottomSheetTest> {
26-
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
27-
28-
bool setStateCalled = false;
29-
30-
void showBottomSheet() {
31-
_scaffoldKey.currentState!
32-
.showBottomSheet((BuildContext context) {
33-
return const Text('bottomSheet');
34-
})
35-
.closed
36-
.whenComplete(() {
37-
setState(() {
38-
setStateCalled = true;
39-
});
40-
});
41-
}
42-
43-
@override
44-
Widget build(BuildContext context) {
45-
return Scaffold(key: _scaffoldKey, body: const Text('Sheet'));
46-
}
47-
}
48-
4916
void main() {
5017
testWidgets('Check onstage/offstage handling around transitions', (WidgetTester tester) async {
5118
final GlobalKey containerKey1 = GlobalKey();
@@ -136,16 +103,16 @@ void main() {
136103
final GlobalKey containerKey2 = GlobalKey();
137104
const kHeroTag = 'hero';
138105
final routes = <String, WidgetBuilder>{
139-
'/': (_) => Scaffold(
106+
'/': (_) => SizedBox(
140107
key: containerKey1,
141-
body: const ColoredBox(
108+
child: const ColoredBox(
142109
color: Color(0xff00ffff),
143110
child: Hero(tag: kHeroTag, child: Text('Home')),
144111
),
145112
),
146-
'/settings': (_) => Scaffold(
113+
'/settings': (_) => SizedBox(
147114
key: containerKey2,
148-
body: Container(
115+
child: Container(
149116
padding: const EdgeInsets.all(100.0),
150117
color: const Color(0xffff00ff),
151118
child: const Hero(tag: kHeroTag, child: Text('Settings')),
@@ -205,8 +172,8 @@ void main() {
205172
final GlobalKey containerKey1 = GlobalKey();
206173
final GlobalKey containerKey2 = GlobalKey();
207174
final routes = <String, WidgetBuilder>{
208-
'/': (_) => Scaffold(key: containerKey1, body: const Text('Home')),
209-
'/settings': (_) => Scaffold(key: containerKey2, body: const Text('Settings')),
175+
'/': (_) => SizedBox(key: containerKey1, child: const Text('Home')),
176+
'/settings': (_) => SizedBox(key: containerKey2, child: const Text('Settings')),
210177
};
211178

212179
await tester.pumpWidget(MaterialApp(routes: routes));
@@ -249,67 +216,6 @@ void main() {
249216
}),
250217
);
251218

252-
// Tests bug https://github.com/flutter/flutter/issues/6451
253-
testWidgets(
254-
'Check back gesture with a persistent bottom sheet showing',
255-
(WidgetTester tester) async {
256-
final GlobalKey containerKey1 = GlobalKey();
257-
final GlobalKey containerKey2 = GlobalKey();
258-
final routes = <String, WidgetBuilder>{
259-
'/': (_) => Scaffold(key: containerKey1, body: const Text('Home')),
260-
'/sheet': (_) => PersistentBottomSheetTest(key: containerKey2),
261-
};
262-
263-
await tester.pumpWidget(MaterialApp(routes: routes));
264-
265-
Navigator.pushNamed(containerKey1.currentContext!, '/sheet');
266-
267-
await tester.pump();
268-
await tester.pump(const Duration(seconds: 1));
269-
270-
expect(find.text('Home'), findsNothing);
271-
expect(find.text('Sheet'), isOnstage);
272-
273-
// Drag from left edge to invoke the gesture. We should go back.
274-
TestGesture gesture = await tester.startGesture(const Offset(5.0, 100.0));
275-
await gesture.moveBy(const Offset(500.0, 0.0));
276-
await gesture.up();
277-
await tester.pump();
278-
await tester.pump(const Duration(seconds: 1));
279-
280-
Navigator.pushNamed(containerKey1.currentContext!, '/sheet');
281-
282-
await tester.pump();
283-
await tester.pump(const Duration(seconds: 1));
284-
285-
expect(find.text('Home'), findsNothing);
286-
expect(find.text('Sheet'), isOnstage);
287-
288-
// Show the bottom sheet.
289-
final sheet = containerKey2.currentState! as PersistentBottomSheetTestState;
290-
sheet.showBottomSheet();
291-
292-
await tester.pump(const Duration(seconds: 1));
293-
294-
// Drag from left edge to invoke the gesture. Nothing should happen.
295-
gesture = await tester.startGesture(const Offset(5.0, 100.0));
296-
await gesture.moveBy(const Offset(500.0, 0.0));
297-
await gesture.up();
298-
await tester.pump();
299-
await tester.pump(const Duration(seconds: 1));
300-
301-
expect(find.text('Home'), findsNothing);
302-
expect(find.text('Sheet'), isOnstage);
303-
304-
// Sheet did not call setState (since the gesture did nothing).
305-
expect(sheet.setStateCalled, isFalse);
306-
},
307-
variant: const TargetPlatformVariant(<TargetPlatform>{
308-
TargetPlatform.iOS,
309-
TargetPlatform.macOS,
310-
}),
311-
);
312-
313219
testWidgets('Test completed future', (WidgetTester tester) async {
314220
final routes = <String, WidgetBuilder>{
315221
'/': (_) => const Center(child: Text('home')),
@@ -318,9 +224,14 @@ void main() {
318224

319225
await tester.pumpWidget(MaterialApp(routes: routes));
320226

321-
final PageRoute<void> route = MaterialPageRoute<void>(
227+
final PageRoute<void> route = PageRouteBuilder<void>(
322228
settings: const RouteSettings(name: '/page'),
323-
builder: (BuildContext context) => const Center(child: Text('page')),
229+
pageBuilder:
230+
(
231+
BuildContext context,
232+
Animation<double> animation,
233+
Animation<double> secondaryAnimation,
234+
) => const Center(child: Text('page')),
324235
);
325236

326237
var popCount = 0;

0 commit comments

Comments
 (0)