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
06fb863a
Unverified
Commit
06fb863a
authored
Mar 08, 2022
by
Kate Lovett
Committed by
GitHub
Mar 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Remove deprecated CupertinoTextField, TextField, TextFormField maxLengthEnforced" (#99768)
parent
df7f05f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
24 deletions
+97
-24
text_field.dart
packages/flutter/lib/src/cupertino/text_field.dart
+43
-8
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+38
-12
text_form_field.dart
packages/flutter/lib/src/material/text_form_field.dart
+12
-0
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+4
-4
No files found.
packages/flutter/lib/src/cupertino/text_field.dart
View file @
06fb863a
...
...
@@ -194,10 +194,10 @@ class CupertinoTextField extends StatefulWidget {
/// must not be null.
///
/// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior],
/// [expands], [
obscureText], [prefixMode], [readOnly], [scrollPadding
],
/// [s
uffixMode], [textAlign], [selectionHeightStyle], [selectionWidth
Style],
/// [
enableSuggestions], and [enableIMEPersonalizedLearning] properties must
/// not be null.
/// [expands], [
maxLengthEnforced], [obscureText], [prefixMode], [readOnly
],
/// [s
crollPadding], [suffixMode], [textAlign], [selectionHeight
Style],
/// [
selectionWidthStyle], [enableSuggestions], and [enableIMEPersonalizedLearning]
///
properties must
not be null.
///
/// See also:
///
...
...
@@ -244,6 +244,12 @@ class CupertinoTextField extends StatefulWidget {
this
.
minLines
,
this
.
expands
=
false
,
this
.
maxLength
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
,
)
this
.
maxLengthEnforced
=
true
,
this
.
maxLengthEnforcement
,
this
.
onChanged
,
this
.
onEditingComplete
,
...
...
@@ -278,6 +284,11 @@ class CupertinoTextField extends StatefulWidget {
smartDashesType
=
smartDashesType
??
(
obscureText
?
SmartDashesType
.
disabled
:
SmartDashesType
.
enabled
),
smartQuotesType
=
smartQuotesType
??
(
obscureText
?
SmartQuotesType
.
disabled
:
SmartQuotesType
.
enabled
),
assert
(
enableSuggestions
!=
null
),
assert
(
maxLengthEnforced
!=
null
),
assert
(
maxLengthEnforced
||
maxLengthEnforcement
==
null
,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement'
,
),
assert
(
scrollPadding
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
selectionHeightStyle
!=
null
),
...
...
@@ -359,9 +370,9 @@ class CupertinoTextField extends StatefulWidget {
/// must not be null.
///
/// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior],
/// [expands], [
obscureText], [prefixMode], [readOnly], [scrollPadding
],
/// [s
uffixMode], [textAlign], [selectionHeightStyle], [selectionWidth
Style],
/// and [enableSuggestions] properties must not be null.
/// [expands], [
maxLengthEnforced], [obscureText], [prefixMode], [readOnly
],
/// [s
crollPadding], [suffixMode], [textAlign], [selectionHeight
Style],
///
[selectionWidthStyle],
and [enableSuggestions] properties must not be null.
///
/// See also:
///
...
...
@@ -405,6 +416,12 @@ class CupertinoTextField extends StatefulWidget {
this
.
minLines
,
this
.
expands
=
false
,
this
.
maxLength
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
,
)
this
.
maxLengthEnforced
=
true
,
this
.
maxLengthEnforcement
,
this
.
onChanged
,
this
.
onEditingComplete
,
...
...
@@ -439,6 +456,11 @@ class CupertinoTextField extends StatefulWidget {
smartDashesType
=
smartDashesType
??
(
obscureText
?
SmartDashesType
.
disabled
:
SmartDashesType
.
enabled
),
smartQuotesType
=
smartQuotesType
??
(
obscureText
?
SmartQuotesType
.
disabled
:
SmartQuotesType
.
enabled
),
assert
(
enableSuggestions
!=
null
),
assert
(
maxLengthEnforced
!=
null
),
assert
(
maxLengthEnforced
||
maxLengthEnforcement
==
null
,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement'
,
),
assert
(
scrollPadding
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
selectionHeightStyle
!=
null
),
...
...
@@ -666,6 +688,18 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength}
final
int
?
maxLength
;
/// If [maxLength] is set, [maxLengthEnforced] indicates whether or not to
/// enforce the limit.
///
/// If true, prevents the field from allowing more than [maxLength]
/// characters.
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
,
)
final
bool
maxLengthEnforced
;
/// Determines how the [maxLength] limit should be enforced.
///
/// If [MaxLengthEnforcement.none] is set, additional input beyond [maxLength]
...
...
@@ -804,6 +838,7 @@ class CupertinoTextField extends StatefulWidget {
properties
.
add
(
IntProperty
(
'minLines'
,
minLines
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
bool
>(
'expands'
,
expands
,
defaultValue:
false
));
properties
.
add
(
IntProperty
(
'maxLength'
,
maxLength
,
defaultValue:
null
));
properties
.
add
(
FlagProperty
(
'maxLengthEnforced'
,
value:
maxLengthEnforced
,
ifTrue:
'max length enforced'
));
properties
.
add
(
EnumProperty
<
MaxLengthEnforcement
>(
'maxLengthEnforcement'
,
maxLengthEnforcement
,
defaultValue:
null
));
properties
.
add
(
DoubleProperty
(
'cursorWidth'
,
cursorWidth
,
defaultValue:
2.0
));
properties
.
add
(
DoubleProperty
(
'cursorHeight'
,
cursorHeight
,
defaultValue:
null
));
...
...
@@ -1157,7 +1192,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
final
Offset
cursorOffset
=
Offset
(
_iOSHorizontalCursorOffsetPixels
/
MediaQuery
.
of
(
context
).
devicePixelRatio
,
0
);
final
List
<
TextInputFormatter
>
formatters
=
<
TextInputFormatter
>[
...?
widget
.
inputFormatters
,
if
(
widget
.
maxLength
!=
null
)
if
(
widget
.
maxLength
!=
null
&&
widget
.
maxLengthEnforced
)
LengthLimitingTextInputFormatter
(
widget
.
maxLength
,
maxLengthEnforcement:
_effectiveMaxLengthEnforcement
,
...
...
packages/flutter/lib/src/material/text_field.dart
View file @
06fb863a
...
...
@@ -251,10 +251,9 @@ class TextField extends StatefulWidget {
/// which is evaluated after the supplied [inputFormatters], if any.
/// The [maxLength] value must be either null or greater than zero.
///
/// If [maxLengthEnforcement] is set to [MaxLengthEnforcement.none], then more
/// than [maxLength] characters may be entered, and the error counter and
/// divider will switch to the [decoration].errorStyle when the limit is
/// exceeded.
/// If [maxLengthEnforced] is set to false, then more than [maxLength]
/// characters may be entered, and the error counter and divider will
/// switch to the [decoration].errorStyle when the limit is exceeded.
///
/// The text cursor is not shown if [showCursor] is false or if [showCursor]
/// is null (the default) and [readOnly] is true.
...
...
@@ -265,8 +264,8 @@ class TextField extends StatefulWidget {
/// must not be null.
///
/// The [textAlign], [autofocus], [obscureText], [readOnly], [autocorrect],
/// [
scrollPadding], [maxLines], [maxLength], [selectionHeightStyle
],
/// [selectionWidthStyle], [enableSuggestions], and
/// [
maxLengthEnforced], [scrollPadding], [maxLines], [maxLength
],
/// [selection
HeightStyle], [selection
WidthStyle], [enableSuggestions], and
/// [enableIMEPersonalizedLearning] arguments must not be null.
///
/// See also:
...
...
@@ -300,6 +299,12 @@ class TextField extends StatefulWidget {
this
.
minLines
,
this
.
expands
=
false
,
this
.
maxLength
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
,
)
this
.
maxLengthEnforced
=
true
,
this
.
maxLengthEnforcement
,
this
.
onChanged
,
this
.
onEditingComplete
,
...
...
@@ -337,6 +342,11 @@ class TextField extends StatefulWidget {
smartDashesType
=
smartDashesType
??
(
obscureText
?
SmartDashesType
.
disabled
:
SmartDashesType
.
enabled
),
smartQuotesType
=
smartQuotesType
??
(
obscureText
?
SmartQuotesType
.
disabled
:
SmartQuotesType
.
enabled
),
assert
(
enableSuggestions
!=
null
),
assert
(
maxLengthEnforced
!=
null
),
assert
(
maxLengthEnforced
||
maxLengthEnforcement
==
null
,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement'
,
),
assert
(
scrollPadding
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
selectionHeightStyle
!=
null
),
...
...
@@ -550,14 +560,28 @@ class TextField extends StatefulWidget {
/// Whitespace characters (e.g. newline, space, tab) are included in the
/// character count.
///
/// If [maxLengthEnforcement] is [MaxLengthEnforcement.none], then more than
/// [maxLength] characters may be entered, but the error counter and divider
/// will switch to the [decoration]'s [InputDecoration.errorStyle] when the
/// limit is exceeded.
/// If [maxLengthEnforced] is set to false or [maxLengthEnforcement] is
/// [MaxLengthEnforcement.none], then more than [maxLength]
/// characters may be entered, but the error counter and divider will switch
/// to the [decoration]'s [InputDecoration.errorStyle] when the limit is
/// exceeded.
///
/// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength}
final
int
?
maxLength
;
/// If [maxLength] is set, [maxLengthEnforced] indicates whether or not to
/// enforce the limit, or merely provide a character counter and warning when
/// [maxLength] is exceeded.
///
/// If true, prevents the field from allowing more than [maxLength]
/// characters.
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
,
)
final
bool
maxLengthEnforced
;
/// Determines how the [maxLength] limit should be enforced.
///
/// {@macro flutter.services.textFormatter.effectiveMaxLengthEnforcement}
...
...
@@ -789,6 +813,7 @@ class TextField extends StatefulWidget {
properties
.
add
(
IntProperty
(
'minLines'
,
minLines
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
bool
>(
'expands'
,
expands
,
defaultValue:
false
));
properties
.
add
(
IntProperty
(
'maxLength'
,
maxLength
,
defaultValue:
null
));
properties
.
add
(
FlagProperty
(
'maxLengthEnforced'
,
value:
maxLengthEnforced
,
defaultValue:
true
,
ifFalse:
'maxLength not enforced'
));
properties
.
add
(
EnumProperty
<
MaxLengthEnforcement
>(
'maxLengthEnforcement'
,
maxLengthEnforcement
,
defaultValue:
null
));
properties
.
add
(
EnumProperty
<
TextInputAction
>(
'textInputAction'
,
textInputAction
,
defaultValue:
null
));
properties
.
add
(
EnumProperty
<
TextCapitalization
>(
'textCapitalization'
,
textCapitalization
,
defaultValue:
TextCapitalization
.
none
));
...
...
@@ -1124,7 +1149,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
final
FocusNode
focusNode
=
_effectiveFocusNode
;
final
List
<
TextInputFormatter
>
formatters
=
<
TextInputFormatter
>[
...?
widget
.
inputFormatters
,
if
(
widget
.
maxLength
!=
null
)
if
(
widget
.
maxLength
!=
null
&&
widget
.
maxLengthEnforced
)
LengthLimitingTextInputFormatter
(
widget
.
maxLength
,
maxLengthEnforcement:
_effectiveMaxLengthEnforcement
,
...
...
@@ -1304,7 +1329,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
);
final
int
?
semanticsMaxValueLength
;
if
(
_effectiveMaxLengthEnforcement
!=
MaxLengthEnforcement
.
none
&&
if
(
widget
.
maxLengthEnforced
&&
_effectiveMaxLengthEnforcement
!=
MaxLengthEnforcement
.
none
&&
widget
.
maxLength
!=
null
&&
widget
.
maxLength
!
>
0
)
{
semanticsMaxValueLength
=
widget
.
maxLength
;
...
...
packages/flutter/lib/src/material/text_form_field.dart
View file @
06fb863a
...
...
@@ -118,6 +118,12 @@ class TextFormField extends FormField<String> {
SmartDashesType
?
smartDashesType
,
SmartQuotesType
?
smartQuotesType
,
bool
enableSuggestions
=
true
,
@Deprecated
(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
,
)
bool
maxLengthEnforced
=
true
,
MaxLengthEnforcement
?
maxLengthEnforcement
,
int
?
maxLines
=
1
,
int
?
minLines
,
...
...
@@ -154,6 +160,11 @@ class TextFormField extends FormField<String> {
assert
(
obscureText
!=
null
),
assert
(
autocorrect
!=
null
),
assert
(
enableSuggestions
!=
null
),
assert
(
maxLengthEnforced
!=
null
),
assert
(
maxLengthEnforced
||
maxLengthEnforcement
==
null
,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement'
,
),
assert
(
scrollPadding
!=
null
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
minLines
==
null
||
minLines
>
0
),
...
...
@@ -212,6 +223,7 @@ class TextFormField extends FormField<String> {
smartDashesType:
smartDashesType
??
(
obscureText
?
SmartDashesType
.
disabled
:
SmartDashesType
.
enabled
),
smartQuotesType:
smartQuotesType
??
(
obscureText
?
SmartQuotesType
.
disabled
:
SmartQuotesType
.
enabled
),
enableSuggestions:
enableSuggestions
,
maxLengthEnforced:
maxLengthEnforced
,
maxLengthEnforcement:
maxLengthEnforcement
,
maxLines:
maxLines
,
minLines:
minLines
,
...
...
packages/flutter/test/material/text_field_test.dart
View file @
06fb863a
...
...
@@ -4290,7 +4290,7 @@ void main() {
expect
(
textController
.
text
,
'#一#二#三#四#五'
);
});
testWidgets
(
"maxLength isn't enforced when maxLengthEnforce
ment.non
e."
,
(
WidgetTester
tester
)
async
{
testWidgets
(
"maxLength isn't enforced when maxLengthEnforce
d is fals
e."
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
textController
=
TextEditingController
();
await
tester
.
pumpWidget
(
boilerplate
(
...
...
@@ -4305,7 +4305,7 @@ void main() {
expect
(
textController
.
text
,
'0123456789101112'
);
});
testWidgets
(
'maxLength shows warning when maxLengthEnforce
ment.non
e.'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'maxLength shows warning when maxLengthEnforce
d is fals
e.'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
textController
=
TextEditingController
();
const
TextStyle
testStyle
=
TextStyle
(
color:
Colors
.
deepPurpleAccent
);
...
...
@@ -4335,7 +4335,7 @@ void main() {
expect
(
counterTextWidget
.
style
!.
color
,
isNot
(
equals
(
Colors
.
deepPurpleAccent
)));
});
testWidgets
(
'maxLength shows warning when maxLengthEnforce
ment.non
e with surrogate pairs.'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'maxLength shows warning when maxLengthEnforce
d is fals
e with surrogate pairs.'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
textController
=
TextEditingController
();
const
TextStyle
testStyle
=
TextStyle
(
color:
Colors
.
deepPurpleAccent
);
...
...
@@ -4365,7 +4365,7 @@ void main() {
expect
(
counterTextWidget
.
style
!.
color
,
isNot
(
equals
(
Colors
.
deepPurpleAccent
)));
});
testWidgets
(
'maxLength shows warning when maxLengthEnforce
ment.non
e with grapheme clusters.'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'maxLength shows warning when maxLengthEnforce
d is fals
e with grapheme clusters.'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
textController
=
TextEditingController
();
const
TextStyle
testStyle
=
TextStyle
(
color:
Colors
.
deepPurpleAccent
);
...
...
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