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
856115b7
Commit
856115b7
authored
Jun 23, 2017
by
Jason Simmons
Committed by
GitHub
Jun 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear the selection when a text widget loses focus (#10938)
Fixes
https://github.com/flutter/flutter/issues/10911
parent
128967cd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+4
-0
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+37
-0
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
856115b7
...
...
@@ -531,6 +531,10 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
_openOrCloseInputConnectionIfNeeded
();
_startOrStopCursorTimerIfNeeded
();
_updateOrDisposeSelectionOverlayIfNeeded
();
if
(!
_hasFocus
)
{
// Clear the selection and composition state if this widget lost focus.
_value
=
new
TextEditingValue
(
text:
_value
.
text
);
}
}
@override
...
...
packages/flutter/test/material/text_field_test.dart
View file @
856115b7
...
...
@@ -1503,4 +1503,41 @@ void main() {
expect
(
scrollableState
.
position
.
pixels
,
isNot
(
equals
(
0.0
)));
}
);
testWidgets
(
'Text field drops selection when losing focus'
,
(
WidgetTester
tester
)
async
{
final
Key
key1
=
new
UniqueKey
();
final
TextEditingController
controller1
=
new
TextEditingController
();
final
Key
key2
=
new
UniqueKey
();
Widget
builder
()
{
return
overlay
(
new
Center
(
child:
new
Material
(
child:
new
Column
(
children:
<
Widget
>[
new
TextField
(
key:
key1
,
controller:
controller1
),
new
TextField
(
key:
key2
),
],
),
),
));
}
await
tester
.
pumpWidget
(
builder
());
await
tester
.
tap
(
find
.
byKey
(
key1
));
await
tester
.
enterText
(
find
.
byKey
(
key1
),
'abcd'
);
await
tester
.
pump
();
controller1
.
selection
=
const
TextSelection
(
baseOffset:
0
,
extentOffset:
3
);
await
tester
.
pump
();
expect
(
controller1
.
selection
,
isNot
(
equals
(
TextRange
.
empty
)));
await
tester
.
tap
(
find
.
byKey
(
key2
));
await
tester
.
pump
();
expect
(
controller1
.
selection
,
equals
(
TextRange
.
empty
));
}
);
}
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