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
7de099bd
Unverified
Commit
7de099bd
authored
Apr 01, 2021
by
LongCatIsLooong
Committed by
GitHub
Apr 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix length formatter typo (#79489)
parent
5740a629
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
1 deletion
+85
-1
text_formatter.dart
packages/flutter/lib/src/services/text_formatter.dart
+1
-1
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+84
-0
No files found.
packages/flutter/lib/src/services/text_formatter.dart
View file @
7de099bd
...
...
@@ -502,7 +502,7 @@ class LengthLimitingTextInputFormatter extends TextInputFormatter {
case
MaxLengthEnforcement
.
enforced
:
// If already at the maximum and tried to enter even more, and has no
// selection, keep the old value.
if
(
oldValue
.
text
.
characters
.
length
==
maxLength
&&
!
oldValue
.
selection
.
isVali
d
)
{
if
(
oldValue
.
text
.
characters
.
length
==
maxLength
&&
oldValue
.
selection
.
isCollapse
d
)
{
return
oldValue
;
}
...
...
packages/flutter/test/material/text_field_test.dart
View file @
7de099bd
...
...
@@ -3864,6 +3864,90 @@ void main() {
expect
(
textController
.
text
,
testValue
);
});
testWidgets
(
'maxLength limits input in the center of a maxed-out field, with collapsed selection'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
textController
=
TextEditingController
();
const
String
testValue
=
'0123456789'
;
await
tester
.
pumpWidget
(
boilerplate
(
child:
TextField
(
controller:
textController
,
maxLength:
10
,
),
));
// Max out the character limit in the field.
await
tester
.
showKeyboard
(
find
.
byType
(
TextField
));
tester
.
testTextInput
.
updateEditingValue
(
const
TextEditingValue
(
text:
testValue
,
selection:
TextSelection
.
collapsed
(
offset:
10
),
composing:
TextRange
.
empty
,
));
await
tester
.
pump
();
expect
(
textController
.
text
,
testValue
);
// Entering more characters at the end does nothing.
await
tester
.
showKeyboard
(
find
.
byType
(
TextField
));
tester
.
testTextInput
.
updateEditingValue
(
const
TextEditingValue
(
text:
testValue
+
'9999999'
,
selection:
TextSelection
.
collapsed
(
offset:
10
+
7
),
composing:
TextRange
.
empty
,
));
await
tester
.
pump
();
expect
(
textController
.
text
,
testValue
);
// Entering text in the middle of the field also does nothing.
// Entering more characters at the end does nothing.
await
tester
.
showKeyboard
(
find
.
byType
(
TextField
));
tester
.
testTextInput
.
updateEditingValue
(
const
TextEditingValue
(
text:
'0123455555555556789'
,
selection:
TextSelection
.
collapsed
(
offset:
19
),
composing:
TextRange
.
empty
,
));
await
tester
.
pump
();
expect
(
textController
.
text
,
testValue
);
},
);
testWidgets
(
'maxLength limits input in the center of a maxed-out field, with non-collapsed selection'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
textController
=
TextEditingController
();
const
String
testValue
=
'0123456789'
;
await
tester
.
pumpWidget
(
boilerplate
(
child:
TextField
(
controller:
textController
,
maxLength:
10
,
),
));
// Max out the character limit in the field.
await
tester
.
showKeyboard
(
find
.
byType
(
TextField
));
tester
.
testTextInput
.
updateEditingValue
(
const
TextEditingValue
(
text:
testValue
,
selection:
TextSelection
(
baseOffset:
8
,
extentOffset:
10
),
composing:
TextRange
.
empty
,
));
await
tester
.
pump
();
expect
(
textController
.
text
,
testValue
);
// Entering more characters at the end does nothing.
await
tester
.
showKeyboard
(
find
.
byType
(
TextField
));
tester
.
testTextInput
.
updateEditingValue
(
const
TextEditingValue
(
text:
'01234569999999'
,
selection:
TextSelection
.
collapsed
(
offset:
14
),
composing:
TextRange
.
empty
,
));
await
tester
.
pump
();
expect
(
textController
.
text
,
'0123456999'
);
},
);
testWidgets
(
'maxLength limits input length even if decoration is null.'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
textController
=
TextEditingController
();
...
...
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