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
2a8e7b7b
Unverified
Commit
2a8e7b7b
authored
Mar 23, 2020
by
chunhtai
Committed by
GitHub
Mar 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix changinternalstate crash when remove local history entry in final… (#52561)
parent
fed6887a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
2 deletions
+61
-2
routes.dart
packages/flutter/lib/src/widgets/routes.dart
+13
-2
routes_test.dart
packages/flutter/test/widgets/routes_test.dart
+48
-0
No files found.
packages/flutter/lib/src/widgets/routes.dart
View file @
2a8e7b7b
...
...
@@ -6,6 +6,7 @@ import 'dart:async';
import
'dart:ui'
as
ui
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'basic.dart'
;
import
'focus_manager.dart'
;
...
...
@@ -606,8 +607,18 @@ mixin LocalHistoryRoute<T> on Route<T> {
_localHistory
.
remove
(
entry
);
entry
.
_owner
=
null
;
entry
.
_notifyRemoved
();
if
(
_localHistory
.
isEmpty
)
changedInternalState
();
if
(
_localHistory
.
isEmpty
)
{
if
(
SchedulerBinding
.
instance
.
schedulerPhase
==
SchedulerPhase
.
persistentCallbacks
)
{
// The local history might be removed as a result of disposing inactive
// elements during finalizeTree. The state is locked at this moment, and
// we can only notify state has changed in the next frame.
SchedulerBinding
.
instance
.
addPostFrameCallback
((
Duration
duration
)
{
changedInternalState
();
});
}
else
{
changedInternalState
();
}
}
}
@override
...
...
packages/flutter/test/widgets/routes_test.dart
View file @
2a8e7b7b
...
...
@@ -1294,6 +1294,28 @@ void main() {
// It should refocus page one after pops.
expect
(
focusNodeOnPageOne
.
hasFocus
,
isTrue
);
});
testWidgets
(
'child with local history can be disposed'
,
(
WidgetTester
tester
)
async
{
// Regression test: https://github.com/flutter/flutter/issues/52478
await
tester
.
pumpWidget
(
MaterialApp
(
home:
WidgetWithLocalHistory
(),
));
final
WidgetWithLocalHistoryState
state
=
tester
.
state
(
find
.
byType
(
WidgetWithLocalHistory
));
state
.
addLocalHistory
();
// Waits for modal route to update its internal state;
await
tester
.
pump
();
// Pumps a new widget to dispose WidgetWithLocalHistory. This should cause
// it to remove the local history entry from modal route during
// finalizeTree.
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Text
(
'dummy'
),
));
// Waits for modal route to update its internal state;
await
tester
.
pump
();
expect
(
tester
.
takeException
(),
null
);
});
});
}
...
...
@@ -1390,3 +1412,29 @@ class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> {
);
}
}
class
WidgetWithLocalHistory
extends
StatefulWidget
{
@override
WidgetWithLocalHistoryState
createState
()
=>
WidgetWithLocalHistoryState
();
}
class
WidgetWithLocalHistoryState
extends
State
<
WidgetWithLocalHistory
>
{
LocalHistoryEntry
_localHistory
;
void
addLocalHistory
()
{
final
ModalRoute
<
dynamic
>
route
=
ModalRoute
.
of
(
context
);
_localHistory
=
LocalHistoryEntry
();
route
.
addLocalHistoryEntry
(
_localHistory
);
}
@override
void
dispose
()
{
super
.
dispose
();
_localHistory
.
remove
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
const
Text
(
'dummy'
);
}
}
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