Skip to content

Commit 7c5e401

Browse files
committed
Code cleanup
1 parent e607547 commit 7c5e401

11 files changed

+105
-70
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [4.0.0-alpha.4] - 04-Jul-2020
2+
* Added static getter for FormBuilderLocalizations delegate
3+
* Fix issue where setting app localization is required for built-in validation to work
4+
15
## [4.0.0-alpha.3] - 01-Jul-2020
26
* Localize validation error texts
37
* Dropped `country_picker` package for `country_code_pickers` in PhoneField which supports localized countries

lib/l10n/messages_all.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ MessageLookupByLibrary _findExact(String localeName) {
4242
/// User programs should call this before using [localeName] for messages.
4343
Future<bool> initializeMessages(String localeName) async {
4444
var availableLocale = Intl.verifiedLocale(
45-
localeName,
46-
(locale) => _deferredLibraries[locale] != null,
47-
onFailure: (_) => null);
45+
localeName, (locale) => _deferredLibraries[locale] != null,
46+
onFailure: (_) => null);
4847
if (availableLocale == null) {
4948
return new Future.value(false);
5049
}
@@ -64,8 +63,8 @@ bool _messagesExistFor(String locale) {
6463
}
6564

6665
MessageLookupByLibrary _findGeneratedMessagesFor(String locale) {
67-
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor,
68-
onFailure: (_) => null);
66+
var actualLocale =
67+
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
6968
if (actualLocale == null) return null;
7069
return _findExact(actualLocale);
7170
}

lib/l10n/messages_en.dart

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,37 @@ class MessageLookup extends MessageLookupByLibrary {
2121

2222
static m0(max) => "Value must be less than or equal to ${max}";
2323

24-
static m1(maxLength) => "Value must have a length less than or equal to ${maxLength}";
24+
static m1(maxLength) =>
25+
"Value must have a length less than or equal to ${maxLength}";
2526

2627
static m2(min) => "Value must be greater than or equal to ${min}.";
2728

28-
static m3(minLength) => "Value must have a length greater than or equal to ${minLength}";
29+
static m3(minLength) =>
30+
"Value must have a length greater than or equal to ${minLength}";
2931

3032
final messages = _notInlinedMessages(_notInlinedMessages);
31-
static _notInlinedMessages(_) => <String, Function> {
32-
"creditCardErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid credit card number."),
33-
"dateStringErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid date string."),
34-
"emailErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid email address."),
35-
"ipErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid IP."),
36-
"maxErrorText" : m0,
37-
"maxLengthErrorText" : m1,
38-
"minErrorText" : m2,
39-
"minLengthErrorText" : m3,
40-
"numericErrorText" : MessageLookupByLibrary.simpleMessage("Value must be numeric."),
41-
"patternErrorText" : MessageLookupByLibrary.simpleMessage("Value does not match pattern."),
42-
"requireTrueErrorText" : MessageLookupByLibrary.simpleMessage("This field must be set to true."),
43-
"requiredErrorText" : MessageLookupByLibrary.simpleMessage("This field cannot be empty."),
44-
"urlErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid URL address.")
45-
};
33+
static _notInlinedMessages(_) => <String, Function>{
34+
"creditCardErrorText": MessageLookupByLibrary.simpleMessage(
35+
"This field requires a valid credit card number."),
36+
"dateStringErrorText": MessageLookupByLibrary.simpleMessage(
37+
"This field requires a valid date string."),
38+
"emailErrorText": MessageLookupByLibrary.simpleMessage(
39+
"This field requires a valid email address."),
40+
"ipErrorText": MessageLookupByLibrary.simpleMessage(
41+
"This field requires a valid IP."),
42+
"maxErrorText": m0,
43+
"maxLengthErrorText": m1,
44+
"minErrorText": m2,
45+
"minLengthErrorText": m3,
46+
"numericErrorText":
47+
MessageLookupByLibrary.simpleMessage("Value must be numeric."),
48+
"patternErrorText": MessageLookupByLibrary.simpleMessage(
49+
"Value does not match pattern."),
50+
"requireTrueErrorText": MessageLookupByLibrary.simpleMessage(
51+
"This field must be set to true."),
52+
"requiredErrorText":
53+
MessageLookupByLibrary.simpleMessage("This field cannot be empty."),
54+
"urlErrorText": MessageLookupByLibrary.simpleMessage(
55+
"This field requires a valid URL address.")
56+
};
4657
}

lib/l10n/messages_es.dart

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,37 @@ class MessageLookup extends MessageLookupByLibrary {
2121

2222
static m0(max) => "Value must be less than or equal to ${max}";
2323

24-
static m1(maxLength) => "Value must have a length less than or equal to ${maxLength}";
24+
static m1(maxLength) =>
25+
"Value must have a length less than or equal to ${maxLength}";
2526

2627
static m2(min) => "Value must be greater than or equal to ${min}.";
2728

28-
static m3(minLength) => "Value must have a length greater than or equal to ${minLength}";
29+
static m3(minLength) =>
30+
"Value must have a length greater than or equal to ${minLength}";
2931

3032
final messages = _notInlinedMessages(_notInlinedMessages);
31-
static _notInlinedMessages(_) => <String, Function> {
32-
"creditCardErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid credit card number."),
33-
"dateStringErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid date string."),
34-
"emailErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid email address."),
35-
"ipErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid IP."),
36-
"maxErrorText" : m0,
37-
"maxLengthErrorText" : m1,
38-
"minErrorText" : m2,
39-
"minLengthErrorText" : m3,
40-
"numericErrorText" : MessageLookupByLibrary.simpleMessage("Value must be numeric."),
41-
"patternErrorText" : MessageLookupByLibrary.simpleMessage("Value does not match pattern."),
42-
"requireTrueErrorText" : MessageLookupByLibrary.simpleMessage("This field must be set to true."),
43-
"requiredErrorText" : MessageLookupByLibrary.simpleMessage("Este campo no puede estar vacío."),
44-
"urlErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid URL address.")
45-
};
33+
static _notInlinedMessages(_) => <String, Function>{
34+
"creditCardErrorText": MessageLookupByLibrary.simpleMessage(
35+
"This field requires a valid credit card number."),
36+
"dateStringErrorText": MessageLookupByLibrary.simpleMessage(
37+
"This field requires a valid date string."),
38+
"emailErrorText": MessageLookupByLibrary.simpleMessage(
39+
"This field requires a valid email address."),
40+
"ipErrorText": MessageLookupByLibrary.simpleMessage(
41+
"This field requires a valid IP."),
42+
"maxErrorText": m0,
43+
"maxLengthErrorText": m1,
44+
"minErrorText": m2,
45+
"minLengthErrorText": m3,
46+
"numericErrorText":
47+
MessageLookupByLibrary.simpleMessage("Value must be numeric."),
48+
"patternErrorText": MessageLookupByLibrary.simpleMessage(
49+
"Value does not match pattern."),
50+
"requireTrueErrorText": MessageLookupByLibrary.simpleMessage(
51+
"This field must be set to true."),
52+
"requiredErrorText": MessageLookupByLibrary.simpleMessage(
53+
"Este campo no puede estar vacío."),
54+
"urlErrorText": MessageLookupByLibrary.simpleMessage(
55+
"This field requires a valid URL address.")
56+
};
4657
}

lib/l10n/messages_messages.dart

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,37 @@ class MessageLookup extends MessageLookupByLibrary {
2121

2222
static m0(max) => "Value must be less than or equal to ${max}";
2323

24-
static m1(maxLength) => "Value must have a length less than or equal to ${maxLength}";
24+
static m1(maxLength) =>
25+
"Value must have a length less than or equal to ${maxLength}";
2526

2627
static m2(min) => "Value must be greater than or equal to ${min}.";
2728

28-
static m3(minLength) => "Value must have a length greater than or equal to ${minLength}";
29+
static m3(minLength) =>
30+
"Value must have a length greater than or equal to ${minLength}";
2931

3032
final messages = _notInlinedMessages(_notInlinedMessages);
31-
static _notInlinedMessages(_) => <String, Function> {
32-
"creditCardErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid credit card number."),
33-
"dateStringErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid date string."),
34-
"emailErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid email address."),
35-
"ipErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid IP."),
36-
"maxErrorText" : m0,
37-
"maxLengthErrorText" : m1,
38-
"minErrorText" : m2,
39-
"minLengthErrorText" : m3,
40-
"numericErrorText" : MessageLookupByLibrary.simpleMessage("Value must be numeric."),
41-
"patternErrorText" : MessageLookupByLibrary.simpleMessage("Value does not match pattern."),
42-
"requireTrueErrorText" : MessageLookupByLibrary.simpleMessage("This field must be set to true."),
43-
"requiredErrorText" : MessageLookupByLibrary.simpleMessage("This field cannot be empty."),
44-
"urlErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid URL address.")
45-
};
33+
static _notInlinedMessages(_) => <String, Function>{
34+
"creditCardErrorText": MessageLookupByLibrary.simpleMessage(
35+
"This field requires a valid credit card number."),
36+
"dateStringErrorText": MessageLookupByLibrary.simpleMessage(
37+
"This field requires a valid date string."),
38+
"emailErrorText": MessageLookupByLibrary.simpleMessage(
39+
"This field requires a valid email address."),
40+
"ipErrorText": MessageLookupByLibrary.simpleMessage(
41+
"This field requires a valid IP."),
42+
"maxErrorText": m0,
43+
"maxLengthErrorText": m1,
44+
"minErrorText": m2,
45+
"minLengthErrorText": m3,
46+
"numericErrorText":
47+
MessageLookupByLibrary.simpleMessage("Value must be numeric."),
48+
"patternErrorText": MessageLookupByLibrary.simpleMessage(
49+
"Value does not match pattern."),
50+
"requireTrueErrorText": MessageLookupByLibrary.simpleMessage(
51+
"This field must be set to true."),
52+
"requiredErrorText":
53+
MessageLookupByLibrary.simpleMessage("This field cannot be empty."),
54+
"urlErrorText": MessageLookupByLibrary.simpleMessage(
55+
"This field requires a valid URL address.")
56+
};
4657
}

lib/src/fields/form_builder_date_range_picker.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ class FormBuilderDateRangePickerState extends FormBuilderFieldState {
263263
Future.microtask(() => FocusScope.of(context).requestFocus(FocusNode()));
264264
}
265265

266-
String format(DateTime date) =>
267-
FormBuilderDateRangePicker.tryFormat(date, widget.format ?? intl.DateFormat.yMd());
266+
String format(DateTime date) => FormBuilderDateRangePicker.tryFormat(
267+
date, widget.format ?? intl.DateFormat.yMd());
268268

269269
void _setTextFieldString() {
270270
setState(() {

lib/src/fields/form_builder_signature_pad.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ class _FormBuilderSignaturePadState extends FormBuilderFieldState {
114114
@override
115115
FormBuilderSignaturePad get widget => super.widget;
116116

117-
SignatureController get effectiveController => widget.controller ?? _controller;
117+
SignatureController get effectiveController =>
118+
widget.controller ?? _controller;
118119

119120
final SignatureController _controller = SignatureController();
120121

lib/src/fields/form_builder_slider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class FormBuilderSlider extends FormBuilderField {
6666
readOnly: readOnly,
6767
builder: (FormFieldState field) {
6868
final _FormBuilderSliderState state = field;
69-
var _numberFormat = numberFormat ?? NumberFormat('##0.0');
69+
// var _numberFormat = numberFormat ?? NumberFormat('##0.0');
7070
return InputDecorator(
7171
decoration: decoration.copyWith(
7272
enabled: !state.readOnly,

lib/src/fields/form_builder_text_field.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ class FormBuilderTextField extends FormBuilderField {
156156
readOnly: readOnly,
157157
builder: (FormFieldState field) {
158158
final _FormBuilderTextFieldState state = field;
159-
final effectiveDecoration = (decoration ??
160-
const InputDecoration())
159+
final effectiveDecoration = (decoration ?? const InputDecoration())
161160
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
162161
void onChangedHandler(String value) {
163162
if (onChanged != null) {
@@ -169,8 +168,9 @@ class FormBuilderTextField extends FormBuilderField {
169168
return TextField(
170169
controller: state._effectiveController,
171170
focusNode: focusNode,
172-
decoration:
173-
effectiveDecoration.copyWith(errorText: decoration?.errorText ?? field.errorText,),
171+
decoration: effectiveDecoration.copyWith(
172+
errorText: decoration?.errorText ?? field.errorText,
173+
),
174174
keyboardType: keyboardType,
175175
textInputAction: textInputAction,
176176
style: style,

lib/src/form_builder_validators.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class FormBuilderValidators {
135135
if (valueCandidate != null && valueCandidate.isNotEmpty) {
136136
if (!isEmail(valueCandidate.trim())) {
137137
return errorText ??
138-
FormBuilderLocalizations.of(context).emailErrorText;
138+
FormBuilderLocalizations.of(context).emailErrorText;
139139
}
140140
}
141141
return null;
@@ -162,8 +162,7 @@ class FormBuilderValidators {
162162
allowUnderscore: allowUnderscore,
163163
hostWhitelist: hostWhitelist,
164164
hostBlacklist: hostBlacklist)) {
165-
return errorText ??
166-
FormBuilderLocalizations.of(context).urlErrorText;
165+
return errorText ?? FormBuilderLocalizations.of(context).urlErrorText;
167166
}
168167
}
169168
return null;
@@ -228,8 +227,7 @@ class FormBuilderValidators {
228227
return (valueCandidate) {
229228
if (valueCandidate != null && valueCandidate.isNotEmpty) {
230229
if (!isIP(valueCandidate, version)) {
231-
return errorText ??
232-
FormBuilderLocalizations.of(context).ipErrorText;
230+
return errorText ?? FormBuilderLocalizations.of(context).ipErrorText;
233231
}
234232
}
235233
return null;

0 commit comments

Comments
 (0)