Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ae4885

Browse files
authored
Remove deprecated CupertinoTextField, TextField, TextFormField maxLengthEnforced (#98539)
1 parent c15ec6a commit 5ae4885

File tree

4 files changed

+24
-97
lines changed

4 files changed

+24
-97
lines changed

packages/flutter/lib/src/cupertino/text_field.dart

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ class CupertinoTextField extends StatefulWidget {
194194
/// must not be null.
195195
///
196196
/// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior],
197-
/// [expands], [maxLengthEnforced], [obscureText], [prefixMode], [readOnly],
198-
/// [scrollPadding], [suffixMode], [textAlign], [selectionHeightStyle],
199-
/// [selectionWidthStyle], [enableSuggestions], and [enableIMEPersonalizedLearning]
200-
/// properties must not be null.
197+
/// [expands], [obscureText], [prefixMode], [readOnly], [scrollPadding],
198+
/// [suffixMode], [textAlign], [selectionHeightStyle], [selectionWidthStyle],
199+
/// [enableSuggestions], and [enableIMEPersonalizedLearning] properties must
200+
/// not be null.
201201
///
202202
/// See also:
203203
///
@@ -244,12 +244,6 @@ class CupertinoTextField extends StatefulWidget {
244244
this.minLines,
245245
this.expands = false,
246246
this.maxLength,
247-
@Deprecated(
248-
'Use maxLengthEnforcement parameter which provides more specific '
249-
'behavior related to the maxLength limit. '
250-
'This feature was deprecated after v1.25.0-5.0.pre.',
251-
)
252-
this.maxLengthEnforced = true,
253247
this.maxLengthEnforcement,
254248
this.onChanged,
255249
this.onEditingComplete,
@@ -284,11 +278,6 @@ class CupertinoTextField extends StatefulWidget {
284278
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
285279
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
286280
assert(enableSuggestions != null),
287-
assert(maxLengthEnforced != null),
288-
assert(
289-
maxLengthEnforced || maxLengthEnforcement == null,
290-
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
291-
),
292281
assert(scrollPadding != null),
293282
assert(dragStartBehavior != null),
294283
assert(selectionHeightStyle != null),
@@ -370,9 +359,9 @@ class CupertinoTextField extends StatefulWidget {
370359
/// must not be null.
371360
///
372361
/// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior],
373-
/// [expands], [maxLengthEnforced], [obscureText], [prefixMode], [readOnly],
374-
/// [scrollPadding], [suffixMode], [textAlign], [selectionHeightStyle],
375-
/// [selectionWidthStyle], and [enableSuggestions] properties must not be null.
362+
/// [expands], [obscureText], [prefixMode], [readOnly], [scrollPadding],
363+
/// [suffixMode], [textAlign], [selectionHeightStyle], [selectionWidthStyle],
364+
/// and [enableSuggestions] properties must not be null.
376365
///
377366
/// See also:
378367
///
@@ -416,12 +405,6 @@ class CupertinoTextField extends StatefulWidget {
416405
this.minLines,
417406
this.expands = false,
418407
this.maxLength,
419-
@Deprecated(
420-
'Use maxLengthEnforcement parameter which provides more specific '
421-
'behavior related to the maxLength limit. '
422-
'This feature was deprecated after v1.25.0-5.0.pre.',
423-
)
424-
this.maxLengthEnforced = true,
425408
this.maxLengthEnforcement,
426409
this.onChanged,
427410
this.onEditingComplete,
@@ -456,11 +439,6 @@ class CupertinoTextField extends StatefulWidget {
456439
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
457440
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
458441
assert(enableSuggestions != null),
459-
assert(maxLengthEnforced != null),
460-
assert(
461-
maxLengthEnforced || maxLengthEnforcement == null,
462-
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
463-
),
464442
assert(scrollPadding != null),
465443
assert(dragStartBehavior != null),
466444
assert(selectionHeightStyle != null),
@@ -688,18 +666,6 @@ class CupertinoTextField extends StatefulWidget {
688666
/// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength}
689667
final int? maxLength;
690668

691-
/// If [maxLength] is set, [maxLengthEnforced] indicates whether or not to
692-
/// enforce the limit.
693-
///
694-
/// If true, prevents the field from allowing more than [maxLength]
695-
/// characters.
696-
@Deprecated(
697-
'Use maxLengthEnforcement parameter which provides more specific '
698-
'behavior related to the maxLength limit. '
699-
'This feature was deprecated after v1.25.0-5.0.pre.',
700-
)
701-
final bool maxLengthEnforced;
702-
703669
/// Determines how the [maxLength] limit should be enforced.
704670
///
705671
/// If [MaxLengthEnforcement.none] is set, additional input beyond [maxLength]
@@ -838,7 +804,6 @@ class CupertinoTextField extends StatefulWidget {
838804
properties.add(IntProperty('minLines', minLines, defaultValue: null));
839805
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
840806
properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
841-
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced'));
842807
properties.add(EnumProperty<MaxLengthEnforcement>('maxLengthEnforcement', maxLengthEnforcement, defaultValue: null));
843808
properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0));
844809
properties.add(DoubleProperty('cursorHeight', cursorHeight, defaultValue: null));
@@ -1192,7 +1157,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
11921157
final Offset cursorOffset = Offset(_iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio, 0);
11931158
final List<TextInputFormatter> formatters = <TextInputFormatter>[
11941159
...?widget.inputFormatters,
1195-
if (widget.maxLength != null && widget.maxLengthEnforced)
1160+
if (widget.maxLength != null)
11961161
LengthLimitingTextInputFormatter(
11971162
widget.maxLength,
11981163
maxLengthEnforcement: _effectiveMaxLengthEnforcement,

packages/flutter/lib/src/material/text_field.dart

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ class TextField extends StatefulWidget {
251251
/// which is evaluated after the supplied [inputFormatters], if any.
252252
/// The [maxLength] value must be either null or greater than zero.
253253
///
254-
/// If [maxLengthEnforced] is set to false, then more than [maxLength]
255-
/// characters may be entered, and the error counter and divider will
256-
/// switch to the [decoration].errorStyle when the limit is exceeded.
254+
/// If [maxLengthEnforcement] is set to [MaxLengthEnforcement.none], then more
255+
/// than [maxLength] characters may be entered, and the error counter and
256+
/// divider will switch to the [decoration].errorStyle when the limit is
257+
/// exceeded.
257258
///
258259
/// The text cursor is not shown if [showCursor] is false or if [showCursor]
259260
/// is null (the default) and [readOnly] is true.
@@ -264,8 +265,8 @@ class TextField extends StatefulWidget {
264265
/// must not be null.
265266
///
266267
/// The [textAlign], [autofocus], [obscureText], [readOnly], [autocorrect],
267-
/// [maxLengthEnforced], [scrollPadding], [maxLines], [maxLength],
268-
/// [selectionHeightStyle], [selectionWidthStyle], [enableSuggestions], and
268+
/// [scrollPadding], [maxLines], [maxLength], [selectionHeightStyle],
269+
/// [selectionWidthStyle], [enableSuggestions], and
269270
/// [enableIMEPersonalizedLearning] arguments must not be null.
270271
///
271272
/// See also:
@@ -299,12 +300,6 @@ class TextField extends StatefulWidget {
299300
this.minLines,
300301
this.expands = false,
301302
this.maxLength,
302-
@Deprecated(
303-
'Use maxLengthEnforcement parameter which provides more specific '
304-
'behavior related to the maxLength limit. '
305-
'This feature was deprecated after v1.25.0-5.0.pre.',
306-
)
307-
this.maxLengthEnforced = true,
308303
this.maxLengthEnforcement,
309304
this.onChanged,
310305
this.onEditingComplete,
@@ -342,11 +337,6 @@ class TextField extends StatefulWidget {
342337
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
343338
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
344339
assert(enableSuggestions != null),
345-
assert(maxLengthEnforced != null),
346-
assert(
347-
maxLengthEnforced || maxLengthEnforcement == null,
348-
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
349-
),
350340
assert(scrollPadding != null),
351341
assert(dragStartBehavior != null),
352342
assert(selectionHeightStyle != null),
@@ -560,28 +550,14 @@ class TextField extends StatefulWidget {
560550
/// Whitespace characters (e.g. newline, space, tab) are included in the
561551
/// character count.
562552
///
563-
/// If [maxLengthEnforced] is set to false or [maxLengthEnforcement] is
564-
/// [MaxLengthEnforcement.none], then more than [maxLength]
565-
/// characters may be entered, but the error counter and divider will switch
566-
/// to the [decoration]'s [InputDecoration.errorStyle] when the limit is
567-
/// exceeded.
553+
/// If [maxLengthEnforcement] is [MaxLengthEnforcement.none], then more than
554+
/// [maxLength] characters may be entered, but the error counter and divider
555+
/// will switch to the [decoration]'s [InputDecoration.errorStyle] when the
556+
/// limit is exceeded.
568557
///
569558
/// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength}
570559
final int? maxLength;
571560

572-
/// If [maxLength] is set, [maxLengthEnforced] indicates whether or not to
573-
/// enforce the limit, or merely provide a character counter and warning when
574-
/// [maxLength] is exceeded.
575-
///
576-
/// If true, prevents the field from allowing more than [maxLength]
577-
/// characters.
578-
@Deprecated(
579-
'Use maxLengthEnforcement parameter which provides more specific '
580-
'behavior related to the maxLength limit. '
581-
'This feature was deprecated after v1.25.0-5.0.pre.',
582-
)
583-
final bool maxLengthEnforced;
584-
585561
/// Determines how the [maxLength] limit should be enforced.
586562
///
587563
/// {@macro flutter.services.textFormatter.effectiveMaxLengthEnforcement}
@@ -813,7 +789,6 @@ class TextField extends StatefulWidget {
813789
properties.add(IntProperty('minLines', minLines, defaultValue: null));
814790
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
815791
properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
816-
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, defaultValue: true, ifFalse: 'maxLength not enforced'));
817792
properties.add(EnumProperty<MaxLengthEnforcement>('maxLengthEnforcement', maxLengthEnforcement, defaultValue: null));
818793
properties.add(EnumProperty<TextInputAction>('textInputAction', textInputAction, defaultValue: null));
819794
properties.add(EnumProperty<TextCapitalization>('textCapitalization', textCapitalization, defaultValue: TextCapitalization.none));
@@ -1149,7 +1124,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
11491124
final FocusNode focusNode = _effectiveFocusNode;
11501125
final List<TextInputFormatter> formatters = <TextInputFormatter>[
11511126
...?widget.inputFormatters,
1152-
if (widget.maxLength != null && widget.maxLengthEnforced)
1127+
if (widget.maxLength != null)
11531128
LengthLimitingTextInputFormatter(
11541129
widget.maxLength,
11551130
maxLengthEnforcement: _effectiveMaxLengthEnforcement,
@@ -1329,8 +1304,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
13291304
);
13301305

13311306
final int? semanticsMaxValueLength;
1332-
if (widget.maxLengthEnforced &&
1333-
_effectiveMaxLengthEnforcement != MaxLengthEnforcement.none &&
1307+
if (_effectiveMaxLengthEnforcement != MaxLengthEnforcement.none &&
13341308
widget.maxLength != null &&
13351309
widget.maxLength! > 0) {
13361310
semanticsMaxValueLength = widget.maxLength;

packages/flutter/lib/src/material/text_form_field.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ class TextFormField extends FormField<String> {
118118
SmartDashesType? smartDashesType,
119119
SmartQuotesType? smartQuotesType,
120120
bool enableSuggestions = true,
121-
@Deprecated(
122-
'Use maxLengthEnforcement parameter which provides more specific '
123-
'behavior related to the maxLength limit. '
124-
'This feature was deprecated after v1.25.0-5.0.pre.',
125-
)
126-
bool maxLengthEnforced = true,
127121
MaxLengthEnforcement? maxLengthEnforcement,
128122
int? maxLines = 1,
129123
int? minLines,
@@ -160,11 +154,6 @@ class TextFormField extends FormField<String> {
160154
assert(obscureText != null),
161155
assert(autocorrect != null),
162156
assert(enableSuggestions != null),
163-
assert(maxLengthEnforced != null),
164-
assert(
165-
maxLengthEnforced || maxLengthEnforcement == null,
166-
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
167-
),
168157
assert(scrollPadding != null),
169158
assert(maxLines == null || maxLines > 0),
170159
assert(minLines == null || minLines > 0),
@@ -223,7 +212,6 @@ class TextFormField extends FormField<String> {
223212
smartDashesType: smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
224213
smartQuotesType: smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
225214
enableSuggestions: enableSuggestions,
226-
maxLengthEnforced: maxLengthEnforced,
227215
maxLengthEnforcement: maxLengthEnforcement,
228216
maxLines: maxLines,
229217
minLines: minLines,

packages/flutter/test/material/text_field_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,7 +4290,7 @@ void main() {
42904290
expect(textController.text, '#一#二#三#四#五');
42914291
});
42924292

4293-
testWidgets("maxLength isn't enforced when maxLengthEnforced is false.", (WidgetTester tester) async {
4293+
testWidgets("maxLength isn't enforced when maxLengthEnforcement.none.", (WidgetTester tester) async {
42944294
final TextEditingController textController = TextEditingController();
42954295

42964296
await tester.pumpWidget(boilerplate(
@@ -4305,7 +4305,7 @@ void main() {
43054305
expect(textController.text, '0123456789101112');
43064306
});
43074307

4308-
testWidgets('maxLength shows warning when maxLengthEnforced is false.', (WidgetTester tester) async {
4308+
testWidgets('maxLength shows warning when maxLengthEnforcement.none.', (WidgetTester tester) async {
43094309
final TextEditingController textController = TextEditingController();
43104310
const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent);
43114311

@@ -4335,7 +4335,7 @@ void main() {
43354335
expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent)));
43364336
});
43374337

4338-
testWidgets('maxLength shows warning when maxLengthEnforced is false with surrogate pairs.', (WidgetTester tester) async {
4338+
testWidgets('maxLength shows warning when maxLengthEnforcement.none with surrogate pairs.', (WidgetTester tester) async {
43394339
final TextEditingController textController = TextEditingController();
43404340
const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent);
43414341

@@ -4365,7 +4365,7 @@ void main() {
43654365
expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent)));
43664366
});
43674367

4368-
testWidgets('maxLength shows warning when maxLengthEnforced is false with grapheme clusters.', (WidgetTester tester) async {
4368+
testWidgets('maxLength shows warning when maxLengthEnforcement.none with grapheme clusters.', (WidgetTester tester) async {
43694369
final TextEditingController textController = TextEditingController();
43704370
const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent);
43714371

0 commit comments

Comments
 (0)