Skip to content

Commit 315285d

Browse files
committed
Merge branch 'master' into split_packages
# Conflicts: # README.md # lib/flutter_form_builder.dart # lib/localization/form_builder_localizations.dart # packages/flutter_form_builder/CHANGELOG.md # packages/flutter_form_builder/pubspec.yaml
2 parents de75d60 + 940dfa8 commit 315285d

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

packages/flutter_form_builder/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
## [7.0.0-alpha.0] - 16-May-2021
1616
* Split up packages - removed fields and validation from core
1717

18+
## [6.2.0] - 21-Oct-2021
19+
* Fixed `didChange` unable to handle null value in `FormBuilderTextField`
20+
21+
**BREAKING CHANGE**
22+
* Added new attribute - `autoFocusOnValidationFailure` (default: `false`) - to FormBuilder to set whether should scroll to first error if validation fails
23+
1824
## [6.1.0] - 01-Sep-2021
1925
* When form validation fails, automatically scroll to first error
2026
* New way to programmatically induce custom errors by calling `GlobalKey<FormBuilderState>.invalidateField()` or `GlobalKey<FormBuilderFieldState>.invalidate()`

packages/flutter_form_builder/lib/src/fields/form_builder_date_range_picker.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class FormBuilderDateRangePicker extends FormBuilderField<DateTimeRange> {
183183
try {
184184
return format.format(date);
185185
} catch (e) {
186-
// print('Error formatting date: $e');
186+
// Ignore exception
187187
}
188188
return '';
189189
}
@@ -266,8 +266,8 @@ class FormBuilderDateRangePickerState
266266
}
267267

268268
@override
269-
void didChange(DateTimeRange? value) {
270-
super.didChange(value);
269+
void didChange(DateTimeRange? val) {
270+
super.didChange(val);
271271
_setTextFieldString();
272272
}
273273

packages/flutter_form_builder/lib/src/fields/form_builder_text_field.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class _FormBuilderTextFieldState
465465
super.didChange(value);
466466

467467
if (_effectiveController!.text != value) {
468-
_effectiveController!.text = value!;
468+
_effectiveController!.text = value ?? '';
469469
}
470470
}
471471

packages/flutter_form_builder/lib/src/form_builder.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class FormBuilder extends StatefulWidget {
5858
/// and their enabled state will be ignored.
5959
final bool enabled;
6060

61+
/// Whether the form should auto focus on the first field that fails validation.
62+
final bool autoFocusOnValidationFailure;
63+
6164
/// Creates a container for form fields.
6265
///
6366
/// The [child] argument must not be null.
@@ -70,6 +73,7 @@ class FormBuilder extends StatefulWidget {
7073
this.initialValue = const <String, dynamic>{},
7174
this.skipDisabled = false,
7275
this.enabled = true,
76+
this.autoFocusOnValidationFailure = false,
7377
}) : super(key: key);
7478

7579
static FormBuilderState? of(BuildContext context) =>
@@ -152,7 +156,7 @@ class FormBuilderState extends State<FormBuilder> {
152156

153157
bool validate() {
154158
final hasError = !_formKey.currentState!.validate();
155-
if (hasError) {
159+
if (hasError && widget.autoFocusOnValidationFailure) {
156160
final wrongFields =
157161
fields.values.where((element) => element.hasError).toList();
158162
wrongFields.first.requestFocus();

packages/flutter_form_builder/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 7.0.0-beta.0
44
homepage: https://github.com/danvick/flutter_form_builder
55

66
environment:
7-
sdk: ">=2.12.0 <3.0.0"
7+
sdk: '>=2.12.0 <3.0.0'
88

99
dependencies:
1010
flutter:

packages/form_builder_validators/test/form_builder_validators_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:form_builder_validators/form_builder_validators.dart';
88
Future<void> testValidations(
99
WidgetTester tester, void Function(BuildContext) validations) async {
1010
await tester.pumpWidget(MaterialApp(
11-
localizationsDelegates: [
11+
localizationsDelegates: const [
1212
FormBuilderLocalizations.delegate,
1313
GlobalMaterialLocalizations.delegate,
1414
GlobalWidgetsLocalizations.delegate,
@@ -18,7 +18,7 @@ Future<void> testValidations(
1818
// Exercise validations using the provided context
1919
validations(context);
2020
// The builder function must return a widget.
21-
return Placeholder();
21+
return const Placeholder();
2222
},
2323
),
2424
));

0 commit comments

Comments
 (0)