Skip to content

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

Open
wants to merge 40 commits into
base: refactor_2024_11
Choose a base branch
from

Conversation

ArturAssisComp
Copy link
Contributor

@ArturAssisComp ArturAssisComp commented Feb 6, 2025

Connection with issue(s)

Close #131

Connected to #???

Solution description

Screenshots or Videos

To Do

  • Read contributing guide
  • Check the original issue to confirm it is fully satisfied
  • Add solution description to help guide reviewers
  • Add unit test to verify new or fixed behaviour
  • If apply, add documentation to code properties and package readme

@ArturAssisComp ArturAssisComp marked this pull request as draft February 6, 2025 13:56
@ArturAssisComp
Copy link
Contributor Author

@deandreamatias I created this PR to do the item 2

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 87.87879% with 12 lines in your changes missing coverage. Please review.

Project coverage is 98.11%. Comparing base (1834d8e) to head (359c8d2).
Report is 1 commits behind head on refactor_2024_11.

Files with missing lines Patch % Lines
lib/src/validators/file_validators.dart 71.79% 11 Missing ⚠️
lib/src/validators/string_validators.dart 0.00% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 98.11% <87.87%> (-0.64%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArturAssisComp
Copy link
Contributor Author

ArturAssisComp commented Feb 27, 2025

I am writing the migration guide now.
While I am doing that, I would like to know what are the validators from the following list that will be implemented in the new api?

Datetime validators

  • TODO FormBuilderValidators.date() - requires the field's value to be a valid date string.
  • TODO FormBuilderValidators.time() - requires the field's value to be a valid time string.
  • TODO FormBuilderValidators.timeZone() - requires the field's value to be a valid time zone.

File validators

  • TODO FormBuilderValidators.fileExtension() - requires the field's value to a valid file extension.
  • TODO FormBuilderValidators.fileName() - requires the field's to be a valid file name.
  • TODO FormBuilderValidators.fileSize() - requires the field's to be less than the max size.
  • TODO FormBuilderValidators.mimeType() - requires the field's value to a valid MIME type.
  • TODO FormBuilderValidators.path() - requires the field's to be a valid file or folder path.

Finance validators

  • TODO FormBuilderValidators.bic() - requires the field's to be a valid BIC.
  • TODO FormBuilderValidators.creditCardCVC() - requires the field's value to be a valid credit card CVC number.
  • TODO FormBuilderValidators.creditCardExpirationDate() - requires the field's value to be a valid credit card expiration date and can check if not expired yet.
  • TODO FormBuilderValidators.iban() - requires the field's to be a valid IBAN.

Miscellaneous validators

  • TODO FormBuilderValidators.base64() - requires the field's to be a valid base64 string.
  • TODO FormBuilderValidators.colorCode() - requires the field's value to be a valid color code.
  • TODO FormBuilderValidators.duns() - requires the field's value to be a valid DUNS.
  • TODO FormBuilderValidators.isbn() - requires the field's to be a valid ISBN.
  • TODO FormBuilderValidators.json() - requires the field's to be a valid json string.
  • TODO FormBuilderValidators.languageCode() - requires the field's to be a valid language code.
  • TODO FormBuilderValidators.licensePlate() - requires the field's to be a valid license plate.
  • TODO FormBuilderValidators.vin() - requires the field's to be a valid VIN number.

Network validators

  • TODO FormBuilderValidators.email() - requires the field's value to be a valid email address.
  • TODO FormBuilderValidators.latitude() - requires the field's to be a valid latitude. - FormBuilderValidators.longitude() - requires the field's to be a valid longitude.
  • TODO FormBuilderValidators.macAddress() - requires the field's to be a valid MAC address.
  • TODO FormBuilderValidators.phoneNumber() - requires the field's value to be a valid phone number.
  • TODO FormBuilderValidators.portNumber() - requires the field's to be a valid port number.

Numeric validators

  • TODO FormBuilderValidators.evenNumber() - requires the field's to be an even number.
  • TODO FormBuilderValidators.negativeNumber() - requires the field's to be a negative number.
  • TODO FormBuilderValidators.notZeroNumber() - requires the field's to be not a number zero.
  • TODO FormBuilderValidators.oddNumber() - requires the field's to be an odd number.
  • TODO FormBuilderValidators.positiveNumber() - requires the field's to be a positive number.
  • TODO FormBuilderValidators.prime() - requires the field's to be a prime number.

String validators

  • TODO FormBuilderValidators.endsWith() - requires the substring 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.lowercase() - requires the field's value to be lowercase.
  • TODO FormBuilderValidators.uppercase() - requires the field's value to be uppercase.
  • TODO FormBuilderValidators.matchNot() - requires the field's value to not match the provided regex pattern.
  • TODO FormBuilderValidators.alphabetical() - requires the field's to contain only alphabetical characters.
  • 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.
  • TODO FormBuilderValidators.singleLine() - requires the field's string to be a single line of text.

User Information validators

  • TODO FormBuilderValidators.city() - requires the field's value to be a valid city name.
  • TODO FormBuilderValidators.country() - requires the field's value to be a valid country name.
  • TODO FormBuilderValidators.firstName() - requires the field's value to be a valid first name.
  • TODO FormBuilderValidators.lastName() - requires the field's value to be a valid last name.
  • TODO FormBuilderValidators.passportNumber() - requires the field's value to be a valid passport number.
  • TODO FormBuilderValidators.ssn() - requires the field's to be a valid SSN (Social Security Number).
  • TODO FormBuilderValidators.state() - requires the field's value to be a valid state name.
  • TODO FormBuilderValidators.street() - requires the field's value to be a valid street name.
  • TODO FormBuilderValidators.username() - requires the field's to be a valid username that matched required conditions.
  • TODO FormBuilderValidators.zipCode() - requires the field's to be a valid zip code.

@deandreamatias
Copy link
Contributor

I will take a look and check. When ready, will write a comment

@ArturAssisComp
Copy link
Contributor Author

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')`
   

@deandreamatias
Copy link
Contributor

About validators on new API.
I finished the checklist. To confirm, this validators should be on new API:

  • FormBuilderValidators.fileSize()
  • FormBuilderValidators.bic()
  • FormBuilderValidators.iban()
  • FormBuilderValidators.colorCode()
  • FormBuilderValidators.isbn()
  • FormBuilderValidators.email()
  • FormBuilderValidators.macAddress()
  • FormBuilderValidators.lowercase()
  • FormBuilderValidators.uppercase()
  • FormBuilderValidators.maxWordsCount()
  • FormBuilderValidators.minWordsCount()

Will be ideal that in some way we preserve the reference to old validators code.
Maybe on changelog can add a link to 11.0.0 branch of Github and the list of all removed validators. With this, the users could see the implementation code and implement with new API if need.

@ArturAssisComp
Copy link
Contributor Author

ArturAssisComp commented Mar 28, 2025

I created a branch called v11.1.2 to use as reference for the validators that are not implemented in the new API.
Oh, I will use permalink instead. this branch will not be necessary anymore.

@ArturAssisComp
Copy link
Contributor Author

@deandreamatias , what option do you think is clearer (A or B) to show the old api and the equivalent/close for the new api?
image

@deandreamatias
Copy link
Contributor

deandreamatias commented Mar 29, 2025

@deandreamatias , what option do you think is clearer (A or B) to show the old api and the equivalent/close for the new api? image

A is 1000% better 😅

@deandreamatias
Copy link
Contributor

deandreamatias commented Mar 30, 2025

I think that is better create a separeted markdown file for migration, because is really big.
The recommended is to create it inside a path call doc/ https://dart.dev/tools/pub/package-layout#documentation. The name of file could be migration.md (very intuitve hehehe)

@deandreamatias
Copy link
Contributor

I was reviewing the issues and I think this #131 is probably solved with the new API.
Maybe you can put it as related in the MR.

@github-actions github-actions bot added the Stale label Jul 14, 2025
@github-actions github-actions bot removed the Stale label Jul 24, 2025
@ArturAssisComp ArturAssisComp marked this pull request as ready for review July 24, 2025 22:46
@ArturAssisComp
Copy link
Contributor Author

Should I update intl version to 20? the CI is complaining. Maybe that break code that is using the older version (19).

@deandreamatias
Copy link
Contributor

On main branch is updated. I need update flutter-form-builder-ecosystem:refactor_2024_11 branch

Comment on lines 369 to 370
- Deprecate `FormBuilderValidators` class with its static methods as validators.
- Instead, you should use `Validators` class.
Copy link
Contributor

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

Comment on lines 398 to 401
- `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')`
Copy link
Contributor

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

Comment on lines +190 to +209
- 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.
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +698 to +699
citiesWhitelist: ['CityA', 'CityB', 'CityC'],
citiesBlacklist: ['CityD', 'CityE'],
Copy link
Contributor

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

Comment on lines 2 to 4
import 'package:form_builder_validators/form_builder_validators.dart'
show Validators, Validator;
show Validator, Validators;

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants