Unverified Commit 5ae4885e authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Remove deprecated CupertinoTextField, TextField, TextFormField maxLengthEnforced (#98539)

parent c15ec6a1
...@@ -194,10 +194,10 @@ class CupertinoTextField extends StatefulWidget { ...@@ -194,10 +194,10 @@ class CupertinoTextField extends StatefulWidget {
/// must not be null. /// must not be null.
/// ///
/// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior], /// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior],
/// [expands], [maxLengthEnforced], [obscureText], [prefixMode], [readOnly], /// [expands], [obscureText], [prefixMode], [readOnly], [scrollPadding],
/// [scrollPadding], [suffixMode], [textAlign], [selectionHeightStyle], /// [suffixMode], [textAlign], [selectionHeightStyle], [selectionWidthStyle],
/// [selectionWidthStyle], [enableSuggestions], and [enableIMEPersonalizedLearning] /// [enableSuggestions], and [enableIMEPersonalizedLearning] properties must
/// properties must not be null. /// not be null.
/// ///
/// See also: /// See also:
/// ///
...@@ -244,12 +244,6 @@ class CupertinoTextField extends StatefulWidget { ...@@ -244,12 +244,6 @@ class CupertinoTextField extends StatefulWidget {
this.minLines, this.minLines,
this.expands = false, this.expands = false,
this.maxLength, 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.maxLengthEnforcement,
this.onChanged, this.onChanged,
this.onEditingComplete, this.onEditingComplete,
...@@ -284,11 +278,6 @@ class CupertinoTextField extends StatefulWidget { ...@@ -284,11 +278,6 @@ class CupertinoTextField extends StatefulWidget {
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
assert(enableSuggestions != null), assert(enableSuggestions != null),
assert(maxLengthEnforced != null),
assert(
maxLengthEnforced || maxLengthEnforcement == null,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
),
assert(scrollPadding != null), assert(scrollPadding != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
assert(selectionHeightStyle != null), assert(selectionHeightStyle != null),
...@@ -370,9 +359,9 @@ class CupertinoTextField extends StatefulWidget { ...@@ -370,9 +359,9 @@ class CupertinoTextField extends StatefulWidget {
/// must not be null. /// must not be null.
/// ///
/// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior], /// The [autocorrect], [autofocus], [clearButtonMode], [dragStartBehavior],
/// [expands], [maxLengthEnforced], [obscureText], [prefixMode], [readOnly], /// [expands], [obscureText], [prefixMode], [readOnly], [scrollPadding],
/// [scrollPadding], [suffixMode], [textAlign], [selectionHeightStyle], /// [suffixMode], [textAlign], [selectionHeightStyle], [selectionWidthStyle],
/// [selectionWidthStyle], and [enableSuggestions] properties must not be null. /// and [enableSuggestions] properties must not be null.
/// ///
/// See also: /// See also:
/// ///
...@@ -416,12 +405,6 @@ class CupertinoTextField extends StatefulWidget { ...@@ -416,12 +405,6 @@ class CupertinoTextField extends StatefulWidget {
this.minLines, this.minLines,
this.expands = false, this.expands = false,
this.maxLength, 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.maxLengthEnforcement,
this.onChanged, this.onChanged,
this.onEditingComplete, this.onEditingComplete,
...@@ -456,11 +439,6 @@ class CupertinoTextField extends StatefulWidget { ...@@ -456,11 +439,6 @@ class CupertinoTextField extends StatefulWidget {
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
assert(enableSuggestions != null), assert(enableSuggestions != null),
assert(maxLengthEnforced != null),
assert(
maxLengthEnforced || maxLengthEnforcement == null,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
),
assert(scrollPadding != null), assert(scrollPadding != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
assert(selectionHeightStyle != null), assert(selectionHeightStyle != null),
...@@ -688,18 +666,6 @@ class CupertinoTextField extends StatefulWidget { ...@@ -688,18 +666,6 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength} /// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength}
final int? 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. /// Determines how the [maxLength] limit should be enforced.
/// ///
/// If [MaxLengthEnforcement.none] is set, additional input beyond [maxLength] /// If [MaxLengthEnforcement.none] is set, additional input beyond [maxLength]
...@@ -838,7 +804,6 @@ class CupertinoTextField extends StatefulWidget { ...@@ -838,7 +804,6 @@ class CupertinoTextField extends StatefulWidget {
properties.add(IntProperty('minLines', minLines, defaultValue: null)); properties.add(IntProperty('minLines', minLines, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); 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(EnumProperty<MaxLengthEnforcement>('maxLengthEnforcement', maxLengthEnforcement, defaultValue: null));
properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)); properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0));
properties.add(DoubleProperty('cursorHeight', cursorHeight, defaultValue: null)); properties.add(DoubleProperty('cursorHeight', cursorHeight, defaultValue: null));
...@@ -1192,7 +1157,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio ...@@ -1192,7 +1157,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
final Offset cursorOffset = Offset(_iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio, 0); final Offset cursorOffset = Offset(_iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio, 0);
final List<TextInputFormatter> formatters = <TextInputFormatter>[ final List<TextInputFormatter> formatters = <TextInputFormatter>[
...?widget.inputFormatters, ...?widget.inputFormatters,
if (widget.maxLength != null && widget.maxLengthEnforced) if (widget.maxLength != null)
LengthLimitingTextInputFormatter( LengthLimitingTextInputFormatter(
widget.maxLength, widget.maxLength,
maxLengthEnforcement: _effectiveMaxLengthEnforcement, maxLengthEnforcement: _effectiveMaxLengthEnforcement,
......
...@@ -251,9 +251,10 @@ class TextField extends StatefulWidget { ...@@ -251,9 +251,10 @@ class TextField extends StatefulWidget {
/// which is evaluated after the supplied [inputFormatters], if any. /// which is evaluated after the supplied [inputFormatters], if any.
/// The [maxLength] value must be either null or greater than zero. /// The [maxLength] value must be either null or greater than zero.
/// ///
/// If [maxLengthEnforced] is set to false, then more than [maxLength] /// If [maxLengthEnforcement] is set to [MaxLengthEnforcement.none], then more
/// characters may be entered, and the error counter and divider will /// than [maxLength] characters may be entered, and the error counter and
/// switch to the [decoration].errorStyle when the limit is exceeded. /// 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] /// The text cursor is not shown if [showCursor] is false or if [showCursor]
/// is null (the default) and [readOnly] is true. /// is null (the default) and [readOnly] is true.
...@@ -264,8 +265,8 @@ class TextField extends StatefulWidget { ...@@ -264,8 +265,8 @@ class TextField extends StatefulWidget {
/// must not be null. /// must not be null.
/// ///
/// The [textAlign], [autofocus], [obscureText], [readOnly], [autocorrect], /// The [textAlign], [autofocus], [obscureText], [readOnly], [autocorrect],
/// [maxLengthEnforced], [scrollPadding], [maxLines], [maxLength], /// [scrollPadding], [maxLines], [maxLength], [selectionHeightStyle],
/// [selectionHeightStyle], [selectionWidthStyle], [enableSuggestions], and /// [selectionWidthStyle], [enableSuggestions], and
/// [enableIMEPersonalizedLearning] arguments must not be null. /// [enableIMEPersonalizedLearning] arguments must not be null.
/// ///
/// See also: /// See also:
...@@ -299,12 +300,6 @@ class TextField extends StatefulWidget { ...@@ -299,12 +300,6 @@ class TextField extends StatefulWidget {
this.minLines, this.minLines,
this.expands = false, this.expands = false,
this.maxLength, 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.maxLengthEnforcement,
this.onChanged, this.onChanged,
this.onEditingComplete, this.onEditingComplete,
...@@ -342,11 +337,6 @@ class TextField extends StatefulWidget { ...@@ -342,11 +337,6 @@ class TextField extends StatefulWidget {
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
assert(enableSuggestions != null), assert(enableSuggestions != null),
assert(maxLengthEnforced != null),
assert(
maxLengthEnforced || maxLengthEnforcement == null,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
),
assert(scrollPadding != null), assert(scrollPadding != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
assert(selectionHeightStyle != null), assert(selectionHeightStyle != null),
...@@ -560,28 +550,14 @@ class TextField extends StatefulWidget { ...@@ -560,28 +550,14 @@ class TextField extends StatefulWidget {
/// Whitespace characters (e.g. newline, space, tab) are included in the /// Whitespace characters (e.g. newline, space, tab) are included in the
/// character count. /// character count.
/// ///
/// If [maxLengthEnforced] is set to false or [maxLengthEnforcement] is /// If [maxLengthEnforcement] is [MaxLengthEnforcement.none], then more than
/// [MaxLengthEnforcement.none], then more than [maxLength] /// [maxLength] characters may be entered, but the error counter and divider
/// characters may be entered, but the error counter and divider will switch /// will switch to the [decoration]'s [InputDecoration.errorStyle] when the
/// to the [decoration]'s [InputDecoration.errorStyle] when the limit is /// limit is exceeded.
/// exceeded.
/// ///
/// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength} /// {@macro flutter.services.lengthLimitingTextInputFormatter.maxLength}
final int? 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. /// Determines how the [maxLength] limit should be enforced.
/// ///
/// {@macro flutter.services.textFormatter.effectiveMaxLengthEnforcement} /// {@macro flutter.services.textFormatter.effectiveMaxLengthEnforcement}
...@@ -813,7 +789,6 @@ class TextField extends StatefulWidget { ...@@ -813,7 +789,6 @@ class TextField extends StatefulWidget {
properties.add(IntProperty('minLines', minLines, defaultValue: null)); properties.add(IntProperty('minLines', minLines, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); 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<MaxLengthEnforcement>('maxLengthEnforcement', maxLengthEnforcement, defaultValue: null));
properties.add(EnumProperty<TextInputAction>('textInputAction', textInputAction, defaultValue: null)); properties.add(EnumProperty<TextInputAction>('textInputAction', textInputAction, defaultValue: null));
properties.add(EnumProperty<TextCapitalization>('textCapitalization', textCapitalization, defaultValue: TextCapitalization.none)); properties.add(EnumProperty<TextCapitalization>('textCapitalization', textCapitalization, defaultValue: TextCapitalization.none));
...@@ -1149,7 +1124,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1149,7 +1124,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
final FocusNode focusNode = _effectiveFocusNode; final FocusNode focusNode = _effectiveFocusNode;
final List<TextInputFormatter> formatters = <TextInputFormatter>[ final List<TextInputFormatter> formatters = <TextInputFormatter>[
...?widget.inputFormatters, ...?widget.inputFormatters,
if (widget.maxLength != null && widget.maxLengthEnforced) if (widget.maxLength != null)
LengthLimitingTextInputFormatter( LengthLimitingTextInputFormatter(
widget.maxLength, widget.maxLength,
maxLengthEnforcement: _effectiveMaxLengthEnforcement, maxLengthEnforcement: _effectiveMaxLengthEnforcement,
...@@ -1329,8 +1304,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1329,8 +1304,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
); );
final int? semanticsMaxValueLength; final int? semanticsMaxValueLength;
if (widget.maxLengthEnforced && if (_effectiveMaxLengthEnforcement != MaxLengthEnforcement.none &&
_effectiveMaxLengthEnforcement != MaxLengthEnforcement.none &&
widget.maxLength != null && widget.maxLength != null &&
widget.maxLength! > 0) { widget.maxLength! > 0) {
semanticsMaxValueLength = widget.maxLength; semanticsMaxValueLength = widget.maxLength;
......
...@@ -118,12 +118,6 @@ class TextFormField extends FormField<String> { ...@@ -118,12 +118,6 @@ class TextFormField extends FormField<String> {
SmartDashesType? smartDashesType, SmartDashesType? smartDashesType,
SmartQuotesType? smartQuotesType, SmartQuotesType? smartQuotesType,
bool enableSuggestions = true, 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, MaxLengthEnforcement? maxLengthEnforcement,
int? maxLines = 1, int? maxLines = 1,
int? minLines, int? minLines,
...@@ -160,11 +154,6 @@ class TextFormField extends FormField<String> { ...@@ -160,11 +154,6 @@ class TextFormField extends FormField<String> {
assert(obscureText != null), assert(obscureText != null),
assert(autocorrect != null), assert(autocorrect != null),
assert(enableSuggestions != null), assert(enableSuggestions != null),
assert(maxLengthEnforced != null),
assert(
maxLengthEnforced || maxLengthEnforcement == null,
'maxLengthEnforced is deprecated, use only maxLengthEnforcement',
),
assert(scrollPadding != null), assert(scrollPadding != null),
assert(maxLines == null || maxLines > 0), assert(maxLines == null || maxLines > 0),
assert(minLines == null || minLines > 0), assert(minLines == null || minLines > 0),
...@@ -223,7 +212,6 @@ class TextFormField extends FormField<String> { ...@@ -223,7 +212,6 @@ class TextFormField extends FormField<String> {
smartDashesType: smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), smartDashesType: smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
smartQuotesType: smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), smartQuotesType: smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
enableSuggestions: enableSuggestions, enableSuggestions: enableSuggestions,
maxLengthEnforced: maxLengthEnforced,
maxLengthEnforcement: maxLengthEnforcement, maxLengthEnforcement: maxLengthEnforcement,
maxLines: maxLines, maxLines: maxLines,
minLines: minLines, minLines: minLines,
......
...@@ -4290,7 +4290,7 @@ void main() { ...@@ -4290,7 +4290,7 @@ void main() {
expect(textController.text, '#一#二#三#四#五'); expect(textController.text, '#一#二#三#四#五');
}); });
testWidgets("maxLength isn't enforced when maxLengthEnforced is false.", (WidgetTester tester) async { testWidgets("maxLength isn't enforced when maxLengthEnforcement.none.", (WidgetTester tester) async {
final TextEditingController textController = TextEditingController(); final TextEditingController textController = TextEditingController();
await tester.pumpWidget(boilerplate( await tester.pumpWidget(boilerplate(
...@@ -4305,7 +4305,7 @@ void main() { ...@@ -4305,7 +4305,7 @@ void main() {
expect(textController.text, '0123456789101112'); expect(textController.text, '0123456789101112');
}); });
testWidgets('maxLength shows warning when maxLengthEnforced is false.', (WidgetTester tester) async { testWidgets('maxLength shows warning when maxLengthEnforcement.none.', (WidgetTester tester) async {
final TextEditingController textController = TextEditingController(); final TextEditingController textController = TextEditingController();
const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent); const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent);
...@@ -4335,7 +4335,7 @@ void main() { ...@@ -4335,7 +4335,7 @@ void main() {
expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent))); expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent)));
}); });
testWidgets('maxLength shows warning when maxLengthEnforced is false with surrogate pairs.', (WidgetTester tester) async { testWidgets('maxLength shows warning when maxLengthEnforcement.none with surrogate pairs.', (WidgetTester tester) async {
final TextEditingController textController = TextEditingController(); final TextEditingController textController = TextEditingController();
const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent); const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent);
...@@ -4365,7 +4365,7 @@ void main() { ...@@ -4365,7 +4365,7 @@ void main() {
expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent))); expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent)));
}); });
testWidgets('maxLength shows warning when maxLengthEnforced is false with grapheme clusters.', (WidgetTester tester) async { testWidgets('maxLength shows warning when maxLengthEnforcement.none with grapheme clusters.', (WidgetTester tester) async {
final TextEditingController textController = TextEditingController(); final TextEditingController textController = TextEditingController();
const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent); const TextStyle testStyle = TextStyle(color: Colors.deepPurpleAccent);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment