mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix heroes transition when initial route is not '/' (#24039)
* early return for initialRoute + test
This commit is contained in:
parent
028087d0fc
commit
220cceedb5
@ -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
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user