diff --git a/dev/integration_tests/flutter_gallery/lib/demo/material/text_form_field_demo.dart b/dev/integration_tests/flutter_gallery/lib/demo/material/text_form_field_demo.dart index 1dbeccaa4a..6fb5b260c4 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/material/text_form_field_demo.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/material/text_form_field_demo.dart @@ -95,7 +95,7 @@ class TextFormFieldDemoState extends State { )); } - bool _autovalidate = false; + AutovalidateMode _autovalidateMode = AutovalidateMode.disabled; bool _formWasEdited = false; final GlobalKey _formKey = GlobalKey(); @@ -104,7 +104,7 @@ class TextFormFieldDemoState extends State { void _handleSubmitted() { final FormState form = _formKey.currentState; if (!form.validate()) { - _autovalidate = true; // Start validating on every change. + _autovalidateMode = AutovalidateMode.always; // Start validating on every change. showInSnackBar('Please fix the errors in red before submitting.'); } else { form.save(); @@ -180,7 +180,7 @@ class TextFormFieldDemoState extends State { bottom: false, child: Form( key: _formKey, - autovalidate: _autovalidate, + autovalidateMode: _autovalidateMode, onWillPop: _warnUserAboutInvalidData, child: Scrollbar( child: SingleChildScrollView( diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 128dec0d1b..600c408140 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -1468,6 +1468,11 @@ class DropdownButtonFormField extends FormField { InputDecoration decoration, FormFieldSetter onSaved, FormFieldValidator validator, + @Deprecated( + 'Use autoValidateMode parameter which provide more specific ' + 'behaviour related to auto validation. ' + 'This feature was deprecated after v1.19.0.' + ) bool autovalidate = false, AutovalidateMode autovalidateMode, }) : assert(items == null || items.isEmpty || value == null || diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index 128b4d1602..fabfdca9f0 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -88,7 +88,7 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType; /// }, /// child: FocusTraversalGroup( /// child: Form( -/// autovalidate: true, +/// autovalidateMode: AutovalidateMode.always, /// onChanged: () { /// Form.of(primaryFocus.context).save(); /// }, @@ -158,6 +158,11 @@ class TextFormField extends FormField { SmartDashesType smartDashesType, SmartQuotesType smartQuotesType, bool enableSuggestions = true, + @Deprecated( + 'Use autoValidateMode parameter which provide more specific ' + 'behaviour related to auto validation. ' + 'This feature was deprecated after v1.19.0.' + ) bool autovalidate = false, bool maxLengthEnforced = true, int maxLines = 1, diff --git a/packages/flutter/lib/src/widgets/form.dart b/packages/flutter/lib/src/widgets/form.dart index 7dbe80addc..9dae622d0b 100644 --- a/packages/flutter/lib/src/widgets/form.dart +++ b/packages/flutter/lib/src/widgets/form.dart @@ -78,7 +78,12 @@ class Form extends StatefulWidget { const Form({ Key key, @required this.child, - this.autovalidate = false, + @Deprecated( + 'Use autoValidateMode parameter which provide more specific ' + 'behaviour related to auto validation. ' + 'This feature was deprecated after v1.19.0.' + ) + bool autovalidate = false, this.onWillPop, this.onChanged, AutovalidateMode autovalidateMode, @@ -114,11 +119,6 @@ class Form extends StatefulWidget { /// {@macro flutter.widgets.child} final Widget child; - /// If true, form fields will validate and update their error text - /// immediately after every change. Otherwise, you must call - /// [FormState.validate] to validate. - final bool autovalidate; - /// Enables the form to veto attempts by the user to dismiss the [ModalRoute] /// that contains the form. /// @@ -319,7 +319,12 @@ class FormField extends StatefulWidget { this.onSaved, this.validator, this.initialValue, - this.autovalidate = false, + @Deprecated( + 'Use autoValidateMode parameter which provide more specific ' + 'behaviour related to auto validation. ' + 'This feature was deprecated after v1.19.0.' + ) + bool autovalidate = false, this.enabled = true, AutovalidateMode autovalidateMode, }) : assert(builder != null), @@ -360,12 +365,6 @@ class FormField extends StatefulWidget { /// An optional value to initialize the form field to, or null otherwise. final T initialValue; - /// If true, this form field will validate and update its error text - /// immediately after every change. Otherwise, you must call - /// [FormFieldState.validate] to validate. If part of a [Form] that - /// auto-validates, this value will be ignored. - final bool autovalidate; - /// Whether the form is able to receive user input. /// /// Defaults to true. If [autovalidateMode] is not [AutovalidateMode.disabled], @@ -382,8 +381,8 @@ class FormField extends StatefulWidget { /// will auto validate even without user interaction and /// if [AutovalidateMode.disabled] the auto validation will be disabled. /// - /// Defaults to [AutovalidateMode.disabled] if [autovalidate] is false which - /// means no auto validation will occur. If [autovalidate] is true then this + /// Defaults to [AutovalidateMode.disabled] if `autovalidate` is false which + /// means no auto validation will occur. If `autovalidate` is true then this /// is set to [AutovalidateMode.always] for backward compatibility. /// {@endtemplate} final AutovalidateMode autovalidateMode;