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
956999a4
Unverified
Commit
956999a4
authored
Aug 31, 2023
by
Polina Cherkasova
Committed by
GitHub
Aug 31, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Route dispatching memory events. (#133721)
parent
727b9fd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
2 deletions
+52
-2
navigator.dart
packages/flutter/lib/src/widgets/navigator.dart
+12
-1
app_test.dart
packages/flutter/test/material/app_test.dart
+4
-1
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+36
-0
No files found.
packages/flutter/lib/src/widgets/navigator.dart
View file @
956999a4
...
...
@@ -140,7 +140,15 @@ abstract class Route<T> {
///
/// If the [settings] are not provided, an empty [RouteSettings] object is
/// used instead.
Route
({
RouteSettings
?
settings
})
:
_settings
=
settings
??
const
RouteSettings
();
Route
({
RouteSettings
?
settings
})
:
_settings
=
settings
??
const
RouteSettings
()
{
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectCreated
(
library
:
'package:flutter/widgets.dart'
,
className:
'
$Route
<
$T
>'
,
object:
this
,
);
}
}
/// The navigator that the route is in, if any.
NavigatorState
?
get
navigator
=>
_navigator
;
...
...
@@ -503,6 +511,9 @@ abstract class Route<T> {
void
dispose
()
{
_navigator
=
null
;
_restorationScopeId
.
dispose
();
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectDisposed
(
object:
this
);
}
}
/// Whether this route is the top-most route on the navigator.
...
...
packages/flutter/test/material/app_test.dart
View file @
956999a4
...
...
@@ -338,7 +338,10 @@ void main() {
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/133695
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>
{
'ValueNotifier<String?>'
:
3
},
notDisposedAllowList:
<
String
,
int
?>
{
'ValueNotifier<String?>'
:
3
,
'MaterialPageRoute<dynamic>'
:
3
,
},
));
testWidgetsWithLeakTracking
(
'Make sure initialRoute is only used the first time'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
956999a4
...
...
@@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'
;
import
'navigator_utils.dart'
;
import
'observer_tester.dart'
;
...
...
@@ -627,6 +628,41 @@ void main() {
expect
(
observations
[
2
].
previous
,
'/A'
);
});
testWidgetsWithLeakTracking
(
'
$Route
dispatches memory events'
,
(
WidgetTester
tester
)
async
{
Future
<
void
>
createAndDisposeRoute
()
async
{
final
GlobalKey
<
NavigatorState
>
nav
=
GlobalKey
<
NavigatorState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
nav
,
home:
const
Scaffold
(
body:
Text
(
'home'
),
)
)
);
nav
.
currentState
!.
push
(
MaterialPageRoute
<
void
>(
builder:
(
_
)
=>
const
Placeholder
()));
// This should create a route
await
tester
.
pumpAndSettle
();
nav
.
currentState
!.
pop
();
await
tester
.
pumpAndSettle
();
// this should dispose the route.
}
final
List
<
ObjectEvent
>
events
=
<
ObjectEvent
>[];
void
listener
(
ObjectEvent
event
)
{
if
(
event
.
object
.
runtimeType
==
MaterialPageRoute
<
void
>)
{
events
.
add
(
event
);
}
}
MemoryAllocations
.
instance
.
addListener
(
listener
);
await
createAndDisposeRoute
();
expect
(
events
,
hasLength
(
2
));
expect
(
events
.
first
,
isA
<
ObjectCreated
>());
expect
(
events
.
last
,
isA
<
ObjectDisposed
>());
MemoryAllocations
.
instance
.
removeListener
(
listener
);
});
testWidgets
(
'Route didAdd and dispose in same frame work'
,
(
WidgetTester
tester
)
async
{
// Regression Test for https://github.com/flutter/flutter/issues/61346.
Widget
buildNavigator
()
{
...
...
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