-
-
Notifications
You must be signed in to change notification settings - Fork 102
Improve documentation readme about migration #146
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
base: refactor_2024_11
Are you sure you want to change the base?
Improve documentation readme about migration #146
Conversation
@deandreamatias I created this PR to do the item 2 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## refactor_2024_11 #146 +/- ##
====================================================
- Coverage 98.74% 98.11% -0.64%
====================================================
Files 111 112 +1
Lines 1510 1588 +78
====================================================
+ Hits 1491 1558 +67
- Misses 19 30 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I am writing the migration guide now. Datetime validators
File validators
Finance validators
Miscellaneous validators
Network validators
Numeric validators
String validators
User Information validators
|
I will take a look and check. When ready, will write a comment |
Added the first migration instructions below. Please, check if they are very clear. Otherwise, I refactor them for them to be clearer. ### v11 to v12
- Deprecate `FormBuilderValidators` class with its static methods as validators.
- Instead, you should use `Validators` class.
- Instructions on how to update each old API validator to the new API equivalent:
- **checkNullOrEmpty**: Before specifying the equivalent to each validator, it is important to deal with the `checkNullOrEmpty` parameter. Every validator from the old API has this parameters, thus we are going to use this section to specify how to handle this situation for most of the cases and we will assume that this aspect is already handled for the following sections:
- `checkNullOrEmpty = true`: Given the old api: `FormBuilderValidators.someValidator(..., checkNullOrEmpty:true)`, the equivalent in the new API is `Validators.required(Validators.someEquivalentValidator(...))`.
- `checkNullOrEmpty = false`: Given the old api: `FormBuilderValidators.someValidator(..., checkNullOrEmpty:false)`, the equivalent in the new API is `Validators.optional(Validators.someEquivalentValidator(...))`.
- Bool validators
- For this group of validators, it is expected to receive a `String` as user input. Thus, if your
form widget does not guarantee a `String` input (it may receive an `Object`), you must wrap the
equivalent validator with the type validator for strings. Thus, instead of
`Validators.hasMin<Something>Chars(...)`, use `Validators.string(Validators.hasMin<Something>Chars(...))`
- `FormBuilderValidators.hasLowercaseChars(atLeast: n, regex: reg, errorText: 'some error')` is
equivalent to `Validators.hasMinLowercaseChars(min: n, customLowercaseCounter:(input)=>reg.allMatches(input).length, hasMinLowercaseCharsMsg:(_, __)=>'some error')`
- `FormBuilderValidators.hasNumericChars(atLeast: n, regex: reg, errorText: 'some error')` is
equivalent to `Validators.hasMinNumericChars(min: n, customNumericCounter:(input)=>reg.allMatches(input).length, hasMinNumericCharsMsg:(_, __)=>'some error')`
- `FormBuilderValidators.hasSpecialChars(atLeast: n, regex: reg, errorText: 'some error')` is
equivalent to `Validators.hasMinSpecialChars(min: n, customSpecialCounter:(input)=>reg.allMatches(input).length, hasMinSpecialCharsMsg:(_, __)=>'some error')`
- `FormBuilderValidators.hasUppercaseChars(atLeast: n, regex: reg, errorText: 'some error')` is
equivalent to `Validators.hasMinUppercaseChars(min: n, customUppercaseCounter:(input)=>reg.allMatches(input).length, hasMinUppercaseCharsMsg:(_, __)=>'some error')`
|
About validators on new API.
Will be ideal that in some way we preserve the reference to old validators code. |
|
@deandreamatias , what option do you think is clearer (A or B) to show the old api and the equivalent/close for the new api? |
A is 1000% better 😅 |
I think that is better create a separeted markdown file for migration, because is really big. |
I was reviewing the issues and I think this #131 is probably solved with the new API. |
Should I update intl version to 20? the CI is complaining. Maybe that break code that is using the older version (19). |
On main branch is updated. I need update flutter-form-builder-ecosystem:refactor_2024_11 branch |
README-updated.md
Outdated
- Deprecate `FormBuilderValidators` class with its static methods as validators. | ||
- Instead, you should use `Validators` class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a single line
README-updated.md
Outdated
- `FormBuilderValidators.maxLength(n, errorText:'some error')` is equivalent to | ||
`Validators.maxLength(n, maxLengthMsg: (_, __)=>'some error')` | ||
- `FormBuilderValidators.minLength(n, errorText:'some error')` is equivalent to | ||
`Validators.minLength(n, minLengthMsg: (_, __)=>'some error')` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this implementation is "intuitive". I don't know if is need
- TODO [ ] `Validators.notContains(substring)` - Checks if the field does not contain the `substring`. | ||
- TODO [ ] `FormBuilderValidators.endsWith()` - requires the substring to be the end of the field's value. | ||
- TODO [ ] `FormBuilderValidators.notEndsWith()` - requires the substring not to be the end of the field's value. | ||
- TODO [ ] `FormBuilderValidators.startsWith()` - requires the substring to be the start of the field's value. | ||
- TODO [ ] `FormBuilderValidators.notStartsWith()` - requires the substring not to be the start of the field's value. | ||
- TODO [ ] `FormBuilderValidators.lowercase()` - requires the field's value to be lowercase. | ||
- TODO [ ] `FormBuilderValidators.uppercase()` - requires the field's value to be uppercase. | ||
- `Validators.hasMinUppercaseChars(min:min)` - Checks if the field has a minimum number of uppercase chars. | ||
- TODO [ ] `Validators.hasMaxUppercaseChars(max:max)` - Checks if the field has a maximum number of uppercase chars. | ||
- `Validators.hasMinLowercaseChars(min:min)` - Checks if the field has a minimum number of lowercase chars. | ||
- TODO [ ] `Validators.hasMaxLowercaseChars(max:max)` - Checks if the field has a maximum number of lowercase chars. | ||
- `Validators.hasMinNumericChars(min:min)` - Checks if the field has a minimum number of numeric chars. | ||
- TODO [ ] `Validators.hasMaxNumericChars(max:max)` - Checks if the field has a maximum number of numeric chars. | ||
- `Validators.hasMinSpecialChars(min:min)` - Checks if the field has a minimum number of special chars. | ||
- TODO [ ] `Validators.hasMaxSpecialChars(max:max)` - Checks if the field has a maximum number of special chars. | ||
- `Validators.match(regExp)` - Checks if the field matches with the regular expression `regExp`. | ||
- TODO [ ] `Validators.notMatch(regExp)` - Checks if the field does not match with the regular expression `regExp`. | ||
- `Validators.uuid()` - Checks if the field is a valid Universally Unique Identifier (UUID). | ||
- TODO [ ] `FormBuilderValidators.maxWordsCount()` - requires the word count of the field's value to be less than or equal to the provided maximum count. | ||
- TODO [ ] `FormBuilderValidators.minWordsCount()` - requires the word count of the field's value to be greater than or equal to the provided minimum count. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing TODOs?
(String? val) { | ||
if (val != null) { | ||
final int? number = int.tryParse(val); | ||
// todo bug here: if it is not int, it accepts negative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo?
return (userInput != null && userInput % 2 == 0) ? null : 'This field must be even'; | ||
} | ||
``` | ||
The challenge with the previous approach is that we must handle null checks in every validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the version of previous approach, like ( < v11.x.x)
} | ||
``` | ||
|
||
This package introduces a more precise approach that separates null-value handling from the actual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package introduces a more precise approach that separates null-value handling from the actual | |
From version 12.x.x, this package introduces a more precise approach that separates null-value handling from the actual |
citiesWhitelist: ['CityA', 'CityB', 'CityC'], | ||
citiesBlacklist: ['CityD', 'CityE'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All reference to whiteList
will be allowList
and blackList
will be blockList
import 'package:form_builder_validators/form_builder_validators.dart' | ||
show Validators, Validator; | ||
show Validator, Validators; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still necessary? The show
Connection with issue(s)
Close #131
Connected to #???
Solution description
Screenshots or Videos
To Do