Hides added routes before top-most route finishes pushing (#156104)
fixes https://github.com/flutter/flutter/issues/156033
This commit is contained in:
@@ -225,7 +225,9 @@ abstract class Route<T> extends _RoutePlaceholder {
|
||||
void _updateSettings(RouteSettings newSettings) {
|
||||
if (_settings != newSettings) {
|
||||
_settings = newSettings;
|
||||
changedInternalState();
|
||||
if (_navigator != null) {
|
||||
changedInternalState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3101,10 +3103,6 @@ class _RouteEntry extends RouteTransitionRecord {
|
||||
void handleAdd({ required NavigatorState navigator, required Route<dynamic>? previousPresent }) {
|
||||
assert(currentState == _RouteLifecycle.add);
|
||||
assert(navigator._debugLocked);
|
||||
assert(route._navigator == null);
|
||||
route._navigator = navigator;
|
||||
route.install();
|
||||
assert(route.overlayEntries.isNotEmpty);
|
||||
currentState = _RouteLifecycle.adding;
|
||||
navigator._observedRouteAdditions.add(
|
||||
_NavigatorPushObservation(route, previousPresent),
|
||||
@@ -3229,6 +3227,10 @@ class _RouteEntry extends RouteTransitionRecord {
|
||||
}
|
||||
|
||||
void didAdd({ required NavigatorState navigator, required bool isNewFirst}) {
|
||||
assert(route._navigator == null);
|
||||
route._navigator = navigator;
|
||||
route.install();
|
||||
assert(route.overlayEntries.isNotEmpty);
|
||||
route.didAdd();
|
||||
currentState = _RouteLifecycle.idle;
|
||||
if (isNewFirst) {
|
||||
@@ -3825,7 +3827,9 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
|
||||
super.didChangeDependencies();
|
||||
_updateHeroController(HeroControllerScope.maybeOf(context));
|
||||
for (final _RouteEntry entry in _history) {
|
||||
entry.route.changedExternalState();
|
||||
if (entry.route.navigator == this) {
|
||||
entry.route.changedExternalState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3945,7 +3949,9 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
|
||||
}
|
||||
|
||||
for (final _RouteEntry entry in _history) {
|
||||
entry.route.changedExternalState();
|
||||
if (entry.route.navigator == this) {
|
||||
entry.route.changedExternalState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3133,8 +3133,8 @@ void main() {
|
||||
testWidgets('can push and pop pages using page api', (WidgetTester tester) async {
|
||||
late Animation<double> secondaryAnimationOfRouteOne;
|
||||
late Animation<double> primaryAnimationOfRouteOne;
|
||||
late Animation<double> secondaryAnimationOfRouteTwo;
|
||||
late Animation<double> primaryAnimationOfRouteTwo;
|
||||
Animation<double>? secondaryAnimationOfRouteTwo;
|
||||
Animation<double>? primaryAnimationOfRouteTwo;
|
||||
late Animation<double> secondaryAnimationOfRouteThree;
|
||||
late Animation<double> primaryAnimationOfRouteThree;
|
||||
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
|
||||
@@ -3208,24 +3208,24 @@ void main() {
|
||||
// won't start until the third page finishes transition.
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteOne.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo.status, AnimationStatus.dismissed);
|
||||
expect(primaryAnimationOfRouteTwo.status, AnimationStatus.dismissed);
|
||||
expect(secondaryAnimationOfRouteTwo, isNull);
|
||||
expect(primaryAnimationOfRouteTwo, isNull);
|
||||
expect(secondaryAnimationOfRouteThree.status, AnimationStatus.dismissed);
|
||||
expect(primaryAnimationOfRouteThree.status, AnimationStatus.forward);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 30));
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteOne.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo.status, AnimationStatus.dismissed);
|
||||
expect(primaryAnimationOfRouteTwo.status, AnimationStatus.dismissed);
|
||||
expect(secondaryAnimationOfRouteTwo, isNull);
|
||||
expect(primaryAnimationOfRouteTwo, isNull);
|
||||
expect(secondaryAnimationOfRouteThree.status, AnimationStatus.dismissed);
|
||||
expect(primaryAnimationOfRouteThree.value, 0.1);
|
||||
await tester.pumpAndSettle();
|
||||
// After transition finishes, the routes' animations are correctly chained.
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo.value);
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo!.value);
|
||||
expect(primaryAnimationOfRouteOne.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteTwo.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo!.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteTwo!.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteThree.status, AnimationStatus.dismissed);
|
||||
expect(primaryAnimationOfRouteThree.status, AnimationStatus.completed);
|
||||
expect(find.text('third'), findsOneWidget);
|
||||
@@ -3264,17 +3264,17 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 30));
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo.value);
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo!.value);
|
||||
expect(primaryAnimationOfRouteOne.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteTwo.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo!.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteTwo!.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteThree.status, AnimationStatus.dismissed);
|
||||
expect(primaryAnimationOfRouteThree.value, 0.9);
|
||||
await tester.pumpAndSettle();
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo.value);
|
||||
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo!.value);
|
||||
expect(primaryAnimationOfRouteOne.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteTwo.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteTwo!.value, primaryAnimationOfRouteThree.value);
|
||||
expect(primaryAnimationOfRouteTwo!.status, AnimationStatus.completed);
|
||||
expect(secondaryAnimationOfRouteThree.status, AnimationStatus.dismissed);
|
||||
expect(primaryAnimationOfRouteThree.status, AnimationStatus.dismissed);
|
||||
});
|
||||
@@ -3415,6 +3415,66 @@ void main() {
|
||||
expect(find.text('page1'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Adds multiple pages won't suddenly jump before top most page finishes pushing", (WidgetTester tester) async {
|
||||
// Regression Test for https://github.com/flutter/flutter/issues/156033.
|
||||
List<Page<Object?>> pages = <Page<Object?>>[
|
||||
MaterialPage<void>(
|
||||
key: UniqueKey(),
|
||||
child: const Text('home'),
|
||||
),
|
||||
];
|
||||
final GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>();
|
||||
Widget buildNavigator() {
|
||||
return TestDependencies(
|
||||
child: Navigator(
|
||||
key: key,
|
||||
pages: pages,
|
||||
onDidRemovePage: (Page<void> page) {},
|
||||
),
|
||||
);
|
||||
}
|
||||
await tester.pumpWidget(buildNavigator());
|
||||
expect(find.text('home'), findsOneWidget);
|
||||
|
||||
pages = <Page<Object?>>[
|
||||
...pages,
|
||||
MaterialPage<void>(
|
||||
key: UniqueKey(),
|
||||
child: const Text('child1'),
|
||||
),
|
||||
MaterialPage<void>(
|
||||
key: UniqueKey(),
|
||||
child: const Text('child2'),
|
||||
),
|
||||
];
|
||||
|
||||
await tester.pumpWidget(buildNavigator());
|
||||
expect(find.text('home'), findsOneWidget);
|
||||
// child 1 should not be created yet because the top-most route is
|
||||
// still in transition.
|
||||
expect(find.text('child1'), findsNothing);
|
||||
expect(find.text('child2'), findsOneWidget);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 150));
|
||||
expect(find.text('home'), findsOneWidget);
|
||||
expect(find.text('child1'), findsNothing);
|
||||
expect(find.text('child2'), findsOneWidget);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Ensure child1 is indeed in the navigator.
|
||||
key.currentState!.pop();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('home'), findsNothing);
|
||||
expect(find.text('child1'), findsOneWidget);
|
||||
expect(find.text('child2'), findsNothing);
|
||||
|
||||
key.currentState!.pop();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('home'), findsOneWidget);
|
||||
expect(find.text('child1'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('can work with pageless route', (WidgetTester tester) async {
|
||||
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
|
||||
List<TestPage> myPages = <TestPage>[
|
||||
|
||||
Reference in New Issue
Block a user