forked from firka/flutter
Restore offstage and ticker mode after hero pop and the from hero is null (#40306)
This commit is contained in:
@@ -359,7 +359,8 @@ class _HeroState extends State<Hero> {
|
||||
}
|
||||
|
||||
// When `keepPlaceholder` is true, the placeholder will continue to be shown
|
||||
// after the flight ends.
|
||||
// after the flight ends. Otherwise the child of the Hero will become visible
|
||||
// and its TickerMode will be re-enabled.
|
||||
void endFlight({ bool keepPlaceholder = false }) {
|
||||
if (!keepPlaceholder) {
|
||||
ensurePlaceholderIsHidden();
|
||||
@@ -833,6 +834,13 @@ class HeroController extends NavigatorObserver {
|
||||
_flights[tag].abort();
|
||||
}
|
||||
}
|
||||
|
||||
// If the from hero is gone, the flight won't start and the to hero needs to
|
||||
// be put on stage again.
|
||||
for (Object tag in toHeroes.keys) {
|
||||
if (fromHeroes[tag] == null)
|
||||
toHeroes[tag].ensurePlaceholderIsHidden();
|
||||
}
|
||||
}
|
||||
|
||||
void _handleFlightEnded(_HeroFlight flight) {
|
||||
|
||||
@@ -2256,6 +2256,56 @@ Future<void> main() async {
|
||||
);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/40239.
|
||||
testWidgets(
|
||||
'In a pop transition, when fromHero is null, the to hero should eventually become visible',
|
||||
(WidgetTester tester) async {
|
||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey();
|
||||
StateSetter setState;
|
||||
bool shouldDisplayHero = true;
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
navigatorKey: navigatorKey,
|
||||
home: Hero(
|
||||
tag: navigatorKey,
|
||||
child: const Placeholder(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final CupertinoPageRoute<void> route2 = CupertinoPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setter) {
|
||||
setState = setter;
|
||||
return shouldDisplayHero
|
||||
? Hero(tag: navigatorKey, child: const Text('text'))
|
||||
: const SizedBox();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
navigatorKey.currentState.push(route2);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('text'), findsOneWidget);
|
||||
expect(find.byType(Placeholder), findsNothing);
|
||||
|
||||
setState(() { shouldDisplayHero = false; });
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('text'), findsNothing);
|
||||
|
||||
navigatorKey.currentState.pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(Placeholder), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('popped hero uses fastOutSlowIn curve', (WidgetTester tester) async {
|
||||
final Key container1 = UniqueKey();
|
||||
final Key container2 = UniqueKey();
|
||||
|
||||
Reference in New Issue
Block a user