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
8c3806f8
Unverified
Commit
8c3806f8
authored
Oct 25, 2022
by
Greg Spencer
Committed by
GitHub
Oct 25, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parentNode to FocusScope widget (#114034)
parent
3ce88d38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
2 deletions
+70
-2
focus_scope.dart
packages/flutter/lib/src/widgets/focus_scope.dart
+4
-2
focus_scope_test.dart
packages/flutter/test/widgets/focus_scope_test.dart
+66
-0
No files found.
packages/flutter/lib/src/widgets/focus_scope.dart
View file @
8c3806f8
...
...
@@ -760,6 +760,7 @@ class FocusScope extends Focus {
const
FocusScope
({
super
.
key
,
FocusScopeNode
?
node
,
super
.
parentNode
,
required
super
.
child
,
super
.
autofocus
,
super
.
onFocusChange
,
...
...
@@ -781,6 +782,7 @@ class FocusScope extends Focus {
Key
?
key
,
required
Widget
child
,
required
FocusScopeNode
focusScopeNode
,
FocusNode
?
parentNode
,
bool
autofocus
,
ValueChanged
<
bool
>?
onFocusChange
,
})
=
_FocusScopeWithExternalFocusNode
;
...
...
@@ -809,13 +811,13 @@ class _FocusScopeWithExternalFocusNode extends FocusScope {
super
.
key
,
required
super
.
child
,
required
FocusScopeNode
focusScopeNode
,
super
.
parentNode
,
super
.
autofocus
,
super
.
onFocusChange
,
})
:
super
(
node:
focusScopeNode
,
);
@override
bool
get
_usingExternalFocus
=>
true
;
@override
...
...
@@ -846,7 +848,7 @@ class _FocusScopeState extends _FocusState {
@override
Widget
build
(
BuildContext
context
)
{
_focusAttachment
!.
reparent
();
_focusAttachment
!.
reparent
(
parent:
widget
.
parentNode
);
return
Semantics
(
explicitChildNodes:
true
,
child:
_FocusMarker
(
...
...
packages/flutter/test/widgets/focus_scope_test.dart
View file @
8c3806f8
...
...
@@ -532,6 +532,72 @@ void main() {
expect
(
insertedNode
.
hasFocus
,
isFalse
);
});
testWidgets
(
'Setting parentNode determines focus scope tree hierarchy.'
,
(
WidgetTester
tester
)
async
{
final
FocusScopeNode
topNode
=
FocusScopeNode
(
debugLabel:
'Top'
);
final
FocusScopeNode
parentNode
=
FocusScopeNode
(
debugLabel:
'Parent'
);
final
FocusScopeNode
childNode
=
FocusScopeNode
(
debugLabel:
'Child'
);
final
FocusScopeNode
insertedNode
=
FocusScopeNode
(
debugLabel:
'Inserted'
);
await
tester
.
pumpWidget
(
FocusScope
.
withExternalFocusNode
(
focusScopeNode:
topNode
,
child:
Column
(
children:
<
Widget
>[
FocusScope
.
withExternalFocusNode
(
focusScopeNode:
parentNode
,
child:
const
SizedBox
(),
),
FocusScope
.
withExternalFocusNode
(
focusScopeNode:
childNode
,
parentNode:
parentNode
,
child:
const
Focus
(
autofocus:
true
,
child:
SizedBox
(),
),
)
],
),
),
);
await
tester
.
pump
();
expect
(
childNode
.
hasFocus
,
isTrue
);
expect
(
parentNode
.
hasFocus
,
isTrue
);
expect
(
topNode
.
hasFocus
,
isTrue
);
// Check that inserting a Focus in between doesn't reparent the child.
await
tester
.
pumpWidget
(
FocusScope
.
withExternalFocusNode
(
focusScopeNode:
topNode
,
child:
Column
(
children:
<
Widget
>[
FocusScope
.
withExternalFocusNode
(
focusScopeNode:
parentNode
,
child:
const
SizedBox
(),
),
FocusScope
.
withExternalFocusNode
(
focusScopeNode:
insertedNode
,
child:
FocusScope
.
withExternalFocusNode
(
focusScopeNode:
childNode
,
parentNode:
parentNode
,
child:
const
Focus
(
autofocus:
true
,
child:
SizedBox
(),
),
),
)
],
),
),
);
await
tester
.
pump
();
expect
(
childNode
.
hasFocus
,
isTrue
);
expect
(
parentNode
.
hasFocus
,
isTrue
);
expect
(
topNode
.
hasFocus
,
isTrue
);
expect
(
insertedNode
.
hasFocus
,
isFalse
);
});
// Arguably, this isn't correct behavior, but it is what happens now.
testWidgets
(
"Removing focused widget doesn't move focus to next widget within FocusScope"
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
TestFocusState
>
keyA
=
GlobalKey
();
...
...
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