Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the API modifications #129

Merged
Show file tree
Hide file tree
Changes from 140 commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
3de8a0c
testing updated api
ArturAssisComp Jul 31, 2024
cc9138a
Merge remote-tracking branch 'Original_Remote/main'
ArturAssisComp Aug 7, 2024
8db49ff
starting the implementation of the api change
ArturAssisComp Aug 7, 2024
d1a54c4
Implement is false elementary validator
ArturAssisComp Aug 13, 2024
82cfae2
Implement is true elementary validator
ArturAssisComp Aug 13, 2024
29dbdec
Implement is has min upper case chars elementary validator
ArturAssisComp Aug 13, 2024
0248556
fix analyzer issues
ArturAssisComp Aug 13, 2024
01a8d97
implemented elementary has min lowercase
ArturAssisComp Aug 19, 2024
7759354
implemented elementary has min numeric
ArturAssisComp Aug 19, 2024
27b79fa
refactor
ArturAssisComp Aug 20, 2024
15985b5
implemented elementary has min special chars
ArturAssisComp Aug 20, 2024
3903b5d
implemented the basic version of the new API
ArturAssisComp Aug 20, 2024
c8a4f20
refactor
ArturAssisComp Aug 20, 2024
1e5285e
add is numeric validator
ArturAssisComp Aug 21, 2024
8b102b9
add max elementary validator
ArturAssisComp Aug 21, 2024
0930a51
add max elementary validator
ArturAssisComp Aug 21, 2024
60799ac
implemented the new prototype
ArturAssisComp Aug 30, 2024
530425e
Merge pull request #1 from ArturAssisComp/prototype-overload-operators
ArturAssisComp Aug 30, 2024
65130df
add new example
ArturAssisComp Aug 31, 2024
0399d92
remove all the changes to the old api
ArturAssisComp Sep 13, 2024
f0cba63
Merge pull request #2 from ArturAssisComp/prototype-overload-operators
ArturAssisComp Sep 13, 2024
764ecee
remove base elementary validators
ArturAssisComp Sep 13, 2024
b189bd6
remove placeholder validator
ArturAssisComp Sep 13, 2024
8725f87
change name
ArturAssisComp Sep 13, 2024
f8f0ec4
change name
ArturAssisComp Sep 14, 2024
26d62e0
change name: msg
ArturAssisComp Sep 14, 2024
1da3af9
update names
ArturAssisComp Sep 20, 2024
08f825c
implement min lowercase chars validator with tests
ArturAssisComp Sep 21, 2024
516c565
implement min numeric chars validator with tests
ArturAssisComp Sep 24, 2024
cfe77ba
implement min special chars validator with tests
ArturAssisComp Sep 24, 2024
6096c0d
implement min uppercase chars validator with tests
ArturAssisComp Sep 26, 2024
0fea0e4
add documentation
ArturAssisComp Sep 26, 2024
8abf52e
implement isTrue and isFalse
ArturAssisComp Sep 26, 2024
a05846e
change name
ArturAssisComp Sep 26, 2024
82bcf8d
change name: message to msg
ArturAssisComp Sep 26, 2024
37cbc25
update has min uppercase
ArturAssisComp Sep 28, 2024
cd13d7b
update has min lowercase
ArturAssisComp Sep 28, 2024
0d4f167
update has min numeric
ArturAssisComp Sep 28, 2024
439fe0a
update has min special chars
ArturAssisComp Oct 2, 2024
445e26b
update has min special chars
ArturAssisComp Oct 2, 2024
537294e
refactor
ArturAssisComp Oct 2, 2024
f6feb9f
Implement contains element validator
ArturAssisComp Oct 3, 2024
c4dd41d
Implement equal length validator
ArturAssisComp Oct 4, 2024
71f6254
Implement max length validator
ArturAssisComp Oct 7, 2024
0f63d93
Implement min length validator
ArturAssisComp Oct 7, 2024
926b96f
Implement between length validator
ArturAssisComp Oct 7, 2024
c14f30b
Merge branch 'main' into main
ArturAssisComp Oct 7, 2024
7df3cf0
add type annotation
ArturAssisComp Oct 7, 2024
086fd66
Merge remote-tracking branch 'origin/main'
ArturAssisComp Oct 7, 2024
3024e98
implement and composition validator
ArturAssisComp Oct 7, 2024
8fab069
implement or composition validator
ArturAssisComp Oct 7, 2024
30c3947
implement conditional validator if
ArturAssisComp Oct 8, 2024
408a9d4
implement conditional validator skip if
ArturAssisComp Oct 8, 2024
0a05445
implement is required validator
ArturAssisComp Oct 8, 2024
3698588
implement is optional validator
ArturAssisComp Oct 9, 2024
9adfa88
implement validate with default validator
ArturAssisComp Oct 9, 2024
286e5be
add partially the isEqual validator
ArturAssisComp Oct 10, 2024
a77e03e
update android project
ArturAssisComp Oct 10, 2024
60f38e4
update example
ArturAssisComp Oct 10, 2024
16fac8a
implement debug print validator
ArturAssisComp Oct 22, 2024
c4c829a
implement isEqual
ArturAssisComp Nov 2, 2024
b58c851
implement isNotEqual
ArturAssisComp Nov 2, 2024
0e4e89a
implement override error msg validator
ArturAssisComp Nov 2, 2024
c6df4e6
implement transform and validate validator
ArturAssisComp Nov 2, 2024
6a3ac04
implement isString validator tests
ArturAssisComp Nov 6, 2024
39e13cb
implement isInt validator tests
ArturAssisComp Nov 6, 2024
4205fa9
implement isNum validator tests
ArturAssisComp Nov 6, 2024
b1e0dc9
implement isBool validator tests
ArturAssisComp Nov 6, 2024
071f3f5
implement isDateTime validator tests
ArturAssisComp Nov 13, 2024
28a7c43
implement isAfter validator
ArturAssisComp Nov 16, 2024
7557dd0
implement isBefore validator
ArturAssisComp Nov 16, 2024
08bb9b8
implement isDateTimeBetween validator
ArturAssisComp Nov 19, 2024
a005cb1
implement isInTheFuture validator
ArturAssisComp Nov 19, 2024
b362433
implement isInThePast validator
ArturAssisComp Nov 19, 2024
e8da6fc
implement matchesAllowedExtensions validator
ArturAssisComp Nov 22, 2024
5a35bbf
(numeric validator) implement between validator
ArturAssisComp Nov 26, 2024
b90bfa5
(numeric validator) implement greater than validator
ArturAssisComp Nov 27, 2024
9170132
(numeric validator) implement greater than or equal to validator
ArturAssisComp Nov 27, 2024
fb07cb1
(numeric validator) implement less than validator
ArturAssisComp Nov 27, 2024
9ff2233
(numeric validator) implement less than or equal to validator
ArturAssisComp Nov 27, 2024
431d574
fix invalid example
ArturAssisComp Nov 27, 2024
c9029d1
add composition validators to aggregator class Validators
ArturAssisComp Dec 13, 2024
2226e57
Merge branch 'refactor_2024_11' into main
deandreamatias Dec 19, 2024
3e860f4
add conditional validators
ArturAssisComp Dec 20, 2024
7e079f6
add debug print validator
ArturAssisComp Dec 20, 2024
a31aa13
add equality validators
ArturAssisComp Dec 21, 2024
bf3c3fe
add override error msg validator
ArturAssisComp Dec 21, 2024
ea740a2
add required validators
ArturAssisComp Dec 25, 2024
89724d6
add transform validator
ArturAssisComp Dec 25, 2024
6ca829b
update custom message parameters
ArturAssisComp Dec 25, 2024
4fcf4a4
add isString
ArturAssisComp Dec 25, 2024
cc7eb6b
fix examples
ArturAssisComp Dec 25, 2024
d47ca0f
add type validators
ArturAssisComp Dec 28, 2024
5348e5b
add localization
ArturAssisComp Dec 28, 2024
29acadf
implement matches_allowed_extensions validator
ArturAssisComp Dec 28, 2024
7079a36
implement password
ArturAssisComp Dec 28, 2024
fd4f33c
implement hasMinLowerCase
ArturAssisComp Dec 28, 2024
f1414ef
implement hasMinNumericChars
ArturAssisComp Dec 28, 2024
c63ecd7
implement hasMinSpecialChars
ArturAssisComp Dec 28, 2024
f3ed40b
implement match
ArturAssisComp Dec 28, 2024
c4caf23
implement collection validators
ArturAssisComp Dec 28, 2024
77ff0d7
implement isAfter
ArturAssisComp Jan 3, 2025
9f22c2e
fix test
ArturAssisComp Jan 4, 2025
d99bb1b
add is date time between
ArturAssisComp Jan 6, 2025
8a1f68b
add is in the past
ArturAssisComp Jan 6, 2025
277858c
add is in the past
ArturAssisComp Jan 6, 2025
27c6f71
add contains element
ArturAssisComp Jan 6, 2025
5325faa
add isTrue and isFalse
ArturAssisComp Jan 6, 2025
420b1ca
add greater than and greater than or equal to validators
ArturAssisComp Jan 6, 2025
cd11182
add less than and less than or equal to validators
ArturAssisComp Jan 6, 2025
bfd9685
add between validator
ArturAssisComp Jan 6, 2025
ced7c08
finish implementing the first set of validators
ArturAssisComp Jan 6, 2025
93da621
add examples using validateGranularly
ArturAssisComp Jan 7, 2025
368e588
add examples using validateGranularly
ArturAssisComp Jan 7, 2025
e425467
remove benchmark harness
ArturAssisComp Jan 7, 2025
d360243
translate and message
ArturAssisComp Jan 17, 2025
bed00ef
improve the documentation of equality validators
ArturAssisComp Jan 20, 2025
3e75d3c
Update lib/src/validators/core_validators/override_error_msg.dart
ArturAssisComp Jan 20, 2025
e29cf28
improve the documentation of equality validators
ArturAssisComp Jan 20, 2025
4f88ec9
remove override error msg validator
ArturAssisComp Jan 21, 2025
28d1a1f
Merge remote-tracking branch 'origin/main'
ArturAssisComp Jan 21, 2025
862a574
refactor collection validators
ArturAssisComp Jan 22, 2025
29e6e2b
add isDouble
ArturAssisComp Jan 23, 2025
96025c7
update the minLength of password validator to 16
ArturAssisComp Jan 23, 2025
81d164c
update compose validators
ArturAssisComp Jan 23, 2025
2dce684
removed isInThePast and isInTheFuture validators.
ArturAssisComp Jan 24, 2025
a52c80f
replace assertion errors with argument errors
ArturAssisComp Jan 24, 2025
62f5f3d
replace the macro documentation with the original documentation to av…
ArturAssisComp Jan 25, 2025
c907fae
add tests to password validator
ArturAssisComp Jan 25, 2025
77bdab2
add ip validator
ArturAssisComp Jan 29, 2025
ce0ca75
fix analyzer issues
ArturAssisComp Jan 29, 2025
575841d
add url validator
ArturAssisComp Feb 3, 2025
4a3d0d7
add contains validator
ArturAssisComp Feb 3, 2025
9bbe9b6
add phoneNumber validator
ArturAssisComp Feb 3, 2025
a7fa09c
add credit card validator
ArturAssisComp Feb 3, 2025
4cb2dd0
add uuid validator
ArturAssisComp Feb 3, 2025
69d4abb
add email validator
ArturAssisComp Feb 3, 2025
020528b
translate between length error text
ArturAssisComp Feb 3, 2025
c3c673b
translate ar
ArturAssisComp Feb 4, 2025
ea9028f
translate for the remaining languages
ArturAssisComp Feb 4, 2025
5af481b
Update lib/src/validators/network_validators.dart
ArturAssisComp Feb 5, 2025
d1b65c0
improve null safety for url validator
ArturAssisComp Feb 5, 2025
70dc1b7
make the url validator immutable
ArturAssisComp Feb 5, 2025
ef62499
add test case to check validator immutability (contains element)
ArturAssisComp Feb 5, 2025
970321f
make 'and' validator immutable
ArturAssisComp Feb 5, 2025
256d2a4
make 'or' validator immutable
ArturAssisComp Feb 5, 2025
9a7b1aa
Add immutability test case for match allowed extension validator
ArturAssisComp Feb 5, 2025
b416e82
update todos
ArturAssisComp Feb 5, 2025
c6d8809
Merge remote-tracking branch 'origin/main'
ArturAssisComp Feb 5, 2025
1834d8e
Merge branch 'refactor_2024_11' into main
deandreamatias Feb 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ build/
pubspec.lock

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
example/android_backup/**/gradle-wrapper.jar
example/android_backup/.gradle
example/android_backup/captures/
example/android_backup/gradlew
example/android_backup/gradlew.bat
example/android_backup/local.properties
example/android_backup/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,37 @@ Take a look at [our fantastic ecosystem](https://github.com/flutter-form-builder
## Thanks to

[All contributors](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/graphs/contributors)


# API changes draft
During the process of exploration of new possibilities for the new API, I realized that there are
basically three layers of validators: required layer, type layer and the specialized layer. Instead of
repeating the computations for required and type layer for each validator composition, it is possible
to decouple them, avoiding this redundancy and taking benefits from the Dart compiler.

During the exploration, I implemented some elementary validators that would make it possible, by
composition, to create more sophisticated validators. The recipe is simple, start with a (not)required
validator, add a type validator, and then chain as many specialized validators as you want.

```dart
// In this example, we build a validator composing a required, with a numeric and then a max.
// The logic result is: required && numeric && max(70)

final validator = ValidatorBuilder.required(and: <Validator<Object, num>>[
ValidatorBuilder.numeric(
errorText: 'La edad debe ser numérica.',
and: <BaseElementaryValidator<num, dynamic>>[
ValidatorBuilder.max(70),
])
]).validate;
```

I needed to change a little bit the approach. Instead of composing directly the validators as
FormFieldValidator's, one level of indirection was necessary, using a ValidatorBuilder instead.
Thus, we first build the validator and then create the validation method calling validate.

I implemented some examples that are related to some examples from example/main.dart. The new
API examples are implemented in example/api_refactoring_main.dart. I recorded a video showing the
execution of the examples and explaining the new api ideas.

Please, give me the necessary feedback for me to continue the work.
6 changes: 3 additions & 3 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ app.*.symbols
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
/android_backup/app/debug
/android_backup/app/profile
/android_backup/app/release
29 changes: 16 additions & 13 deletions example/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "5dcb86f68f239346676ceb1ed1ea385bd215fba1"
revision: "2663184aa79047d0a33a14a3b607954f8fdd8730"
channel: "stable"

project_type: app
Expand All @@ -13,23 +13,26 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: android
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: ios
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: linux
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: macos
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: web
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: windows
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730

# User provided section

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
69 changes: 69 additions & 0 deletions example/lib/basic_examples.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';
import 'package:form_builder_validators/form_builder_validators.dart'
show Validators;

/// Basic examples involving only one validator per example
class BasicExamplesPage extends StatelessWidget {
/// Constructs a new instance of the [BasicExamplesPage] class.
const BasicExamplesPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Basic Examples (one validator per example)')),
body: Padding(
padding: const EdgeInsets.all(8),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
// Core validators
Text(
'Core Validators',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24),
),
Align(
alignment: Alignment.centerLeft,
child: Text(
'Equality Validators',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
),
TextFormField(
decoration: const InputDecoration(
labelText:
'Type "I want to delete" to confirm the action.'),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: Validators.isEqual('I want to delete'),
),
TextFormField(
decoration: const InputDecoration(
labelText: 'Username (should not be "RESERVED")'),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: Validators.isNotEqual('RESERVED'),
),
Align(
alignment: Alignment.centerLeft,
child: Text(
'Required Error Message',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
),
TextFormField(
decoration:
const InputDecoration(labelText: 'Input must not be null'),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String? input) {
final String? isRequiredMsg = Validators.isRequired()(input);
return isRequiredMsg
?.toUpperCase()
.replaceFirst('OVERRIDE: ', '');
},
),
],
),
),
),
);
}
}
Loading