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
6656356b
Unverified
Commit
6656356b
authored
3 years ago
by
LongCatIsLooong
Committed by
GitHub
3 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EditableText does not request focus on autofill (#97846)
parent
3f9c0e74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
18 deletions
+72
-18
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+21
-2
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+51
-16
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
6656356b
...
...
@@ -2391,8 +2391,27 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
widget
.
controller
.
selection
=
selection
;
// This will show the keyboard for all selection changes on the
// EditableWidget, not just changes triggered by user gestures.
requestKeyboard
();
// EditableText except for those triggered by a keyboard input.
// Typically EditableText shouldn't take user keyboard input if
// it's not focused already. If the EditableText is being
// autofilled it shouldn't request focus.
switch
(
cause
)
{
case
null
:
case
SelectionChangedCause
.
doubleTap
:
case
SelectionChangedCause
.
drag
:
case
SelectionChangedCause
.
forcePress
:
case
SelectionChangedCause
.
longPress
:
case
SelectionChangedCause
.
scribble
:
case
SelectionChangedCause
.
tap
:
case
SelectionChangedCause
.
toolbar
:
requestKeyboard
();
break
;
case
SelectionChangedCause
.
keyboard
:
if
(
_hasFocus
)
{
requestKeyboard
();
}
break
;
}
if
(
widget
.
selectionControls
==
null
)
{
_selectionOverlay
?.
dispose
();
_selectionOverlay
=
null
;
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/test/widgets/editable_text_test.dart
View file @
6656356b
...
...
@@ -3013,8 +3013,6 @@ void main() {
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorBackwardByWord
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -3049,8 +3047,6 @@ void main() {
actions:
<
SemanticsAction
>[
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -3122,8 +3118,6 @@ void main() {
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorBackwardByWord
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -3156,8 +3150,6 @@ void main() {
actions:
<
SemanticsAction
>[
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -3240,8 +3232,6 @@ void main() {
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorBackwardByWord
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -3276,8 +3266,6 @@ void main() {
actions:
<
SemanticsAction
>[
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -3360,8 +3348,6 @@ void main() {
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorBackwardByWord
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -3394,8 +3380,6 @@ void main() {
actions:
<
SemanticsAction
>[
SemanticsAction
.
moveCursorForwardByCharacter
,
SemanticsAction
.
moveCursorForwardByWord
,
SemanticsAction
.
setSelection
,
SemanticsAction
.
setText
,
],
),
);
...
...
@@ -8137,6 +8121,57 @@ void main() {
);
});
testWidgets
(
'Autofill does not request focus'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/91354 .
final
FocusNode
focusNode1
=
FocusNode
();
final
EditableText
editableText1
=
EditableText
(
showSelectionHandles:
true
,
maxLines:
2
,
controller:
TextEditingController
(),
focusNode:
focusNode1
,
cursorColor:
Colors
.
red
,
backgroundCursorColor:
Colors
.
blue
,
style:
Typography
.
material2018
().
black
.
subtitle1
!.
copyWith
(
fontFamily:
'Roboto'
),
keyboardType:
TextInputType
.
text
,
);
final
FocusNode
focusNode2
=
FocusNode
();
final
EditableText
editableText2
=
EditableText
(
showSelectionHandles:
true
,
maxLines:
2
,
controller:
TextEditingController
(),
focusNode:
focusNode2
,
cursorColor:
Colors
.
red
,
backgroundCursorColor:
Colors
.
blue
,
style:
Typography
.
material2018
().
black
.
subtitle1
!.
copyWith
(
fontFamily:
'Roboto'
),
keyboardType:
TextInputType
.
text
,
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Center
(
child:
Column
(
children:
<
Widget
>[
editableText1
,
editableText2
],
),
),
));
// editableText1 has the focus.
await
tester
.
tap
(
find
.
byWidget
(
editableText1
));
await
tester
.
pumpAndSettle
();
final
EditableTextState
state2
=
tester
.
state
<
EditableTextState
>(
find
.
byWidget
(
editableText2
));
// Update editableText2 when it's not focused. It should not request focus.
state2
.
updateEditingValue
(
const
TextEditingValue
(
text:
'password'
,
selection:
TextSelection
.
collapsed
(
offset:
8
)),
);
await
tester
.
pumpAndSettle
();
expect
(
focusNode1
.
hasFocus
,
isTrue
);
expect
(
focusNode2
.
hasFocus
,
isFalse
);
});
testWidgets
(
'setEditingState is not called when text changes'
,
(
WidgetTester
tester
)
async
{
// We shouldn't get a message here because this change is owned by the platform side.
const
String
testText
=
'flutter is the best!'
;
...
...
This diff is collapsed.
Click to expand it.
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