Skip to content

Commit a3fa6aa

Browse files
committed
Docs
1 parent 7a32228 commit a3fa6aa

File tree

5 files changed

+66
-15
lines changed

5 files changed

+66
-15
lines changed

example/lib/home_page.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:form_builder_validators/form_builder_validators.dart';
33

4+
/// Represents the home page of the application.
45
class HomePage extends StatelessWidget {
6+
/// Constructs a new instance of the [HomePage] class.
57
const HomePage({super.key});
68

79
@override

example/lib/override_form_builder_localizations_en.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import 'package:flutter/material.dart';
33
import 'package:form_builder_validators/form_builder_validators.dart';
44

55
/// Created by ipcjs on 2022/10/31.
6+
///
7+
/// Overrides the default FormBuilderLocalizationsImplEn class for English localizations.
68
class OverrideFormBuilderLocalizationsEn
79
extends FormBuilderLocalizationsImplEn {
810
/// Constructor for the override class.
911
OverrideFormBuilderLocalizationsEn();
1012

13+
/// The delegate for the override class.
1114
static const LocalizationsDelegate<FormBuilderLocalizationsImpl> delegate =
1215
_LocalizationsDelegate();
1316

17+
/// The list of supported locales for the override class.
1418
static const List<Locale> supportedLocales = <Locale>[Locale('en')];
1519

1620
// Override a field and return your translation.

lib/src/bool/has_lowercase_chars_validator.dart

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import '../../localization/l10n.dart';
22
import '../base_validator.dart';
33

4+
/// {@template has_lowercase_chars_template}
5+
/// [HasLowercaseCharsValidator] extends [BaseValidator] to validate if a string
6+
/// contains a specified minimum number of lowercase characters.
7+
///
8+
/// ## Parameters:
9+
///
10+
/// - [atLeast] The minimum number of lowercase characters required.
11+
/// - [regex] The regular expression used to identify lowercase characters.
12+
/// - [errorText] The error message returned if the validation fails.
13+
///
14+
/// {@macro lower_case_template}
15+
/// {@endtemplate}
416
class HasLowercaseCharsValidator extends BaseValidator<String> {
17+
/// Constructor for the lowercase characters validator.
518
HasLowercaseCharsValidator({
619
this.atLeast = 1,
720

@@ -15,21 +28,23 @@ class HasLowercaseCharsValidator extends BaseValidator<String> {
1528
super.checkNullOrEmpty,
1629
}) : regex = regex ?? _lowerCase;
1730

31+
/// The minimum number of lowercase characters required.
1832
final int atLeast;
1933

34+
/// The regular expression used to identify lowercase characters.
2035
final RegExp regex;
2136

2237
@override
2338
String get translatedErrorText =>
2439
FormBuilderLocalizations.current.containsLowercaseCharErrorText(atLeast);
2540

2641
/// {@template lower_case_template}
27-
/// This regex matches any character that is not a lowercase letter (a-z).
42+
/// This regex matches any character that is a lowercase letter (a-z).
2843
///
29-
/// - It includes special characters, digits, and uppercase letters.
30-
/// - It can be used to find non-lowercase characters.
44+
/// - It includes all lowercase letters.
45+
/// - It can be used to find lowercase characters.
3146
///
32-
/// Examples: A, 1, @
47+
/// Examples: a, b, c
3348
/// {@endtemplate}
3449
static final RegExp _lowerCase = RegExp('[a-z]');
3550

@@ -38,6 +53,13 @@ class HasLowercaseCharsValidator extends BaseValidator<String> {
3853
return lowercaseCharLength(valueCandidate) >= atLeast ? null : errorText;
3954
}
4055

56+
/// Calculates the number of lowercase characters in the given value.
57+
///
58+
/// ## Parameters:
59+
/// - [value] The string to be evaluated.
60+
///
61+
/// ## Returns:
62+
/// The count of lowercase characters in the string.
4163
int lowercaseCharLength(String value) {
4264
return regex.allMatches(value).length;
4365
}

lib/src/bool/has_numeric_chars_validator.dart

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import '../../localization/l10n.dart';
22
import '../base_validator.dart';
33

4+
/// {@template has_numeric_chars_template}
5+
/// [HasNumericCharsValidator] extends [BaseValidator] to validate if a string
6+
/// contains a specified minimum number of numeric characters (digits).
7+
///
8+
/// ## Parameters:
9+
///
10+
/// - [atLeast] The minimum number of numeric characters required.
11+
/// - [regex] The regular expression used to identify numeric characters.
12+
/// - [errorText] The error message returned if the validation fails.
13+
///
14+
/// {@macro numeric_chars_template}
15+
/// {@endtemplate}
416
class HasNumericCharsValidator extends BaseValidator<String> {
17+
/// Constructor for the numeric characters validator.
518
HasNumericCharsValidator({
619
this.atLeast = 1,
720

@@ -15,21 +28,23 @@ class HasNumericCharsValidator extends BaseValidator<String> {
1528
super.checkNullOrEmpty,
1629
}) : regex = regex ?? _number;
1730

31+
/// The minimum number of numeric characters required.
1832
final int atLeast;
1933

34+
/// The regular expression used to identify numeric characters.
2035
final RegExp regex;
2136

2237
@override
2338
String get translatedErrorText =>
2439
FormBuilderLocalizations.current.containsNumberErrorText(atLeast);
2540

2641
/// {@template numeric_chars_template}
27-
/// This regex matches any character that is not a digit (0-9).
42+
/// This regex matches any character that is a digit (0-9).
2843
///
29-
/// - It includes special characters, letters, and other non-numeric characters.
30-
/// - It can be used to find non-digit characters.
44+
/// - It includes all numeric digits.
45+
/// - It can be used to find numeric characters.
3146
///
32-
/// Examples: a, A, @
47+
/// Examples: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
3348
/// {@endtemplate}
3449
static final RegExp _number = RegExp('[0-9]');
3550

@@ -38,6 +53,13 @@ class HasNumericCharsValidator extends BaseValidator<String> {
3853
return numberCharLength(valueCandidate) >= atLeast ? null : errorText;
3954
}
4055

56+
/// Calculates the number of numeric characters in the given value.
57+
///
58+
/// ## Parameters:
59+
/// - [value] The string to be evaluated.
60+
///
61+
/// ## Returns:
62+
/// The count of numeric characters in the string.
4163
int numberCharLength(String value) {
4264
return regex.allMatches(value).length;
4365
}

lib/src/network/email_validator.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import '../../localization/l10n.dart';
22
import '../base_validator.dart';
33

44
/// {@template email_template}
5-
/// `EmailValidator` extends `BaseValidator` that validates a given email address.
5+
/// [EmailValidator] extends [BaseValidator] that validates a given email address.
66
/// It uses a regular expression to check if the email address is valid.
77
///
8-
/// Parameters:
8+
/// ## Parameters:
99
///
10-
/// - [errorText]: The error message returned if the email address is invalid.
11-
/// - [regex]: The regular expression used to validate the email address.
10+
/// - [errorText] The error message returned if the email address is invalid.
11+
/// - [regex] The regular expression used to validate the email address.
1212
///
1313
/// {@macro email_regex_template}
1414
/// {@endtemplate}
1515
class EmailValidator extends BaseValidator<String> {
16+
/// Constructor for the email validator.
1617
EmailValidator({
1718
/// {@macro email_regex_template}
1819
RegExp? regex,
@@ -28,6 +29,9 @@ class EmailValidator extends BaseValidator<String> {
2829
String get translatedErrorText =>
2930
FormBuilderLocalizations.current.emailErrorText;
3031

32+
/// The regular expression used to validate the email address.
33+
final RegExp regex;
34+
3135
/// {@template email_regex_template}
3236
/// The default regex matches an email address.
3337
///
@@ -41,9 +45,6 @@ class EmailValidator extends BaseValidator<String> {
4145
r"^((([a-z]|\d|[!#\$%&'*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$",
4246
);
4347

44-
/// The regular expression used to validate the email address.
45-
final RegExp regex;
46-
4748
@override
4849
String? validateValue(String valueCandidate) {
4950
return regex.hasMatch(valueCandidate.toLowerCase()) ? null : errorText;

0 commit comments

Comments
 (0)