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
0abb017c
Unverified
Commit
0abb017c
authored
Oct 19, 2023
by
Greg Spencer
Committed by
GitHub
Oct 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reland: "Add code for updating `focusedChild` when removing grandchildren from scope" (#136899)
parent
f82299ef
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletion
+47
-1
focus_manager.dart
packages/flutter/lib/src/widgets/focus_manager.dart
+7
-1
focus_manager_test.dart
packages/flutter/test/widgets/focus_manager_test.dart
+40
-0
No files found.
packages/flutter/lib/src/widgets/focus_manager.dart
View file @
0abb017c
...
...
@@ -964,7 +964,13 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
assert
(
node
.
_manager
==
_manager
);
if
(
removeScopeFocus
)
{
node
.
enclosingScope
?.
_focusedChildren
.
remove
(
node
);
final
FocusScopeNode
?
nodeScope
=
node
.
enclosingScope
;
if
(
nodeScope
!=
null
)
{
nodeScope
.
_focusedChildren
.
remove
(
node
);
node
.
descendants
.
where
((
FocusNode
descendant
)
{
return
descendant
.
enclosingScope
==
nodeScope
;
}).
forEach
(
nodeScope
.
_focusedChildren
.
remove
);
}
}
node
.
_parent
=
null
;
...
...
packages/flutter/test/widgets/focus_manager_test.dart
View file @
0abb017c
...
...
@@ -459,6 +459,46 @@ void main() {
expect
(
child2
.
hasPrimaryFocus
,
isTrue
);
});
// Regression test for https://github.com/flutter/flutter/issues/136758
testWidgetsWithLeakTracking
(
'removing grandchildren from scope updates focusedChild'
,
(
WidgetTester
tester
)
async
{
final
BuildContext
context
=
await
setupWidget
(
tester
);
// Sets up this focus node tree:
//
// root
// |
// scope1
// |
// child1
// |
// child2
final
FocusScopeNode
scope1
=
FocusScopeNode
(
debugLabel:
'scope2'
);
addTearDown
(
scope1
.
dispose
);
final
FocusAttachment
scope2Attachment
=
scope1
.
attach
(
context
);
scope2Attachment
.
reparent
(
parent:
tester
.
binding
.
focusManager
.
rootScope
);
final
FocusNode
child1
=
FocusNode
(
debugLabel:
'child2'
);
addTearDown
(
child1
.
dispose
);
final
FocusAttachment
child2Attachment
=
child1
.
attach
(
context
);
final
FocusNode
child2
=
FocusNode
(
debugLabel:
'child3'
);
addTearDown
(
child2
.
dispose
);
final
FocusAttachment
child3Attachment
=
child2
.
attach
(
context
);
child2Attachment
.
reparent
(
parent:
scope1
);
child3Attachment
.
reparent
(
parent:
child1
);
expect
(
child1
.
parent
,
equals
(
scope1
));
expect
(
scope1
.
children
.
first
,
equals
(
child1
));
child2
.
requestFocus
();
await
tester
.
pump
();
expect
(
scope1
.
focusedChild
,
equals
(
child2
));
// Detach the middle child and make sure that the scope is updated so that
// it no longer references child2 as the focused child.
child2Attachment
.
detach
();
expect
(
scope1
.
focusedChild
,
isNull
);
});
testWidgetsWithLeakTracking
(
'Requesting focus before adding to tree results in a request after adding'
,
(
WidgetTester
tester
)
async
{
final
BuildContext
context
=
await
setupWidget
(
tester
);
final
FocusScopeNode
scope
=
FocusScopeNode
();
...
...
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