Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 68587a0

Browse files
LongCatIsLooonggoderbauer
authored andcommittedOct 22, 2019
V1.9.1 hotfix
This fixes the issue described in #40239: * Restore offstage and ticker mode after hero pop and the from hero is null (#40306)
1 parent 1aedbb1 commit 68587a0

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
 

‎packages/flutter/lib/src/widgets/heroes.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ class _HeroState extends State<Hero> {
359359
}
360360

361361
// When `keepPlaceholder` is true, the placeholder will continue to be shown
362-
// after the flight ends.
362+
// after the flight ends. Otherwise the child of the Hero will become visible
363+
// and its TickerMode will be re-enabled.
363364
void endFlight({ bool keepPlaceholder = false }) {
364365
if (!keepPlaceholder) {
365366
ensurePlaceholderIsHidden();
@@ -828,6 +829,13 @@ class HeroController extends NavigatorObserver {
828829
_flights[tag].abort();
829830
}
830831
}
832+
833+
// If the from hero is gone, the flight won't start and the to hero needs to
834+
// be put on stage again.
835+
for (Object tag in toHeroes.keys) {
836+
if (fromHeroes[tag] == null)
837+
toHeroes[tag].ensurePlaceholderIsHidden();
838+
}
831839
}
832840

833841
void _handleFlightEnded(_HeroFlight flight) {

‎packages/flutter/test/widgets/heroes_test.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,4 +2255,54 @@ Future<void> main() async {
22552255
moreOrLessEquals(tester.getTopLeft(find.text('1')).dx, epsilon: 0.01)
22562256
);
22572257
});
2258+
2259+
// Regression test for https://github.com/flutter/flutter/issues/40239.
2260+
testWidgets(
2261+
'In a pop transition, when fromHero is null, the to hero should eventually become visible',
2262+
(WidgetTester tester) async {
2263+
final GlobalKey<NavigatorState> navigatorKey = GlobalKey();
2264+
StateSetter setState;
2265+
bool shouldDisplayHero = true;
2266+
await tester.pumpWidget(
2267+
CupertinoApp(
2268+
navigatorKey: navigatorKey,
2269+
home: Hero(
2270+
tag: navigatorKey,
2271+
child: const Placeholder(),
2272+
),
2273+
),
2274+
);
2275+
2276+
final CupertinoPageRoute<void> route2 = CupertinoPageRoute<void>(
2277+
builder: (BuildContext context) {
2278+
return CupertinoPageScaffold(
2279+
child: StatefulBuilder(
2280+
builder: (BuildContext context, StateSetter setter) {
2281+
setState = setter;
2282+
return shouldDisplayHero
2283+
? Hero(tag: navigatorKey, child: const Text('text'))
2284+
: const SizedBox();
2285+
},
2286+
),
2287+
);
2288+
},
2289+
);
2290+
2291+
navigatorKey.currentState.push(route2);
2292+
await tester.pumpAndSettle();
2293+
2294+
expect(find.text('text'), findsOneWidget);
2295+
expect(find.byType(Placeholder), findsNothing);
2296+
2297+
setState(() { shouldDisplayHero = false; });
2298+
await tester.pumpAndSettle();
2299+
2300+
expect(find.text('text'), findsNothing);
2301+
2302+
navigatorKey.currentState.pop();
2303+
await tester.pumpAndSettle();
2304+
2305+
expect(find.byType(Placeholder), findsOneWidget);
2306+
},
2307+
);
22582308
}

0 commit comments

Comments
 (0)
Please sign in to comment.