Skip to content

Commit 5d29dad

Browse files
committed
fix: rename fields for custom error to conform with Flutter form naming
1 parent 46376f4 commit 5d29dad

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

lib/src/form_builder_field.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class FormBuilderField<T> extends FormField<T?> {
8383

8484
class FormBuilderFieldState<F extends FormBuilderField<T?>, T>
8585
extends FormFieldState<T?> {
86-
String? _customError;
86+
String? _customErrorText;
8787

8888
@override
8989
F get widget => super.widget as F;
@@ -176,9 +176,7 @@ class FormBuilderFieldState<F extends FormBuilderField<T?>, T>
176176

177177
@override
178178
bool validate() {
179-
setState(() {
180-
_customError = null;
181-
});
179+
setState(() => _customErrorText = null);
182180
return super.validate() && widget.decoration.errorText == null;
183181
}
184182

@@ -187,15 +185,13 @@ class FormBuilderFieldState<F extends FormBuilderField<T?>, T>
187185
Scrollable.ensureVisible(context);
188186
}
189187

190-
void invalidateField(String reason) {
188+
void invalidate(String reason) {
189+
setState(() => _customErrorText = reason);
191190
requestFocus();
192-
setState(() {
193-
_customError = reason;
194-
});
195191
}
196192

197193
// FIXME: This could be a getter instead of a classic function
198194
InputDecoration decoration() => widget.decoration.copyWith(
199-
errorText: widget.decoration.errorText ?? errorText ?? _customError,
195+
errorText: widget.decoration.errorText ?? errorText ?? _customErrorText,
200196
);
201197
}

lib/src/utils/extension.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import 'package:flutter/widgets.dart';
22
import 'package:flutter_form_builder/flutter_form_builder.dart';
33

44
extension FormKey on GlobalKey<FormBuilderState> {
5-
void invalidateField({
6-
required String name,
7-
String? reason,
8-
}) =>
9-
currentState?.fields[name]?.invalidateField(reason ?? '');
5+
void invalidateField({required String name, String? errorText}) =>
6+
currentState?.fields[name]?.invalidate(errorText ?? '');
107

11-
void invalidateFirstField({required String reason}) =>
12-
currentState?.fields.values.first.invalidateField(reason);
13-
}
8+
void invalidateFirstField({required String errorText}) =>
9+
currentState?.fields.values.first.invalidate(errorText);
10+
}

0 commit comments

Comments
 (0)