Skip to content

Commit ab1b865

Browse files
authored
Dispose routes in navigator when throwing exception (flutter#134596)
fixes: flutter#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
1 parent 2daf917 commit ab1b865

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

packages/flutter/lib/src/widgets/navigator.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,9 @@ class Navigator extends StatefulWidget {
27922792
);
27932793
return true;
27942794
}());
2795+
for (final Route<dynamic>? route in result) {
2796+
route?.dispose();
2797+
}
27952798
result.clear();
27962799
}
27972800
} else if (initialRouteName != Navigator.defaultRouteName) {

packages/flutter/test/material/app_test.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,7 @@ void main() {
334334
expect(find.text('route "/a/b"'), findsNothing);
335335
expect(find.text('route "/b"'), findsNothing);
336336
}
337-
},
338-
// TODO(polina-c): remove after fixing
339-
// https://github.com/flutter/flutter/issues/133695
340-
leakTrackingTestConfig: const LeakTrackingTestConfig(
341-
notDisposedAllowList: <String, int?> {
342-
'ValueNotifier<String?>': 3,
343-
'MaterialPageRoute<dynamic>': 3,
344-
},
345-
));
337+
});
346338

347339
testWidgetsWithLeakTracking('Make sure initialRoute is only used the first time', (WidgetTester tester) async {
348340
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{

0 commit comments

Comments
 (0)