Unverified Commit 7fdd9218 authored by Pedro Massango's avatar Pedro Massango Committed by GitHub

Proposal: deprecate autovalidate parameter of the Form, FormField and TextFormField widget (#61648)

parent 4fde217d
...@@ -95,7 +95,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> { ...@@ -95,7 +95,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
)); ));
} }
bool _autovalidate = false; AutovalidateMode _autovalidateMode = AutovalidateMode.disabled;
bool _formWasEdited = false; bool _formWasEdited = false;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
...@@ -104,7 +104,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> { ...@@ -104,7 +104,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
void _handleSubmitted() { void _handleSubmitted() {
final FormState form = _formKey.currentState; final FormState form = _formKey.currentState;
if (!form.validate()) { 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.'); showInSnackBar('Please fix the errors in red before submitting.');
} else { } else {
form.save(); form.save();
...@@ -180,7 +180,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> { ...@@ -180,7 +180,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
bottom: false, bottom: false,
child: Form( child: Form(
key: _formKey, key: _formKey,
autovalidate: _autovalidate, autovalidateMode: _autovalidateMode,
onWillPop: _warnUserAboutInvalidData, onWillPop: _warnUserAboutInvalidData,
child: Scrollbar( child: Scrollbar(
child: SingleChildScrollView( child: SingleChildScrollView(
......
...@@ -1468,6 +1468,11 @@ class DropdownButtonFormField<T> extends FormField<T> { ...@@ -1468,6 +1468,11 @@ class DropdownButtonFormField<T> extends FormField<T> {
InputDecoration decoration, InputDecoration decoration,
FormFieldSetter<T> onSaved, FormFieldSetter<T> onSaved,
FormFieldValidator<T> validator, FormFieldValidator<T> 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, bool autovalidate = false,
AutovalidateMode autovalidateMode, AutovalidateMode autovalidateMode,
}) : assert(items == null || items.isEmpty || value == null || }) : assert(items == null || items.isEmpty || value == null ||
......
...@@ -88,7 +88,7 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType; ...@@ -88,7 +88,7 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType;
/// }, /// },
/// child: FocusTraversalGroup( /// child: FocusTraversalGroup(
/// child: Form( /// child: Form(
/// autovalidate: true, /// autovalidateMode: AutovalidateMode.always,
/// onChanged: () { /// onChanged: () {
/// Form.of(primaryFocus.context).save(); /// Form.of(primaryFocus.context).save();
/// }, /// },
...@@ -158,6 +158,11 @@ class TextFormField extends FormField<String> { ...@@ -158,6 +158,11 @@ class TextFormField extends FormField<String> {
SmartDashesType smartDashesType, SmartDashesType smartDashesType,
SmartQuotesType smartQuotesType, SmartQuotesType smartQuotesType,
bool enableSuggestions = true, 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 autovalidate = false,
bool maxLengthEnforced = true, bool maxLengthEnforced = true,
int maxLines = 1, int maxLines = 1,
......
...@@ -78,7 +78,12 @@ class Form extends StatefulWidget { ...@@ -78,7 +78,12 @@ class Form extends StatefulWidget {
const Form({ const Form({
Key key, Key key,
@required this.child, @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.onWillPop,
this.onChanged, this.onChanged,
AutovalidateMode autovalidateMode, AutovalidateMode autovalidateMode,
...@@ -114,11 +119,6 @@ class Form extends StatefulWidget { ...@@ -114,11 +119,6 @@ class Form extends StatefulWidget {
/// {@macro flutter.widgets.child} /// {@macro flutter.widgets.child}
final Widget 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] /// Enables the form to veto attempts by the user to dismiss the [ModalRoute]
/// that contains the form. /// that contains the form.
/// ///
...@@ -319,7 +319,12 @@ class FormField<T> extends StatefulWidget { ...@@ -319,7 +319,12 @@ class FormField<T> extends StatefulWidget {
this.onSaved, this.onSaved,
this.validator, this.validator,
this.initialValue, 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, this.enabled = true,
AutovalidateMode autovalidateMode, AutovalidateMode autovalidateMode,
}) : assert(builder != null), }) : assert(builder != null),
...@@ -360,12 +365,6 @@ class FormField<T> extends StatefulWidget { ...@@ -360,12 +365,6 @@ class FormField<T> extends StatefulWidget {
/// An optional value to initialize the form field to, or null otherwise. /// An optional value to initialize the form field to, or null otherwise.
final T initialValue; 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. /// Whether the form is able to receive user input.
/// ///
/// Defaults to true. If [autovalidateMode] is not [AutovalidateMode.disabled], /// Defaults to true. If [autovalidateMode] is not [AutovalidateMode.disabled],
...@@ -382,8 +381,8 @@ class FormField<T> extends StatefulWidget { ...@@ -382,8 +381,8 @@ class FormField<T> extends StatefulWidget {
/// will auto validate even without user interaction and /// will auto validate even without user interaction and
/// if [AutovalidateMode.disabled] the auto validation will be disabled. /// if [AutovalidateMode.disabled] the auto validation will be disabled.
/// ///
/// Defaults to [AutovalidateMode.disabled] if [autovalidate] is false which /// Defaults to [AutovalidateMode.disabled] if `autovalidate` is false which
/// means no auto validation will occur. If [autovalidate] is true then this /// means no auto validation will occur. If `autovalidate` is true then this
/// is set to [AutovalidateMode.always] for backward compatibility. /// is set to [AutovalidateMode.always] for backward compatibility.
/// {@endtemplate} /// {@endtemplate}
final AutovalidateMode autovalidateMode; final AutovalidateMode autovalidateMode;
......
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