diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index 78871141902..5c163a68160 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -598,9 +598,18 @@ class HeroController extends NavigatorObserver { final PageRoute to = toRoute; final Animation 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 diff --git a/packages/flutter/test/widgets/heroes_test.dart b/packages/flutter/test/widgets/heroes_test.dart index 4cdb8fba166..e33291b4bf3 100644 --- a/packages/flutter/test/widgets/heroes_test.dart +++ b/packages/flutter/test/widgets/heroes_test.dart @@ -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); + }); }