Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a4f5a587
Unverified
Commit
a4f5a587
authored
Aug 16, 2021
by
Dan Field
Committed by
GitHub
Aug 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid retaining routes when subscriptions are cleared (#88310)
parent
ddb8bfb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
2 deletions
+48
-2
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+21
-2
routes_test.dart
packages/flutter/test/widgets/routes_test.dart
+27
-0
No files found.
packages/flutter/lib/src/widgets/routes.dart
View file @
a4f5a587
...
...
@@ -1733,6 +1733,19 @@ abstract class PopupRoute<T> extends ModalRoute<T> {
class
RouteObserver
<
R
extends
Route
<
dynamic
>>
extends
NavigatorObserver
{
final
Map
<
R
,
Set
<
RouteAware
>>
_listeners
=
<
R
,
Set
<
RouteAware
>>{};
/// Whether this observer is managing changes for the specified route.
///
/// If asserts are disabled, this method will throw an exception.
@visibleForTesting
bool
debugObservingRoute
(
R
route
)
{
late
bool
contained
;
assert
(()
{
contained
=
_listeners
.
containsKey
(
route
);
return
true
;
}());
return
contained
;
}
/// Subscribe [routeAware] to be informed about changes to [route].
///
/// Going forward, [routeAware] will be informed about qualifying changes
...
...
@@ -1753,9 +1766,15 @@ class RouteObserver<R extends Route<dynamic>> extends NavigatorObserver {
/// subscribed to multiple types, this will unregister it (once) from each type.
void
unsubscribe
(
RouteAware
routeAware
)
{
assert
(
routeAware
!=
null
);
for
(
final
R
route
in
_listeners
.
keys
)
{
final
List
<
R
>
routes
=
_listeners
.
keys
.
toList
();
for
(
final
R
route
in
routes
)
{
final
Set
<
RouteAware
>?
subscribers
=
_listeners
[
route
];
subscribers
?.
remove
(
routeAware
);
if
(
subscribers
!=
null
)
{
subscribers
.
remove
(
routeAware
);
if
(
subscribers
.
isEmpty
)
{
_listeners
.
remove
(
route
);
}
}
}
}
...
...
packages/flutter/test/widgets/routes_test.dart
View file @
a4f5a587
...
...
@@ -525,6 +525,33 @@ void main() {
expect
(
pageRouteAware
.
didPushCount
,
2
);
expect
(
pageRouteAware
.
didPopCount
,
0
);
});
test
(
'releases reference to route when unsubscribed'
,
()
{
final
RouteObserver
<
PageRoute
<
dynamic
>>
observer
=
RouteObserver
<
PageRoute
<
dynamic
>>();
final
MockRouteAware
pageRouteAware
=
MockRouteAware
();
final
MockRouteAware
page2RouteAware
=
MockRouteAware
();
final
MockPageRoute
pageRoute
=
MockPageRoute
();
final
MockPageRoute
nextPageRoute
=
MockPageRoute
();
observer
.
subscribe
(
pageRouteAware
,
pageRoute
);
observer
.
subscribe
(
pageRouteAware
,
nextPageRoute
);
observer
.
subscribe
(
page2RouteAware
,
pageRoute
);
observer
.
subscribe
(
page2RouteAware
,
nextPageRoute
);
expect
(
pageRouteAware
.
didPushCount
,
2
);
expect
(
page2RouteAware
.
didPushCount
,
2
);
expect
(
observer
.
debugObservingRoute
(
pageRoute
),
true
);
expect
(
observer
.
debugObservingRoute
(
nextPageRoute
),
true
);
observer
.
unsubscribe
(
pageRouteAware
);
expect
(
observer
.
debugObservingRoute
(
pageRoute
),
true
);
expect
(
observer
.
debugObservingRoute
(
nextPageRoute
),
true
);
observer
.
unsubscribe
(
page2RouteAware
);
expect
(
observer
.
debugObservingRoute
(
pageRoute
),
false
);
expect
(
observer
.
debugObservingRoute
(
nextPageRoute
),
false
);
});
});
testWidgets
(
'Can autofocus a TextField nested in a Focus in a route.'
,
(
WidgetTester
tester
)
async
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment