Skip to content

Commit c1478b2

Browse files
committed
Renamed pettern validator to macth, rename requireTrue to equal to allow equality check with other types. Closes #397
1 parent ade7769 commit c1478b2

12 files changed

+111
-150
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ You can either change the value of one field at a time like so:
419419
```dart
420420
_fbKey.currentState.fields['color_picker'].patchValue(Colors.black);
421421
```
422-
Or multiple field value like so:
422+
Or multiple fields value like so:
423423
```dart
424424
_fbKey.currentState.patchValue({
425425
'age': '50',

example/lib/sources/complete_form.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ class CompleteFormState extends State<CompleteForm> {
210210
),
211211
),
212212
validator: FormBuilderValidators.compose([
213-
FormBuilderValidators.requireTrue(
213+
FormBuilderValidators.equal(
214214
context,
215+
true,
215216
errorText:
216217
'You must accept terms and conditions to continue',
217218
),
@@ -229,9 +230,7 @@ class CompleteFormState extends State<CompleteForm> {
229230
),
230231
onChanged: (val) {
231232
setState(() {
232-
print(val);
233233
_ageHasError = !_ageKey.currentState.validate();
234-
// _genderHasError = !_fbKey.currentState.fields['gender'].currentState.validate();
235234
});
236235
},
237236
// valueTransformer: (text) => num.tryParse(text),

lib/l10n/intl_en.arb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
"type": "text",
77
"placeholders": {}
88
},
9-
"requireTrueErrorText": "This field must be set to true.",
10-
"@requireTrueErrorText": {
11-
"description": "Error Text for required field",
12-
"type": "text",
13-
"placeholders": {}
14-
},
159
"minErrorText": "Value must be greater than or equal to {min}.",
1610
"@minErrorText": {
1711
"description": "Error Text for required field",
@@ -56,8 +50,8 @@
5650
"type": "text",
5751
"placeholders": {}
5852
},
59-
"patternErrorText": "Value does not match pattern.",
60-
"@patternErrorText": {
53+
"matchErrorText": "Value does not match pattern.",
54+
"@matchErrorText": {
6155
"description": "Error Text for pattern field",
6256
"type": "text",
6357
"placeholders": {}

lib/l10n/intl_es.arb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
"type": "text",
77
"placeholders": {}
88
},
9-
"requireTrueErrorText": "This field must be set to true.",
10-
"@requireTrueErrorText": {
11-
"description": "Error Text for required field",
12-
"type": "text",
13-
"placeholders": {}
14-
},
159
"minErrorText": "Value must be greater than or equal to {min}.",
1610
"@minErrorText": {
1711
"description": "Error Text for required field",
@@ -56,8 +50,8 @@
5650
"type": "text",
5751
"placeholders": {}
5852
},
59-
"patternErrorText": "Value does not match pattern.",
60-
"@patternErrorText": {
53+
"matchErrorText": "Value does not match pattern.",
54+
"@matchErrorText": {
6155
"description": "Error Text for pattern field",
6256
"type": "text",
6357
"placeholders": {}

lib/l10n/intl_messages.arb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
2-
"@@last_modified": "2020-06-19T21:53:39.706877",
2+
"@@last_modified": "2020-08-05T13:22:06.942734",
33
"requiredErrorText": "This field cannot be empty.",
44
"@requiredErrorText": {
5-
"description": "Error Text for required field",
5+
"description": "Error Text for required validator",
66
"type": "text",
77
"placeholders": {}
88
},
9-
"requireTrueErrorText": "This field must be set to true.",
10-
"@requireTrueErrorText": {
11-
"description": "Error Text for required field",
9+
"equalErrorText": "This field value must be equal to {value}.",
10+
"@equalErrorText": {
11+
"description": "Error Text for equal validator",
1212
"type": "text",
13-
"placeholders": {}
13+
"placeholders": {
14+
"value": {}
15+
}
1416
},
1517
"minErrorText": "Value must be greater than or equal to {min}.",
1618
"@minErrorText": {
@@ -22,15 +24,15 @@
2224
},
2325
"minLengthErrorText": "Value must have a length greater than or equal to {minLength}",
2426
"@minLengthErrorText": {
25-
"description": "Error Text for required field",
27+
"description": "Error Text for minLength validator",
2628
"type": "text",
2729
"placeholders": {
2830
"minLength": {}
2931
}
3032
},
3133
"maxErrorText": "Value must be less than or equal to {max}",
3234
"@maxErrorText": {
33-
"description": "Error Text for required field",
35+
"description": "Error Text for max validator",
3436
"type": "text",
3537
"placeholders": {
3638
"max": {}
@@ -46,43 +48,43 @@
4648
},
4749
"emailErrorText": "This field requires a valid email address.",
4850
"@emailErrorText": {
49-
"description": "Error Text for email field",
51+
"description": "Error Text for email validator",
5052
"type": "text",
5153
"placeholders": {}
5254
},
5355
"urlErrorText": "This field requires a valid URL address.",
5456
"@urlErrorText": {
55-
"description": "Error Text for URL field",
57+
"description": "Error Text for URL validator",
5658
"type": "text",
5759
"placeholders": {}
5860
},
59-
"patternErrorText": "Value does not match pattern.",
60-
"@patternErrorText": {
61-
"description": "Error Text for pattern field",
61+
"matchErrorText": "Value does not match pattern.",
62+
"@matchErrorText": {
63+
"description": "Error Text for pattern validator",
6264
"type": "text",
6365
"placeholders": {}
6466
},
6567
"numericErrorText": "Value must be numeric.",
6668
"@numericErrorText": {
67-
"description": "Error Text for numeric field",
69+
"description": "Error Text for numeric validator",
6870
"type": "text",
6971
"placeholders": {}
7072
},
7173
"creditCardErrorText": "This field requires a valid credit card number.",
7274
"@creditCardErrorText": {
73-
"description": "Error Text for credit card field",
75+
"description": "Error Text for credit card validator",
7476
"type": "text",
7577
"placeholders": {}
7678
},
7779
"ipErrorText": "This field requires a valid IP.",
7880
"@ipErrorText": {
79-
"description": "Error Text for IP address field",
81+
"description": "Error Text for IP address validator",
8082
"type": "text",
8183
"placeholders": {}
8284
},
8385
"dateStringErrorText": "This field requires a valid date string.",
8486
"@dateStringErrorText": {
85-
"description": "Error Text for date string field",
87+
"description": "Error Text for date string validator",
8688
"type": "text",
8789
"placeholders": {}
8890
}

lib/l10n/messages_all.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ import 'package:intl/intl.dart';
1515
import 'package:intl/message_lookup_by_library.dart';
1616
import 'package:intl/src/intl_helpers.dart';
1717

18-
import 'messages_es.dart' as messages_es;
1918
import 'messages_en.dart' as messages_en;
19+
import 'messages_es.dart' as messages_es;
2020
import 'messages_messages.dart' as messages_messages;
2121

2222
typedef Future<dynamic> LibraryLoader();
2323
Map<String, LibraryLoader> _deferredLibraries = {
24-
'es': () => new Future.value(null),
2524
'en': () => new Future.value(null),
25+
'es': () => new Future.value(null),
2626
'messages': () => new Future.value(null),
2727
};
2828

2929
MessageLookupByLibrary _findExact(String localeName) {
3030
switch (localeName) {
31-
case 'es':
32-
return messages_es.messages;
3331
case 'en':
3432
return messages_en.messages;
33+
case 'es':
34+
return messages_es.messages;
3535
case 'messages':
3636
return messages_messages.messages;
3737
default:
@@ -42,8 +42,9 @@ 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, (locale) => _deferredLibraries[locale] != null,
46-
onFailure: (_) => null);
45+
localeName,
46+
(locale) => _deferredLibraries[locale] != null,
47+
onFailure: (_) => null);
4748
if (availableLocale == null) {
4849
return new Future.value(false);
4950
}
@@ -63,8 +64,8 @@ bool _messagesExistFor(String locale) {
6364
}
6465

6566
MessageLookupByLibrary _findGeneratedMessagesFor(String locale) {
66-
var actualLocale =
67-
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
67+
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor,
68+
onFailure: (_) => null);
6869
if (actualLocale == null) return null;
6970
return _findExact(actualLocale);
7071
}

lib/l10n/messages_en.dart

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

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

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

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

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

3230
final messages = _notInlinedMessages(_notInlinedMessages);
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-
};
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+
"matchErrorText" : MessageLookupByLibrary.simpleMessage("Value does not match pattern."),
37+
"maxErrorText" : m0,
38+
"maxLengthErrorText" : m1,
39+
"minErrorText" : m2,
40+
"minLengthErrorText" : m3,
41+
"numericErrorText" : MessageLookupByLibrary.simpleMessage("Value must be numeric."),
42+
"requiredErrorText" : MessageLookupByLibrary.simpleMessage("This field cannot be empty."),
43+
"urlErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid URL address.")
44+
};
5745
}

lib/l10n/messages_es.dart

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

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

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

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

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

3230
final messages = _notInlinedMessages(_notInlinedMessages);
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-
};
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+
"matchErrorText" : MessageLookupByLibrary.simpleMessage("Value does not match pattern."),
37+
"maxErrorText" : m0,
38+
"maxLengthErrorText" : m1,
39+
"minErrorText" : m2,
40+
"minLengthErrorText" : m3,
41+
"numericErrorText" : MessageLookupByLibrary.simpleMessage("Value must be numeric."),
42+
"requiredErrorText" : MessageLookupByLibrary.simpleMessage("Este campo no puede estar vacío."),
43+
"urlErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid URL address.")
44+
};
5745
}

lib/l10n/messages_messages.dart

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,30 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
1919
class MessageLookup extends MessageLookupByLibrary {
2020
String get localeName => 'messages';
2121

22+
static m4(value) => "This field value must be equal to ${value}.";
23+
2224
static m0(max) => "Value must be less than or equal to ${max}";
2325

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

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

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

3232
final messages = _notInlinedMessages(_notInlinedMessages);
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-
};
33+
static _notInlinedMessages(_) => <String, Function> {
34+
"creditCardErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid credit card number."),
35+
"dateStringErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid date string."),
36+
"emailErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid email address."),
37+
"equalErrorText" : m4,
38+
"ipErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid IP."),
39+
"matchErrorText" : MessageLookupByLibrary.simpleMessage("Value does not match pattern."),
40+
"maxErrorText" : m0,
41+
"maxLengthErrorText" : m1,
42+
"minErrorText" : m2,
43+
"minLengthErrorText" : m3,
44+
"numericErrorText" : MessageLookupByLibrary.simpleMessage("Value must be numeric."),
45+
"requiredErrorText" : MessageLookupByLibrary.simpleMessage("This field cannot be empty."),
46+
"urlErrorText" : MessageLookupByLibrary.simpleMessage("This field requires a valid URL address.")
47+
};
5748
}

0 commit comments

Comments
 (0)