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
8538b4f5
Unverified
Commit
8538b4f5
authored
Oct 12, 2020
by
xubaolin
Committed by
GitHub
Oct 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix TextField bug when the formatter repeatedly format (#67892)
parent
345188d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
2 deletions
+87
-2
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+9
-2
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+78
-0
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
8538b4f5
...
...
@@ -2212,8 +2212,15 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_lastFormattedValue
=
value
;
}
// Setting _value here ensures the selection and composing region info is passed.
_value
=
value
;
if
(
value
==
_value
)
{
// If the value was modified by the formatter, the remote should be notified to keep in sync,
// if not modified, it will short-circuit.
_updateRemoteEditingValueIfNeeded
();
}
else
{
// Setting _value here ensures the selection and composing region info is passed.
_value
=
value
;
}
// Use the last formatted value when an identical repeat pass is detected.
if
(
isRepeat
&&
textChanged
&&
_lastFormattedValue
!=
null
)
{
_value
=
_lastFormattedValue
!;
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
8538b4f5
...
...
@@ -4998,6 +4998,84 @@ void main() {
);
});
testWidgets
(
'Send text input state to engine when the input formatter rejects user input'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/67828
final
List
<
MethodCall
>
log
=
<
MethodCall
>[];
SystemChannels
.
textInput
.
setMockMethodCallHandler
((
MethodCall
methodCall
)
async
{
log
.
add
(
methodCall
);
});
final
TextInputFormatter
formatter
=
TextInputFormatter
.
withFunction
((
TextEditingValue
oldValue
,
TextEditingValue
newValue
)
{
return
const
TextEditingValue
(
text:
'Flutter is the best!'
);
});
final
TextEditingController
controller
=
TextEditingController
();
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'EditableText Focus Node'
);
Widget
builder
()
{
return
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setter
)
{
return
MaterialApp
(
home:
MediaQuery
(
data:
const
MediaQueryData
(
devicePixelRatio:
1.0
),
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
Material
(
child:
EditableText
(
controller:
controller
,
focusNode:
focusNode
,
style:
textStyle
,
cursorColor:
Colors
.
red
,
backgroundCursorColor:
Colors
.
red
,
keyboardType:
TextInputType
.
multiline
,
inputFormatters:
<
TextInputFormatter
>[
formatter
,
],
onChanged:
(
String
value
)
{
},
),
),
),
),
),
);
},
);
}
await
tester
.
pumpWidget
(
builder
());
await
tester
.
tap
(
find
.
byType
(
EditableText
));
await
tester
.
showKeyboard
(
find
.
byType
(
EditableText
));
await
tester
.
pump
();
log
.
clear
();
final
EditableTextState
state
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
// setEditingState is called when remote value modified by the formatter.
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'I will be modified by the formatter.'
,
));
expect
(
log
.
length
,
1
);
expect
(
log
,
contains
(
matchesMethodCall
(
'TextInput.setEditingState'
,
args:
allOf
(
containsPair
(
'text'
,
'Flutter is the best!'
),
),
)));
log
.
clear
();
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'I will be modified by the formatter.'
,
));
expect
(
log
.
length
,
1
);
expect
(
log
,
contains
(
matchesMethodCall
(
'TextInput.setEditingState'
,
args:
allOf
(
containsPair
(
'text'
,
'Flutter is the best!'
),
),
)));
});
testWidgets
(
'autofocus:true on first frame does not throw'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
controller
=
TextEditingController
(
text:
testText
);
controller
.
selection
=
const
TextSelection
(
...
...
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