Fix heroes transition when initial route is not '/' (#24039)

* early return for initialRoute + test
This commit is contained in:
Dan Field 2018-11-07 00:06:34 -08:00 committed by GitHub
parent 028087d0fc
commit 220cceedb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -598,9 +598,18 @@ class HeroController extends NavigatorObserver {
final PageRoute<dynamic> to = toRoute;
final Animation<double> animation = (flightType == HeroFlightDirection.push) ? to.animation : from.animation;
// A user gesture may have already completed the pop.
if (flightType == HeroFlightDirection.pop && animation.status == AnimationStatus.dismissed) {
return;
// A user gesture may have already completed the pop, or we might be the initial route
switch (flightType) {
case HeroFlightDirection.pop:
if (animation.value == 0.0) {
return;
}
break;
case HeroFlightDirection.push:
if (animation.value == 1.0) {
return;
}
break;
}
// For pop transitions driven by a user gesture: if the "to" page has

View File

@ -1437,4 +1437,12 @@ void main() {
expect(find.byKey(firstKey), isInCard);
expect(find.byKey(secondKey), findsNothing);
});
testWidgets('Handles transitions when a non-default initial route is set', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
routes: routes,
initialRoute: '/two',
));
expect(find.text('two'), findsOneWidget);
});
}