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
31e75545
Unverified
Commit
31e75545
authored
May 21, 2021
by
Ludwik Trammer
Committed by
GitHub
May 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make SelectableText focus traversal behavior more standard (#80110)
parent
f33e88ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
+44
-2
selectable_text.dart
packages/flutter/lib/src/material/selectable_text.dart
+5
-2
selectable_text_test.dart
packages/flutter/test/widgets/selectable_text_test.dart
+39
-0
No files found.
packages/flutter/lib/src/material/selectable_text.dart
View file @
31e75545
...
...
@@ -304,7 +304,9 @@ class SelectableText extends StatefulWidget {
/// focusNode.addListener(() { print(myFocusNode.hasFocus); });
/// ```
///
/// If null, this widget will create its own [FocusNode].
/// If null, this widget will create its own [FocusNode] with
/// [FocusNode.skipTraversal] parameter set to `true`, which causes the widget
/// to be skipped over during focus traversal.
final
FocusNode
?
focusNode
;
/// The style to use for the text.
...
...
@@ -431,7 +433,8 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
late
_TextSpanEditingController
_controller
;
FocusNode
?
_focusNode
;
FocusNode
get
_effectiveFocusNode
=>
widget
.
focusNode
??
(
_focusNode
??=
FocusNode
());
FocusNode
get
_effectiveFocusNode
=>
widget
.
focusNode
??
(
_focusNode
??=
FocusNode
(
skipTraversal:
true
));
bool
_showSelectionHandles
=
false
;
...
...
packages/flutter/test/widgets/selectable_text_test.dart
View file @
31e75545
...
...
@@ -1417,6 +1417,45 @@ void main() {
expect
(
controller
.
selection
,
equals
(
TextRange
.
empty
));
});
testWidgets
(
'Selectable text is skipped during focus traversal'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
firstFieldFocus
=
FocusNode
();
final
FocusNode
lastFieldFocus
=
FocusNode
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
Center
(
child:
Column
(
children:
<
Widget
>[
TextField
(
focusNode:
firstFieldFocus
,
autofocus:
true
,
),
const
SelectableText
(
'some text'
),
TextField
(
focusNode:
lastFieldFocus
,
),
],
),
),
),
),
);
await
tester
.
pump
();
expect
(
firstFieldFocus
.
hasFocus
,
isTrue
);
expect
(
lastFieldFocus
.
hasFocus
,
isFalse
);
firstFieldFocus
.
nextFocus
();
await
tester
.
pump
();
// expecting focus to skip straight to the second field
expect
(
firstFieldFocus
.
hasFocus
,
isFalse
);
expect
(
lastFieldFocus
.
hasFocus
,
isTrue
);
});
testWidgets
(
'Selectable text identifies as text field in semantics'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
...
...
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