Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
wellgenio committed Aug 29, 2024
1 parent ca421eb commit 5fac23d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class UserModel {
String email;
String password;
int age;
DateTime dateOfBirth;
UserModel({
required this.email,
required this.password,
required this.age,
required this.dateOfBirth,
});
}
Expand All @@ -44,6 +46,8 @@ import 'package:lucid_validation/lucid_validation.dart';
class UserValidator extends LucidValidator<UserModel> {
UserValidator() {
final now = DateTime.now();
ruleFor((user) => user.email, key: 'email')
.notEmpty()
.validEmail();
Expand All @@ -58,6 +62,9 @@ class UserValidator extends LucidValidator<UserModel> {
ruleFor((user) => user.age, key: 'age')
.min(18, message: 'Minimum age is 18 years');
ruleFor((user) => user.dateOfBirth, key: 'dateOfBirth')
.lessThan(DateTime(now.year - 18, now.month, now.day));
}
}
Expand Down Expand Up @@ -111,6 +118,12 @@ Here’s a complete list of available validators you can use:
- **validCNPJ**: Checks if a string is a valid CNPJ (for use in Brazil).
- **validCEP**: Checks if a string is a valid CEP (for use in Brazil).
- **validCredCard**: Checks if a string is a valid Credit Card.
- **greaterThanOrEqualTo**: Checks if the datetime value is greater than or equal to a specified minimum datetime.
- **greaterThan**: Checks if the datetime value is greater than a specified minimum datetime.
- **lessThanOrEqualTo**: Checks if the datetime value is less than or equal to a specified maximum datetime.
- **lessThan**: Checks if the datetime value is less than a specified maximum datetime.
- **inclusiveBetween**: Checks if the datetime value is between two datetime values, including both bounds.
- **exclusiveBetween**: Checks if the datetime value is between two datetime values, excluding both bounds.

## Usage with Flutter

Expand Down
7 changes: 3 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() {
runApp(const MyApp());
}

final globalLocale = ValueNotifier(Locale('en'));
final globalLocale = ValueNotifier(const Locale('en'));

class MyApp extends StatelessWidget {
const MyApp({super.key});
Expand All @@ -29,7 +29,7 @@ class MyApp extends StatelessWidget {
Locale('en', 'US'),
Locale('pt', 'BR'),
],
localizationsDelegates: [
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
Expand All @@ -49,7 +49,7 @@ class MyApp extends StatelessWidget {
class LucidLocalizationDelegate extends LocalizationsDelegate<Culture> {
const LucidLocalizationDelegate();

static final delegate = LucidLocalizationDelegate();
static const delegate = LucidLocalizationDelegate();

@override
bool isSupported(Locale locale) {
Expand All @@ -61,7 +61,6 @@ class LucidLocalizationDelegate extends LocalizationsDelegate<Culture> {

@override
Future<Culture> load(Locale locale) async {
print(locale);
final culture = Culture(locale.languageCode, locale.countryCode ?? '');
LucidValidation.global.culture = culture;
return culture;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/localization/language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ abstract class Language {
code.greaterThanDatetime: "'{PropertyName}' must be greater than date '{ComparisonValue}'.",
code.lessThanOrEqualToDateTime: "'{PropertyName}' must be less than or equal to date '{ComparisonValue}'.",
code.lessThanDateTime: "'{PropertyName}' must be less than date '{ComparisonValue}'.",
code.inclusiveBetweenDatetime: "'{PropertyName}' must be less than or equal to '{StartValue}' date and less than or equal to '{EndValue}' date.",
code.exclusiveBetweenDatetime: "'{PropertyName}' must be less than the '{StartValue}' date and less than the '{EndValue}' date."
code.inclusiveBetweenDatetime: "'{PropertyName}' must be greater than or equal to '{StartValue}' date and less than or equal to '{EndValue}' date.",
code.exclusiveBetweenDatetime: "'{PropertyName}' must be greater than the '{StartValue}' date and less than the '{EndValue}' date."
};

String? getTranslation(String key) => _translations[key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ class PortugueseBrasillianLanguage extends Language {
Language.code.validCNPJ: "'{PropertyName}' não é um CNPJ válido.",
Language.code.validCreditCard: "'{PropertyName}' não é um número de cartão de crédito válido.",
Language.code.validEmail: "'{PropertyName}' não é um endereço de e-mail válido.",
Language.code.greaterThanOrEqualToDateTime: "'{PropertyName}' deve ser maior ou igual à data '{ComparisonValue}'.",
Language.code.greaterThanDatetime: "'{PropertyName}' deve ser maior que a data '{ComparisonValue}'.",
Language.code.lessThanOrEqualToDateTime: "'{PropertyName}' deve ser menor ou igual à data '{ComparisonValue}'.",
Language.code.lessThanDateTime: "'{PropertyName}' deve ser menor que a data '{ComparisonValue}'.",
Language.code.inclusiveBetweenDatetime: "'{PropertyName}' deve ser maior ou igual à data '{StartValue}' e menor ou igual à data '{EndValue}'.",
Language.code.exclusiveBetweenDatetime: "'{PropertyName}' deve ser maior que a data '{StartValue}' e menor que a data '{EndValue}'."
});
}
6 changes: 6 additions & 0 deletions lib/src/localization/languages/spanish_language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ class SpanishLanguage extends Language {
Language.code.validCNPJ: "'{PropertyName}' no es un CNPJ válido.",
Language.code.validCreditCard: "'{PropertyName}' no es un número de tarjeta de crédito válido.",
Language.code.validEmail: "'{PropertyName}' no es una dirección de correo electrónico válida.",
Language.code.greaterThanOrEqualToDateTime: "'{PropertyName}' debe ser mayor o igual a la fecha '{ComparisonValue}'.",
Language.code.greaterThanDatetime: "'{PropertyName}' debe ser mayor que la fecha '{ComparisonValue}'.",
Language.code.lessThanOrEqualToDateTime: "'{PropertyName}' debe ser menor o igual a la fecha '{ComparisonValue}'.",
Language.code.lessThanDateTime: "'{PropertyName}' debe ser menor que la fecha '{ComparisonValue}'.",
Language.code.inclusiveBetweenDatetime: "'{PropertyName}' debe ser mayor o igual a la fecha '{StartValue}' y menor o igual a la fecha '{EndValue}'.",
Language.code.exclusiveBetweenDatetime: "'{PropertyName}' debe ser mayor que la fecha '{StartValue}' y menor que la fecha '{EndValue}'."
});
}

0 comments on commit 5fac23d

Please sign in to comment.