From 5fac23dcaac44ce6c3e3a75a992870a53af0605d Mon Sep 17 00:00:00 2001 From: wellgenio Date: Thu, 29 Aug 2024 09:34:28 -0300 Subject: [PATCH] Update doc --- README.md | 13 +++++++++++++ example/lib/main.dart | 7 +++---- lib/src/localization/language.dart | 4 ++-- .../languages/portuguese_brazillian_language.dart | 6 ++++++ .../localization/languages/spanish_language.dart | 6 ++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 49996cb..e2865d8 100644 --- a/README.md +++ b/README.md @@ -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, }); } @@ -44,6 +46,8 @@ import 'package:lucid_validation/lucid_validation.dart'; class UserValidator extends LucidValidator { UserValidator() { + final now = DateTime.now(); + ruleFor((user) => user.email, key: 'email') .notEmpty() .validEmail(); @@ -58,6 +62,9 @@ class UserValidator extends LucidValidator { 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)); } } @@ -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 diff --git a/example/lib/main.dart b/example/lib/main.dart index 70e5e43..ffa56e7 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -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}); @@ -29,7 +29,7 @@ class MyApp extends StatelessWidget { Locale('en', 'US'), Locale('pt', 'BR'), ], - localizationsDelegates: [ + localizationsDelegates: const [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, @@ -49,7 +49,7 @@ class MyApp extends StatelessWidget { class LucidLocalizationDelegate extends LocalizationsDelegate { const LucidLocalizationDelegate(); - static final delegate = LucidLocalizationDelegate(); + static const delegate = LucidLocalizationDelegate(); @override bool isSupported(Locale locale) { @@ -61,7 +61,6 @@ class LucidLocalizationDelegate extends LocalizationsDelegate { @override Future load(Locale locale) async { - print(locale); final culture = Culture(locale.languageCode, locale.countryCode ?? ''); LucidValidation.global.culture = culture; return culture; diff --git a/lib/src/localization/language.dart b/lib/src/localization/language.dart index ffabf9b..c9f0439 100644 --- a/lib/src/localization/language.dart +++ b/lib/src/localization/language.dart @@ -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]; diff --git a/lib/src/localization/languages/portuguese_brazillian_language.dart b/lib/src/localization/languages/portuguese_brazillian_language.dart index 22fe282..55c090f 100644 --- a/lib/src/localization/languages/portuguese_brazillian_language.dart +++ b/lib/src/localization/languages/portuguese_brazillian_language.dart @@ -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}'." }); } diff --git a/lib/src/localization/languages/spanish_language.dart b/lib/src/localization/languages/spanish_language.dart index 82749fa..a2fafef 100644 --- a/lib/src/localization/languages/spanish_language.dart +++ b/lib/src/localization/languages/spanish_language.dart @@ -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}'." }); }