Unverified Commit 10f62844 authored by Pedro Massango's avatar Pedro Massango Committed by GitHub

Add back the autovalidate class property (#66267)

* Add back autovalidate property

* Add autovalidate property back (include tests)

* Fix typos

* One more test :)
parent d95bff1e
......@@ -77,11 +77,11 @@ class Form extends StatefulWidget {
Key? key,
required this.child,
@Deprecated(
'Use autoValidateMode parameter which provide more specific '
'behaviour related to auto validation. '
'Use autoValidateMode parameter which provides more specific '
'behavior related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
bool autovalidate = false,
this.autovalidate = false,
this.onWillPop,
this.onChanged,
AutovalidateMode? autovalidateMode,
......@@ -92,9 +92,8 @@ class Form extends StatefulWidget {
autovalidate == true && autovalidateMode == null,
'autovalidate and autovalidateMode should not be used together.'
),
autovalidateMode = autovalidate
? AutovalidateMode.always
: (autovalidateMode ?? AutovalidateMode.disabled),
autovalidateMode = autovalidateMode ??
(autovalidate ? AutovalidateMode.always : AutovalidateMode.disabled),
super(key: key);
/// Returns the closest [FormState] which encloses the given context.
......@@ -141,6 +140,15 @@ class Form extends StatefulWidget {
/// {@macro flutter.widgets.form.autovalidateMode}
final AutovalidateMode autovalidateMode;
/// Used to enable/disable form fields auto validation and update their error
/// text.
@Deprecated(
'Use autoValidateMode parameter which provides more specific '
'behavior related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
final bool autovalidate;
@override
FormState createState() => FormState();
}
......@@ -318,11 +326,11 @@ class FormField<T> extends StatefulWidget {
this.validator,
this.initialValue,
@Deprecated(
'Use autoValidateMode parameter which provide more specific '
'behaviour related to auto validation. '
'Use autoValidateMode parameter which provides more specific '
'behavior related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
bool autovalidate = false,
this.autovalidate = false,
this.enabled = true,
AutovalidateMode? autovalidateMode,
}) : assert(builder != null),
......@@ -331,9 +339,8 @@ class FormField<T> extends StatefulWidget {
autovalidate == true && autovalidateMode == null,
'autovalidate and autovalidateMode should not be used together.'
),
autovalidateMode = autovalidate
? AutovalidateMode.always
: (autovalidateMode ?? AutovalidateMode.disabled),
autovalidateMode = autovalidateMode ??
(autovalidate ? AutovalidateMode.always : AutovalidateMode.disabled),
super(key: key);
/// An optional method to call with the final value when the form is saved via
......@@ -385,6 +392,15 @@ class FormField<T> extends StatefulWidget {
/// {@endtemplate}
final AutovalidateMode autovalidateMode;
/// Used to enable/disable auto validation and update their error
/// text.
@Deprecated(
'Use autoValidateMode parameter which provides more specific '
'behavior related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
final bool autovalidate;
@override
FormFieldState<T> createState() => FormFieldState<T>();
}
......
......@@ -886,4 +886,87 @@ void main() {
expect(fieldValue, '123456');
expect(formKey.currentState.validate(), isFalse);
});
testWidgets('FormField.autovalidate parameter is passed into class the property', (WidgetTester tester) async {
String errorText(String value) => '$value/error';
const ObjectKey widgetKey = ObjectKey('key');
Widget builder({@required bool autovalidate}) {
return MaterialApp(
home: MediaQuery(
data: const MediaQueryData(devicePixelRatio: 1.0),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Material(
child: FormField<String>(
key: widgetKey,
initialValue: 'foo',
autovalidate: autovalidate,
builder: (FormFieldState<String> state) {
return Container();
},
validator: errorText,
),
),
),
),
),
);
}
// When autovalidate is true
await tester.pumpWidget(builder(autovalidate: true));
final Finder formFieldFinder = find.byKey(widgetKey);
FormField<String> formField = tester.widget(formFieldFinder);
expect(formField.autovalidate, isTrue);
expect(formField.autovalidateMode, equals(AutovalidateMode.always));
// When autovalidate is false
await tester.pumpWidget(builder(autovalidate: false));
formField = tester.widget(formFieldFinder);
expect(formField.autovalidate, isFalse);
expect(formField.autovalidateMode, equals(AutovalidateMode.disabled));
});
testWidgets('Form.autovalidate parameter is passed into class the property', (WidgetTester tester) async {
const ObjectKey widgetKey = ObjectKey('key');
Widget builder({@required bool autovalidate}) {
return MaterialApp(
home: MediaQuery(
data: const MediaQueryData(devicePixelRatio: 1.0),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Material(
child: Form(
key: widgetKey,
autovalidate: autovalidate,
child: Container(),
),
),
),
),
),
);
}
// When autovalidate is true
await tester.pumpWidget(builder(autovalidate: true));
final Finder formFinder = find.byKey(widgetKey);
Form formWidget = tester.widget(formFinder);
expect(formWidget.autovalidate, isTrue);
expect(formWidget.autovalidateMode, equals(AutovalidateMode.always));
// When autovalidate is false
await tester.pumpWidget(builder(autovalidate: false));
formWidget = tester.widget(formFinder);
expect(formWidget.autovalidate, isFalse);
expect(formWidget.autovalidateMode, equals(AutovalidateMode.disabled));
});
}
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