Skip to content

Commit 304cafa

Browse files
committed
Docs
1 parent 239477d commit 304cafa

22 files changed

+316
-8
lines changed

lib/src/form_field_validator_extensions.dart

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

4+
/// Extension methods for [FormFieldValidator].
45
extension FormFieldValidatorExtensions<T> on FormFieldValidator<T> {
56
/// Combines the current validator with another validator using logical AND.
67
FormFieldValidator<T> and(FormFieldValidator<T> other) {

lib/src/string/alphabetical_validator.dart

Lines changed: 14 additions & 0 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 alphabetical_validator_template}
5+
/// [AlphabeticalValidator] extends [BaseValidator] to validate if a string contains only alphabetical characters.
6+
///
7+
/// This validator checks if the value matches the specified regex pattern that allows only letters (both uppercase and lowercase).
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [regex] The regular expression used to validate the alphabetical format. Defaults to a regex that matches only alphabetical characters.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class AlphabeticalValidator extends BaseValidator<String> {
17+
/// Constructor for the alphabetical validator.
518
AlphabeticalValidator({
619
/// {@macro alphabetical_template}
720
RegExp? regex,
@@ -13,6 +26,7 @@ class AlphabeticalValidator extends BaseValidator<String> {
1326
super.checkNullOrEmpty,
1427
}) : regex = regex ?? _alphabetical;
1528

29+
/// The regular expression used to validate the alphabetical format.
1630
final RegExp regex;
1731

1832
/// {@template alphabetical_template}

lib/src/string/contains_validator.dart

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

4+
/// {@template contains_validator_template}
5+
/// [ContainsValidator] extends [BaseValidator] to validate if a string contains a specified substring.
6+
///
7+
/// This validator checks if the value contains the specified substring, with an option for case sensitivity.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [substring] The substring that the value must contain.
12+
/// - [caseSensitive] Whether the search should be case-sensitive. Defaults to true.
13+
/// - [errorText] The error message returned if the validation fails.
14+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
15+
///
16+
/// {@endtemplate}
417
class ContainsValidator extends BaseValidator<String> {
18+
/// Constructor for the contains validator.
519
const ContainsValidator(
620
this.substring, {
721
this.caseSensitive = true,
@@ -13,8 +27,10 @@ class ContainsValidator extends BaseValidator<String> {
1327
super.checkNullOrEmpty,
1428
});
1529

30+
/// The substring that the value must contain.
1631
final String substring;
1732

33+
/// Whether the search should be case-sensitive.
1834
final bool caseSensitive;
1935

2036
@override

lib/src/string/ends_with_validator.dart

Lines changed: 14 additions & 0 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 ends_with_validator_template}
5+
/// [EndsWithValidator] extends [BaseValidator] to validate if a string ends with a specified suffix.
6+
///
7+
/// This validator checks if the value ends with the specified suffix.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [suffix] The suffix that the value must end with.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class EndsWithValidator extends BaseValidator<String> {
17+
/// Constructor for the ends with validator.
518
const EndsWithValidator(
619
this.suffix, {
720
/// {@macro base_validator_error_text}
@@ -11,6 +24,7 @@ class EndsWithValidator extends BaseValidator<String> {
1124
super.checkNullOrEmpty,
1225
});
1326

27+
/// The suffix that the value must end with.
1428
final String suffix;
1529

1630
@override

lib/src/string/lowercase_validator.dart

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

4+
/// {@template lowercase_validator_template}
5+
/// [LowercaseValidator] extends [BaseValidator] to validate if a string is entirely lowercase.
6+
///
7+
/// This validator checks if the value is the same as its lowercase version.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [errorText] The error message returned if the validation fails.
12+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
13+
///
14+
/// {@endtemplate}
415
class LowercaseValidator extends BaseValidator<String> {
16+
/// Constructor for the lowercase validator.
517
const LowercaseValidator({
618
/// {@macro base_validator_error_text}
719
super.errorText,

lib/src/string/match_not_validator.dart

Lines changed: 14 additions & 0 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 match_not_validator_template}
5+
/// [MatchNotValidator] extends [BaseValidator] to validate if a string does not match a specified regular expression pattern.
6+
///
7+
/// This validator checks if the value does not match the provided regex pattern.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [regex] The regular expression pattern that the value must not match.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class MatchNotValidator extends BaseValidator<String> {
17+
/// Constructor for the match not validator.
518
const MatchNotValidator(
619
this.regex, {
720
/// {@macro base_validator_error_text}
@@ -11,6 +24,7 @@ class MatchNotValidator extends BaseValidator<String> {
1124
super.checkNullOrEmpty,
1225
});
1326

27+
/// The regular expression pattern that the value must not match.
1428
final RegExp regex;
1529

1630
@override

lib/src/string/match_validator.dart

Lines changed: 14 additions & 0 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 match_validator_template}
5+
/// [MatchValidator] extends [BaseValidator] to validate if a string matches a specified regular expression pattern.
6+
///
7+
/// This validator checks if the value matches the provided regex pattern.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [regex] The regular expression pattern that the value must match.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class MatchValidator extends BaseValidator<String> {
17+
/// Constructor for the match validator.
518
const MatchValidator(
619
this.regex, {
720
/// {@macro base_validator_error_text}
@@ -11,6 +24,7 @@ class MatchValidator extends BaseValidator<String> {
1124
super.checkNullOrEmpty,
1225
});
1326

27+
/// The regular expression pattern that the value must match.
1428
final RegExp regex;
1529

1630
@override

lib/src/string/max_words_count_validator.dart

Lines changed: 15 additions & 1 deletion
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 max_words_count_validator_template}
5+
/// [MaxWordsCountValidator] extends [BaseValidator] to validate if a string contains no more than a specified number of words.
6+
///
7+
/// This validator checks if the number of words in the value does not exceed the specified maximum word count.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [maxWordsCount] The maximum allowable number of words.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class MaxWordsCountValidator extends BaseValidator<String> {
17+
/// Constructor for the maximum words count validator.
518
const MaxWordsCountValidator(
619
this.maxWordsCount, {
720
/// {@macro base_validator_error_text}
@@ -11,6 +24,7 @@ class MaxWordsCountValidator extends BaseValidator<String> {
1124
super.checkNullOrEmpty,
1225
});
1326

27+
/// The maximum allowable number of words.
1428
final int maxWordsCount;
1529

1630
@override
@@ -19,7 +33,7 @@ class MaxWordsCountValidator extends BaseValidator<String> {
1933

2034
@override
2135
String? validateValue(String valueCandidate) {
22-
final int wordsCount = valueCandidate.trim().split(' ').length;
36+
final int wordsCount = valueCandidate.trim().split(RegExp(r'\s+')).length;
2337

2438
return wordsCount > maxWordsCount ? errorText : null;
2539
}

lib/src/string/min_words_count_validator.dart

Lines changed: 15 additions & 1 deletion
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 min_words_count_validator_template}
5+
/// [MinWordsCountValidator] extends [BaseValidator] to validate if a string contains at least a specified number of words.
6+
///
7+
/// This validator checks if the number of words in the value is at least the specified minimum word count.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [minWordsCount] The minimum required number of words.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class MinWordsCountValidator extends BaseValidator<String> {
17+
/// Constructor for the minimum words count validator.
518
const MinWordsCountValidator(
619
this.minWordsCount, {
720
/// {@macro base_validator_error_text}
@@ -11,6 +24,7 @@ class MinWordsCountValidator extends BaseValidator<String> {
1124
super.checkNullOrEmpty,
1225
});
1326

27+
/// The minimum required number of words.
1428
final int minWordsCount;
1529

1630
@override
@@ -19,7 +33,7 @@ class MinWordsCountValidator extends BaseValidator<String> {
1933

2034
@override
2135
String? validateValue(String valueCandidate) {
22-
final int wordsCount = valueCandidate.trim().split(' ').length;
36+
final int wordsCount = valueCandidate.trim().split(RegExp(r'\s+')).length;
2337

2438
return wordsCount < minWordsCount ? errorText : null;
2539
}

lib/src/string/single_line_validator.dart

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

4+
/// {@template single_line_validator_template}
5+
/// [SingleLineValidator] extends [BaseValidator] to validate if a string contains only a single line.
6+
///
7+
/// This validator checks if the value does not contain any newline characters.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [errorText] The error message returned if the validation fails.
12+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
13+
///
14+
/// {@endtemplate}
415
class SingleLineValidator extends BaseValidator<String> {
16+
/// Constructor for the single line validator.
517
const SingleLineValidator({
618
/// {@macro base_validator_error_text}
719
super.errorText,

0 commit comments

Comments
 (0)