Unverified Commit 89c8616f authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

fix `_owner` nullability in `routers.dart` (#84840)

parent 0504fac7
...@@ -447,7 +447,7 @@ class LocalHistoryEntry { ...@@ -447,7 +447,7 @@ class LocalHistoryEntry {
/// Remove this entry from the history of its associated [LocalHistoryRoute]. /// Remove this entry from the history of its associated [LocalHistoryRoute].
void remove() { void remove() {
_owner!.removeLocalHistoryEntry(this); _owner?.removeLocalHistoryEntry(this);
assert(_owner == null); assert(_owner == null);
} }
......
...@@ -1701,7 +1701,6 @@ void main() { ...@@ -1701,7 +1701,6 @@ void main() {
state.addLocalHistory(); state.addLocalHistory();
// Waits for modal route to update its internal state; // Waits for modal route to update its internal state;
await tester.pump(); await tester.pump();
// Pumps a new widget to dispose WidgetWithLocalHistory. This should cause // Pumps a new widget to dispose WidgetWithLocalHistory. This should cause
// it to remove the local history entry from modal route during // it to remove the local history entry from modal route during
// finalizeTree. // finalizeTree.
...@@ -1712,6 +1711,25 @@ void main() { ...@@ -1712,6 +1711,25 @@ void main() {
await tester.pump(); await tester.pump();
expect(tester.takeException(), null); expect(tester.takeException(), null);
}); });
testWidgets('child with no local history can be disposed', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: WidgetWithNoLocalHistory(),
));
final WidgetWithNoLocalHistoryState state = tester.state(find.byType(WidgetWithNoLocalHistory));
state.addLocalHistory();
// Waits for modal route to update its internal state;
await tester.pump();
// Pumps a new widget to dispose WidgetWithNoLocalHistory. This should cause
// it to remove the local history entry from modal route during
// finalizeTree.
await tester.pumpWidget(const MaterialApp(
home: Text('dummy'),
));
await tester.pump();
expect(tester.takeException(), null);
});
}); });
testWidgets('can be dismissed with escape keyboard shortcut', (WidgetTester tester) async { testWidgets('can be dismissed with escape keyboard shortcut', (WidgetTester tester) async {
...@@ -1972,6 +1990,33 @@ class WidgetWithLocalHistoryState extends State<WidgetWithLocalHistory> { ...@@ -1972,6 +1990,33 @@ class WidgetWithLocalHistoryState extends State<WidgetWithLocalHistory> {
} }
} }
class WidgetWithNoLocalHistory extends StatefulWidget {
const WidgetWithNoLocalHistory({Key? key}) : super(key: key);
@override
WidgetWithNoLocalHistoryState createState() => WidgetWithNoLocalHistoryState();
}
class WidgetWithNoLocalHistoryState extends State<WidgetWithNoLocalHistory> {
late LocalHistoryEntry _localHistory;
void addLocalHistory() {
_localHistory = LocalHistoryEntry();
// Not calling `route.addLocalHistoryEntry` here.
}
@override
void dispose() {
super.dispose();
_localHistory.remove();
}
@override
Widget build(BuildContext context) {
return const Text('dummy');
}
}
class TransitionDetector extends DefaultTransitionDelegate<void> { class TransitionDetector extends DefaultTransitionDelegate<void> {
bool hasTransition = false; bool hasTransition = false;
@override @override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment