Unverified Commit ab1b865e authored by hangyu's avatar hangyu Committed by GitHub

Dispose routes in navigator when throwing exception (#134596)

fixes: #133695
## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
parent 2daf9177
...@@ -2792,6 +2792,9 @@ class Navigator extends StatefulWidget { ...@@ -2792,6 +2792,9 @@ class Navigator extends StatefulWidget {
); );
return true; return true;
}()); }());
for (final Route<dynamic>? route in result) {
route?.dispose();
}
result.clear(); result.clear();
} }
} else if (initialRouteName != Navigator.defaultRouteName) { } else if (initialRouteName != Navigator.defaultRouteName) {
......
...@@ -334,15 +334,7 @@ void main() { ...@@ -334,15 +334,7 @@ void main() {
expect(find.text('route "/a/b"'), findsNothing); expect(find.text('route "/a/b"'), findsNothing);
expect(find.text('route "/b"'), findsNothing); expect(find.text('route "/b"'), findsNothing);
} }
}, });
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/133695
leakTrackingTestConfig: const LeakTrackingTestConfig(
notDisposedAllowList: <String, int?> {
'ValueNotifier<String?>': 3,
'MaterialPageRoute<dynamic>': 3,
},
));
testWidgetsWithLeakTracking('Make sure initialRoute is only used the first time', (WidgetTester tester) async { testWidgetsWithLeakTracking('Make sure initialRoute is only used the first time', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
......
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