├── .github └── workflows │ ├── ci.yaml │ └── publish.yml ├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── example │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable-v21 │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── values-night │ │ │ │ └── styles.xml │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ ├── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ │ ├── Icon-App-20x20@1x.png │ │ │ │ ├── Icon-App-20x20@2x.png │ │ │ │ ├── Icon-App-20x20@3x.png │ │ │ │ ├── Icon-App-29x29@1x.png │ │ │ │ ├── Icon-App-29x29@2x.png │ │ │ │ ├── Icon-App-29x29@3x.png │ │ │ │ ├── Icon-App-40x40@1x.png │ │ │ │ ├── Icon-App-40x40@2x.png │ │ │ │ ├── Icon-App-40x40@3x.png │ │ │ │ ├── Icon-App-60x60@2x.png │ │ │ │ ├── Icon-App-60x60@3x.png │ │ │ │ ├── Icon-App-76x76@1x.png │ │ │ │ ├── Icon-App-76x76@2x.png │ │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ │ └── LaunchImage.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── LaunchImage.png │ │ │ │ ├── LaunchImage@2x.png │ │ │ │ ├── LaunchImage@3x.png │ │ │ │ └── README.md │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h │ └── RunnerTests │ │ └── RunnerTests.swift ├── lib │ ├── domain │ │ ├── dtos │ │ │ ├── login_param_dto.dart │ │ │ └── register_param_dto.dart │ │ └── validations │ │ │ ├── extensions.dart │ │ │ ├── language_manager.dart │ │ │ ├── login_param_validation.dart │ │ │ └── register_param_validation.dart │ ├── main.dart │ └── presentation │ │ ├── login_page │ │ └── login_page.dart │ │ └── register_page │ │ └── register_page.dart ├── linux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── main.cc │ ├── my_application.cc │ └── my_application.h ├── macos │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ └── GeneratedPluginRegistrant.swift │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── app_icon_1024.png │ │ │ │ ├── app_icon_128.png │ │ │ │ ├── app_icon_16.png │ │ │ │ ├── app_icon_256.png │ │ │ │ ├── app_icon_32.png │ │ │ │ ├── app_icon_512.png │ │ │ │ └── app_icon_64.png │ │ ├── Base.lproj │ │ │ └── MainMenu.xib │ │ ├── Configs │ │ │ ├── AppInfo.xcconfig │ │ │ ├── Debug.xcconfig │ │ │ ├── Release.xcconfig │ │ │ └── Warnings.xcconfig │ │ ├── DebugProfile.entitlements │ │ ├── Info.plist │ │ ├── MainFlutterWindow.swift │ │ └── Release.entitlements │ └── RunnerTests │ │ └── RunnerTests.swift ├── pubspec.lock ├── pubspec.yaml ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── index.html │ └── manifest.json └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake │ └── runner │ ├── CMakeLists.txt │ ├── Runner.rc │ ├── flutter_window.cpp │ ├── flutter_window.h │ ├── main.cpp │ ├── resource.h │ ├── resources │ └── app_icon.ico │ ├── runner.exe.manifest │ ├── utils.cpp │ ├── utils.h │ ├── win32_window.cpp │ └── win32_window.h ├── lib ├── lucid_validation.dart └── src │ ├── localization │ ├── culture.dart │ ├── language.dart │ ├── language_manager.dart │ ├── languages │ │ ├── english_language.dart │ │ ├── portuguese_brazillian_language.dart │ │ └── spanish_language.dart │ └── localization.dart │ ├── lucid_validation_builder.dart │ ├── lucid_validator.dart │ ├── types │ ├── types.dart │ ├── validation_exception.dart │ └── validation_result.dart │ ├── utils │ └── utils.dart │ └── validations │ ├── equal_validation.dart │ ├── exclusive_between_datetime_validation.dart │ ├── greater_than_datetime_validation.dart │ ├── greater_than_or_equal_to_datetime_validation.dart │ ├── greater_than_validation.dart │ ├── inclusive_between_datetime_validation.dart │ ├── is_empty_validation.dart │ ├── is_not_null_validation.dart │ ├── is_null_validation.dart │ ├── less_than_datetime_validation.dart │ ├── less_than_or_equal_to_datetime_validation.dart │ ├── less_then_validation.dart │ ├── matches_pattern_validation.dart │ ├── max_length_validation.dart │ ├── max_validation.dart │ ├── min_length_validation.dart │ ├── min_validation.dart │ ├── must_have_lowercase_validation.dart │ ├── must_have_number_validation.dart │ ├── must_have_special_character_validation.dart │ ├── must_have_uppercase_validation.dart │ ├── not_empty_validation.dart │ ├── not_equal_validation.dart │ ├── range_validation.dart │ ├── repeated_characters_validation.dart │ ├── sequential_characters_validation.dart │ ├── valid_cep_validation.dart │ ├── valid_cnpj_validation.dart │ ├── valid_cpf_or_cnpj_validation.dart │ ├── valid_cpf_validation.dart │ ├── valid_creditcard_validation.dart │ ├── valid_email_validation.dart │ ├── valid_phone_validation.dart │ └── validations.dart ├── pubspec.yaml └── test ├── byfield_validation_test.dart ├── list_validations_test.dart ├── lucid_validation_test.dart ├── mocks └── mocks.dart └── src └── validations ├── equal_validation_test.dart ├── exclusive_between_datetime_validation_test.dart ├── greater_than_datetime_validation_test.dart ├── greater_than_or_equal_to_datetime_validation_test.dart ├── greater_than_validation_test.dart ├── inclusive_between_datetime_validation_test.dart ├── is_empty_validation_test.dart ├── is_not_null_validation_test.dart ├── is_null_validation_test.dart ├── less_than_datetime_validation_test.dart ├── less_than_or_equal_to_datetime_validation_test.dart ├── less_then_validation_test.dart ├── matches_pattern_validation_test.dart ├── max_length_validation_test.dart ├── max_validation_test.dart ├── min_length_validation_test.dart ├── min_validation_test.dart ├── must_have_lowercase_validation_test.dart ├── must_have_number_validation_test.dart ├── must_have_special_character_validation_test.dart ├── must_have_uppercase_validation_test.dart ├── not_empty_validation_test.dart ├── not_equal_validation_test.dart ├── range_validation_test.dart ├── repeated_characters_validation_test.dart ├── sequential_characters_validation_test.dart ├── valid_cep_validation_test.dart ├── valid_cnpj_validation_test.dart ├── valid_cpf_or_cnpj_validation_test.dart ├── valid_cpf_validation_test.dart ├── valid_creditcard_validation_test.dart ├── valid_email_validation_test.dart └── valid_phone_validation_test.dart /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | # name: Flutter CI 2 | 3 | # on: 4 | # push: 5 | # branches: [main] 6 | # pull_request: 7 | # branches: [main] 8 | 9 | # jobs: 10 | # build: 11 | # runs-on: ubuntu-latest 12 | # steps: 13 | # - name: Checkout repository 14 | # uses: actions/checkout@v3 15 | 16 | # - name: Set up Flutter 17 | # uses: subosito/flutter-action@v2 18 | # with: 19 | # channel: stable 20 | 21 | # - name: Install dependencies 22 | # run: flutter pub get 23 | 24 | # - name: Run Analyze 25 | # run: flutter analyze --no-fatal-infos ./lib/**/*.dart ./test/**/*.dart 26 | 27 | # - name: Check format 28 | # run: dart format --set-exit-if-changed ./lib ./test 29 | 30 | # - name: Run tests 31 | # run: flutter test --coverage 32 | 33 | # - name: Upload coverage reports to Codecov 34 | # uses: codecov/codecov-action@v4.0.1 35 | # with: 36 | # token: ${{ secrets.CODECOV_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | # .github/workflows/publish.yml 2 | name: Publish to pub.dev 3 | 4 | on: 5 | push: 6 | tags: 7 | - 'v[0-9]+.[0-9]+.[0-9]+*' 8 | 9 | jobs: 10 | publish: 11 | permissions: 12 | id-token: write 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | - uses: dart-lang/setup-dart@v1 17 | - name: Set up Flutter 18 | uses: subosito/flutter-action@v2 19 | with: 20 | channel: stable 21 | 22 | - name: Install dependencies 23 | run: flutter pub get 24 | 25 | - name: Publish 26 | run: dart pub publish --force -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | build/ 30 | coverage/ 31 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49" 8 | channel: "stable" 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.3.1 2 | 3 | * Added nullable support for phone number validation 4 | 5 | ## 1.3.0 6 | 7 | * Added support for list validation using `setEach`, allowing nested validators with index-aware error reporting. 8 | 9 | ## 1.2.7 10 | 11 | * Aded hasNoSequentialRepeatedCharacters and hasNoSequentialCharacters 12 | 13 | ## 1.2.6 14 | 15 | * Aded validPhoneWithCountryCodeBR and validPhoneBR 16 | 17 | ## 1.2.5 18 | 19 | * Aded Exception serialization 20 | 21 | ## 1.2.4 22 | 23 | * Fix overrideCallback in byField 24 | 25 | ## 1.2.3 26 | 27 | * Added overrideCallback in byField 28 | 29 | ## 1.2.2 30 | 31 | * Added validCPFOrCNPJ 32 | 33 | ## 1.2.1 34 | 35 | * Added getExceptions and getExceptionsByKey 36 | 37 | ## 1.2.0 38 | 39 | * Added support nullable 40 | 41 | ## 1.1.0 42 | 43 | * Added Label 44 | 45 | ## 1.0.1 46 | 47 | * Added valid greaterThanOrEqualTo, greaterThan, lessThanOrEqualTo, lessThan, inclusiveBetween and exclusiveBetween 48 | 49 | ## 1.0.0 50 | 51 | * Production release 52 | 53 | ## 0.0.7 54 | 55 | * Added `when` and `setValidator` 56 | 57 | ## 0.0.5 58 | 59 | * Added must and mustWith 60 | 61 | ## 0.0.3 62 | 63 | * Added Cascade Mode 64 | 65 | ## 0.0.2 66 | 67 | * Added valid CEP, CNPJ and CreditCard 68 | 69 | ## 0.0.1+1 70 | 71 | * Initial Release 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | License Copyright: Flutterando. 3 | License License: Flutterando. 4 | License Contact: Flutterando. 5 | SPDX short identifier: MIT 6 | Further resources... 7 | 8 | Begin license text. 9 | Copyright 2023 Flutterando 10 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | End license text. -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:lints/recommended.yaml 2 | # Additional information about this file can be found at 3 | # https://dart.dev/guides/language/analysis-options 4 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .build/ 9 | .buildlog/ 10 | .history 11 | .svn/ 12 | .swiftpm/ 13 | migrate_working_dir/ 14 | 15 | # IntelliJ related 16 | *.iml 17 | *.ipr 18 | *.iws 19 | .idea/ 20 | 21 | # The .vscode folder contains launch configuration and tasks you configure in 22 | # VS Code which you may wish to be included in version control, so this line 23 | # is commented out by default. 24 | #.vscode/ 25 | 26 | # Flutter/Dart/Pub related 27 | **/doc/api/ 28 | **/ios/Flutter/.last_build_id 29 | .dart_tool/ 30 | .flutter-plugins 31 | .flutter-plugins-dependencies 32 | .pub-cache/ 33 | .pub/ 34 | /build/ 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | 42 | # Android Studio will place build artifacts here 43 | /android/app/debug 44 | /android/app/profile 45 | /android/app/release 46 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: "80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819" 8 | channel: "stable" 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 17 | base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 18 | - platform: android 19 | create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 20 | base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 21 | - platform: ios 22 | create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 23 | base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 24 | - platform: linux 25 | create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 26 | base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 27 | - platform: macos 28 | create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 29 | base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 30 | - platform: web 31 | create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 32 | base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 33 | - platform: windows 34 | create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 35 | base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 36 | 37 | # User provided section 38 | 39 | # List of Local paths (relative to this file) that should be 40 | # ignored by the migrate tool. 41 | # 42 | # Files that are not part of the templates will be ignored by default. 43 | unmanaged_files: 44 | - 'lib/main.dart' 45 | - 'ios/Runner.xcodeproj/project.pbxproj' 46 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Lucid Validation Example 2 | 3 | Check this! 4 | 5 | 6 | ```dart 7 | import 'package:lucid_validation/lucid_validation.dart'; 8 | 9 | class UserModel { 10 | String email; 11 | String password; 12 | int age; 13 | 14 | UserModel({ 15 | required this.email, 16 | required this.password, 17 | required this.age, 18 | }); 19 | } 20 | 21 | class UserValidation extends LucidValidation { 22 | UserValidation() { 23 | ruleFor((user) => user.email, key: 'email') 24 | .notEmpty() 25 | .validEmail(); 26 | 27 | ruleFor((user) => user.password, key: 'password') 28 | .notEmpty() 29 | .minLength(8, message: 'Must be at least 8 characters long') 30 | .mustHaveLowercase() 31 | .mustHaveUppercase() 32 | .mustHaveNumbers() 33 | .mustHaveSpecialCharacter(); 34 | 35 | ruleFor((user) => user.age, key: 'age') 36 | .min(18, message: 'Minimum age is 18 years'); 37 | } 38 | } 39 | 40 | void main() { 41 | final user = UserModel(email: 'test@example.com', password: 'Passw0rd!', age: 25); 42 | final validator = UserValidation(); 43 | 44 | final errors = validator.validate(user); 45 | 46 | if (errors.isEmpty) { 47 | print('User is valid'); 48 | } else { 49 | print('Validation errors: ${errors.map((e) => e.message).join(', ')}'); 50 | } 51 | } 52 | 53 | ``` 54 | 55 | ## Flutter Integration 56 | 57 | ```dart 58 | import 'package:flutter/material.dart'; 59 | import 'package:lucid_validation/lucid_validation.dart'; 60 | 61 | class LoginForm extends StatelessWidget { 62 | final validator = UserValidation(); 63 | 64 | @override 65 | Widget build(BuildContext context) { 66 | return Form( 67 | child: Column( 68 | children: [ 69 | TextFormField( 70 | decoration: const InputDecoration(hintText: 'Email'), 71 | validator: validator.byField('email'), 72 | ), 73 | TextFormField( 74 | decoration: const InputDecoration(hintText: 'Password'), 75 | validator: validator.byField('password'), 76 | obscureText: true, 77 | ), 78 | ], 79 | ), 80 | ); 81 | } 82 | } 83 | 84 | ``` -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at https://dart.dev/lints. 17 | # 18 | # Instead of disabling a lint rule for the entire project in the 19 | # section below, it can also be suppressed for a single line of code 20 | # or a specific dart file by using the `// ignore: name_of_lint` and 21 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 22 | # producing the lint. 23 | rules: 24 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 25 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 26 | 27 | # Additional information about this file can be found at 28 | # https://dart.dev/guides/language/analysis-options 29 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/to/reference-keystore 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "com.android.application" 3 | id "kotlin-android" 4 | // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. 5 | id "dev.flutter.flutter-gradle-plugin" 6 | } 7 | 8 | android { 9 | namespace = "com.example.example" 10 | compileSdk = flutter.compileSdkVersion 11 | ndkVersion = flutter.ndkVersion 12 | 13 | compileOptions { 14 | sourceCompatibility = JavaVersion.VERSION_1_8 15 | targetCompatibility = JavaVersion.VERSION_1_8 16 | } 17 | 18 | kotlinOptions { 19 | jvmTarget = JavaVersion.VERSION_1_8 20 | } 21 | 22 | defaultConfig { 23 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 24 | applicationId = "com.example.example" 25 | // You can update the following values to match your application needs. 26 | // For more information, see: https://flutter.dev/to/review-gradle-config. 27 | minSdk = flutter.minSdkVersion 28 | targetSdk = flutter.targetSdkVersion 29 | versionCode = flutter.versionCode 30 | versionName = flutter.versionName 31 | } 32 | 33 | buildTypes { 34 | release { 35 | // TODO: Add your own signing config for the release build. 36 | // Signing with the debug keys for now, so `flutter run --release` works. 37 | signingConfig = signingConfigs.debug 38 | } 39 | } 40 | } 41 | 42 | flutter { 43 | source = "../.." 44 | } 45 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | } 7 | 8 | rootProject.buildDir = "../build" 9 | subprojects { 10 | project.buildDir = "${rootProject.buildDir}/${project.name}" 11 | } 12 | subprojects { 13 | project.evaluationDependsOn(":app") 14 | } 15 | 16 | tasks.register("clean", Delete) { 17 | delete rootProject.buildDir 18 | } 19 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip 6 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | def flutterSdkPath = { 3 | def properties = new Properties() 4 | file("local.properties").withInputStream { properties.load(it) } 5 | def flutterSdkPath = properties.getProperty("flutter.sdk") 6 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 7 | return flutterSdkPath 8 | }() 9 | 10 | includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") 11 | 12 | repositories { 13 | google() 14 | mavenCentral() 15 | gradlePluginPortal() 16 | } 17 | } 18 | 19 | plugins { 20 | id "dev.flutter.flutter-plugin-loader" version "1.0.0" 21 | id "com.android.application" version "7.3.0" apply false 22 | id "org.jetbrains.kotlin.android" version "1.7.10" apply false 23 | } 24 | 25 | include ":app" 26 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 12.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 64 | 66 | 72 | 73 | 74 | 75 | 81 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Flutter 2 | import UIKit 3 | 4 | @main 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | CADisableMinimumFrameDurationOnPhone 45 | 46 | UIApplicationSupportsIndirectInputEvents 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/ios/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Flutter 2 | import UIKit 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /example/lib/domain/dtos/login_param_dto.dart: -------------------------------------------------------------------------------- 1 | class LoginParamDto { 2 | String email; 3 | String password; 4 | 5 | LoginParamDto({ 6 | required this.email, 7 | required this.password, 8 | }); 9 | 10 | factory LoginParamDto.empty() => LoginParamDto(email: '', password: ''); 11 | 12 | setEmail(String value) => email = value; 13 | 14 | setPassword(String value) => password = value; 15 | } 16 | -------------------------------------------------------------------------------- /example/lib/domain/dtos/register_param_dto.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class RegisterParamDto extends ChangeNotifier { 4 | String _email; 5 | String _phone; 6 | String _password; 7 | String _confirmPassword; 8 | 9 | String get email => _email; 10 | String get phone => _phone; 11 | String get password => _password; 12 | String get confirmPassword => _confirmPassword; 13 | 14 | RegisterParamDto({ 15 | required String email, 16 | required String phone, 17 | required String password, 18 | required String confirmPassword, 19 | }) : _email = email, 20 | _phone = phone, 21 | _password = password, 22 | _confirmPassword = confirmPassword; 23 | 24 | factory RegisterParamDto.empty() => 25 | RegisterParamDto(email: '', password: '', phone: '', confirmPassword: ''); 26 | 27 | void setEmail(String value) { 28 | _email = value; 29 | notifyListeners(); 30 | } 31 | 32 | void setPassword(String value) { 33 | _password = value; 34 | notifyListeners(); 35 | } 36 | 37 | void setConfirmPassword(String value) { 38 | _confirmPassword = value; 39 | notifyListeners(); 40 | } 41 | 42 | void setPhone(String value) { 43 | _phone = value; 44 | notifyListeners(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/lib/domain/validations/extensions.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | 3 | extension CustomValidPasswordValidator on SimpleValidationBuilder { 4 | SimpleValidationBuilder customValidPassword() { 5 | return notEmpty() // 6 | .minLength(5) 7 | .mustHaveLowercase() 8 | .mustHaveUppercase() 9 | .mustHaveNumber() 10 | .mustHaveSpecialCharacter(); 11 | } 12 | } 13 | 14 | extension CustomValidPhoneValidator on SimpleValidationBuilder { 15 | SimpleValidationBuilder customValidPhone({ 16 | String code = 'validPhone', 17 | required String message, 18 | }) { 19 | return use((value, entity) { 20 | final regex = RegExp( 21 | r'^\(?(\d{2})\)?\s?9?\d{4}-?\d{4}$', 22 | caseSensitive: false, 23 | ); 24 | 25 | if (regex.hasMatch(value)) { 26 | return null; 27 | } 28 | 29 | return ValidationException( 30 | message: message, 31 | code: code, 32 | key: key, 33 | entity: extractClassName(entity.toString()), 34 | ); 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /example/lib/domain/validations/language_manager.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | 3 | class CustomLanguageManager extends LanguageManager { 4 | CustomLanguageManager() { 5 | addTranslation(Culture('pt', 'BR'), 'passwordEqualTo', 6 | "'{PropertyName}' deve ser igual."); 7 | addTranslation( 8 | Culture('pt'), 'passwordEqualTo', "'{PropertyName}' deve ser igual."); 9 | addTranslation(Culture('en', 'US'), 'passwordEqualTo', 10 | "'{PropertyName}' must be equal."); 11 | addTranslation( 12 | Culture('en'), 'passwordEqualTo', "'{PropertyName}' must be equal."); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/lib/domain/validations/login_param_validation.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/domain/dtos/login_param_dto.dart'; 2 | import 'package:example/domain/validations/extensions.dart'; 3 | import 'package:lucid_validation/lucid_validation.dart'; 4 | 5 | class LoginParamValidation extends LucidValidator { 6 | LoginParamValidation() { 7 | ruleFor((loginParamDto) => loginParamDto.email, key: 'email') // 8 | .notEmpty() 9 | .validEmail(); 10 | 11 | ruleFor((loginParamDto) => loginParamDto.password, key: 'password') // 12 | .customValidPassword(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/lib/domain/validations/register_param_validation.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/domain/dtos/register_param_dto.dart'; 2 | import 'package:example/domain/validations/extensions.dart'; 3 | import 'package:lucid_validation/lucid_validation.dart'; 4 | 5 | class RegisterParamValidation extends LucidValidator { 6 | RegisterParamValidation() { 7 | ruleFor((registerParamDto) => registerParamDto.email, key: 'email') // 8 | .notEmpty() 9 | .validEmail(); 10 | 11 | ruleFor((registerParamDto) => registerParamDto.password, key: 'password') // 12 | .customValidPassword(); 13 | 14 | ruleFor((registerParamDto) => registerParamDto.confirmPassword, 15 | key: 'confirmPassword') // 16 | .customValidPassword() 17 | .equalTo((registerParamDto) => registerParamDto.password, 18 | code: 'passwordEqualTo', message: 'As senhas devem ser iguais'); 19 | 20 | ruleFor((registerParamDto) => registerParamDto.phone, key: 'phone') // 21 | .customValidPhone(message: 'Digite um celular valido'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/presentation/login_page/login_page.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_localizations/flutter_localizations.dart'; 4 | import 'package:lucid_validation/lucid_validation.dart'; 5 | 6 | import 'domain/validations/language_manager.dart'; 7 | 8 | void main() { 9 | LucidValidation.global.languageManager = CustomLanguageManager(); 10 | 11 | runApp(const MyApp()); 12 | } 13 | 14 | final globalLocale = ValueNotifier(const Locale('en')); 15 | 16 | class MyApp extends StatelessWidget { 17 | const MyApp({super.key}); 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return ValueListenableBuilder( 22 | valueListenable: globalLocale, 23 | builder: (context, value, child) { 24 | return MaterialApp( 25 | debugShowCheckedModeBanner: false, 26 | title: 'Flutter Demo', 27 | locale: value, 28 | supportedLocales: const [ 29 | Locale('en', 'US'), 30 | Locale('pt', 'BR'), 31 | ], 32 | localizationsDelegates: const [ 33 | GlobalMaterialLocalizations.delegate, 34 | GlobalWidgetsLocalizations.delegate, 35 | GlobalCupertinoLocalizations.delegate, 36 | LucidLocalizationDelegate.delegate, 37 | ], 38 | theme: ThemeData( 39 | colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), 40 | useMaterial3: true, 41 | ), 42 | home: const LoginPage(), 43 | ); 44 | }, 45 | ); 46 | } 47 | } 48 | 49 | class LucidLocalizationDelegate extends LocalizationsDelegate { 50 | const LucidLocalizationDelegate(); 51 | 52 | static const delegate = LucidLocalizationDelegate(); 53 | 54 | @override 55 | bool isSupported(Locale locale) { 56 | return LucidValidation.global.languageManager.isSupported( 57 | locale.languageCode, 58 | locale.countryCode, 59 | ); 60 | } 61 | 62 | @override 63 | Future load(Locale locale) async { 64 | final culture = Culture(locale.languageCode, locale.countryCode ?? ''); 65 | LucidValidation.global.culture = culture; 66 | return culture; 67 | } 68 | 69 | @override 70 | bool shouldReload(LocalizationsDelegate old) { 71 | return true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /example/lib/presentation/login_page/login_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/domain/dtos/login_param_dto.dart'; 2 | import 'package:example/domain/validations/login_param_validation.dart'; 3 | import 'package:example/main.dart'; 4 | import 'package:example/presentation/register_page/register_page.dart'; 5 | import 'package:flutter/material.dart'; 6 | 7 | class LoginPage extends StatefulWidget { 8 | const LoginPage({super.key}); 9 | 10 | @override 11 | State createState() => _LoginPageState(); 12 | } 13 | 14 | class _LoginPageState extends State { 15 | final validator = LoginParamValidation(); 16 | final loginParamDto = LoginParamDto.empty(); 17 | final formKey = GlobalKey(); 18 | 19 | void signIn() { 20 | final snackBarSuccess = SnackBar( 21 | behavior: SnackBarBehavior.floating, 22 | backgroundColor: Colors.green, 23 | margin: EdgeInsets.only( 24 | bottom: MediaQuery.sizeOf(context).height * 0.8, 25 | left: 12, 26 | right: 12, 27 | ), 28 | content: const Text('logged in'), 29 | ); 30 | 31 | if (formKey.currentState!.validate()) { 32 | ScaffoldMessenger.of(context).showSnackBar(snackBarSuccess); 33 | } 34 | } 35 | 36 | @override 37 | Widget build(BuildContext context) { 38 | return Scaffold( 39 | appBar: AppBar( 40 | title: const Text('Login'), 41 | actions: [ 42 | Row( 43 | mainAxisSize: MainAxisSize.min, 44 | children: [ 45 | Text('Is English'), 46 | ValueListenableBuilder( 47 | valueListenable: globalLocale, 48 | builder: (context, _, __) { 49 | return Switch( 50 | value: globalLocale.value.languageCode == 'en', 51 | onChanged: (value) { 52 | globalLocale.value = 53 | value ? Locale('en', 'US') : Locale('pt', 'BR'); 54 | }, 55 | ); 56 | }), 57 | ], 58 | ) 59 | ], 60 | ), 61 | body: Form( 62 | key: formKey, 63 | child: Padding( 64 | padding: const EdgeInsets.all(12.0), 65 | child: Column( 66 | children: [ 67 | const Spacer(), 68 | const Text( 69 | 'Login', 70 | style: TextStyle(fontWeight: FontWeight.w800, fontSize: 24), 71 | ), 72 | const SizedBox(height: 24), 73 | TextFormField( 74 | autovalidateMode: AutovalidateMode.onUserInteraction, 75 | onChanged: loginParamDto.setEmail, 76 | validator: validator.byField(loginParamDto, 'email'), 77 | decoration: const InputDecoration( 78 | hintText: 'Email', 79 | ), 80 | ), 81 | const SizedBox(height: 12), 82 | TextFormField( 83 | autovalidateMode: AutovalidateMode.onUserInteraction, 84 | onChanged: loginParamDto.setPassword, 85 | validator: validator.byField(loginParamDto, 'password'), 86 | obscureText: true, 87 | decoration: const InputDecoration( 88 | hintText: 'Password', 89 | ), 90 | ), 91 | const SizedBox(height: 12), 92 | ElevatedButton( 93 | onPressed: signIn, 94 | child: const Text('Sign In'), 95 | ), 96 | const SizedBox(height: 12), 97 | ElevatedButton( 98 | onPressed: () { 99 | Navigator.push( 100 | context, 101 | MaterialPageRoute( 102 | builder: (context) => const RegisterPage()), 103 | ); 104 | }, 105 | child: const Text('Sign up'), 106 | ), 107 | const Spacer(), 108 | ], 109 | ), 110 | ), 111 | ), 112 | ); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @main 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2024 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: "A new Flutter project." 3 | # The following line prevents the package from being accidentally published to 4 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 5 | publish_to: "none" # Remove this line if you wish to publish to pub.dev 6 | 7 | # The following defines the version and build number for your application. 8 | # A version number is three numbers separated by dots, like 1.2.43 9 | # followed by an optional build number separated by a +. 10 | # Both the version and the builder number may be overridden in flutter 11 | # build by specifying --build-name and --build-number, respectively. 12 | # In Android, build-name is used as versionName while build-number used as versionCode. 13 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 14 | # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. 15 | # Read more about iOS versioning at 16 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 17 | # In Windows, build-name is used as the major, minor, and patch parts 18 | # of the product and file versions while build-number is used as the build suffix. 19 | version: 1.0.0+1 20 | 21 | environment: 22 | sdk: ">=3.4.3 <4.0.0" 23 | 24 | # Dependencies specify other packages that your package needs in order to work. 25 | # To automatically upgrade your package dependencies to the latest versions 26 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 27 | # dependencies can be manually updated by changing the version numbers below to 28 | # the latest version available on pub.dev. To see which dependencies have newer 29 | # versions available, run `flutter pub outdated`. 30 | dependencies: 31 | flutter: 32 | sdk: flutter 33 | flutter_localizations: 34 | sdk: flutter 35 | lucid_validation: 36 | path: ../ 37 | 38 | # The following adds the Cupertino Icons font to your application. 39 | # Use with the CupertinoIcons class for iOS style icons. 40 | cupertino_icons: ^1.0.6 41 | 42 | dev_dependencies: 43 | flutter_test: 44 | sdk: flutter 45 | 46 | # The "flutter_lints" package below contains a set of recommended lints to 47 | # encourage good coding practices. The lint set provided by the package is 48 | # activated in the `analysis_options.yaml` file located at the root of your 49 | # package. See that file for information about deactivating specific lint 50 | # rules and activating additional ones. 51 | flutter_lints: ^3.0.0 52 | 53 | # For information on the generic Dart part of this file, see the 54 | # following page: https://dart.dev/tools/pub/pubspec 55 | 56 | # The following section is specific to Flutter packages. 57 | flutter: 58 | # The following line ensures that the Material Icons font is 59 | # included with your application, so that you can use the icons in 60 | # the material Icons class. 61 | uses-material-design: true 62 | 63 | # To add assets to your application, add an assets section, like this: 64 | # assets: 65 | # - images/a_dot_burr.jpeg 66 | # - images/a_dot_ham.jpeg 67 | 68 | # An image asset can refer to one or more resolution-specific "variants", see 69 | # https://flutter.dev/assets-and-images/#resolution-aware 70 | 71 | # For details regarding adding assets from package dependencies, see 72 | # https://flutter.dev/assets-and-images/#from-packages 73 | 74 | # To add custom fonts to your application, add a fonts section here, 75 | # in this "flutter" section. Each entry in this list should have a 76 | # "family" key with the font family name, and a "fonts" key with a 77 | # list giving the asset and other descriptors for the font. For 78 | # example: 79 | # fonts: 80 | # - family: Schyler 81 | # fonts: 82 | # - asset: fonts/Schyler-Regular.ttf 83 | # - asset: fonts/Schyler-Italic.ttf 84 | # style: italic 85 | # - family: Trajan Pro 86 | # fonts: 87 | # - asset: fonts/TrajanPro.ttf 88 | # - asset: fonts/TrajanPro_Bold.ttf 89 | # weight: 700 90 | # 91 | # For details regarding fonts from package dependencies, 92 | # see https://flutter.dev/custom-fonts/#from-packages 93 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(example LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(VERSION 3.14...3.25) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | 56 | # Generated plugin build rules, which manage building the plugins and adding 57 | # them to the application. 58 | include(flutter/generated_plugins.cmake) 59 | 60 | 61 | # === Installation === 62 | # Support files are copied into place next to the executable, so that it can 63 | # run in place. This is done instead of making a separate bundle (as on Linux) 64 | # so that building and running from within Visual Studio will work. 65 | set(BUILD_BUNDLE_DIR "$") 66 | # Make the "install" step default, as it's required to run. 67 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 68 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 69 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 70 | endif() 71 | 72 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 73 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 74 | 75 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 76 | COMPONENT Runtime) 77 | 78 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 79 | COMPONENT Runtime) 80 | 81 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 82 | COMPONENT Runtime) 83 | 84 | if(PLUGIN_BUNDLED_LIBRARIES) 85 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 86 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 87 | COMPONENT Runtime) 88 | endif() 89 | 90 | # Copy the native assets provided by the build.dart from all packages. 91 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") 92 | install(DIRECTORY "${NATIVE_ASSETS_DIR}" 93 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 94 | COMPONENT Runtime) 95 | 96 | # Fully re-copy the assets directory on each build to avoid having stale files 97 | # from a previous install. 98 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 99 | install(CODE " 100 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 101 | " COMPONENT Runtime) 102 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 103 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 104 | 105 | # Install the AOT library on non-Debug builds only. 106 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 107 | CONFIGURATIONS Profile;Release 108 | COMPONENT Runtime) 109 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # Set fallback configurations for older versions of the flutter tool. 14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 15 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 16 | endif() 17 | 18 | # === Flutter Library === 19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 20 | 21 | # Published to parent scope for install step. 22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 26 | 27 | list(APPEND FLUTTER_LIBRARY_HEADERS 28 | "flutter_export.h" 29 | "flutter_windows.h" 30 | "flutter_messenger.h" 31 | "flutter_plugin_registrar.h" 32 | "flutter_texture_registrar.h" 33 | ) 34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 35 | add_library(flutter INTERFACE) 36 | target_include_directories(flutter INTERFACE 37 | "${EPHEMERAL_DIR}" 38 | ) 39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 40 | add_dependencies(flutter flutter_assemble) 41 | 42 | # === Wrapper === 43 | list(APPEND CPP_WRAPPER_SOURCES_CORE 44 | "core_implementations.cc" 45 | "standard_codec.cc" 46 | ) 47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 49 | "plugin_registrar.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 52 | list(APPEND CPP_WRAPPER_SOURCES_APP 53 | "flutter_engine.cc" 54 | "flutter_view_controller.cc" 55 | ) 56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 57 | 58 | # Wrapper sources needed for a plugin. 59 | add_library(flutter_wrapper_plugin STATIC 60 | ${CPP_WRAPPER_SOURCES_CORE} 61 | ${CPP_WRAPPER_SOURCES_PLUGIN} 62 | ) 63 | apply_standard_settings(flutter_wrapper_plugin) 64 | set_target_properties(flutter_wrapper_plugin PROPERTIES 65 | POSITION_INDEPENDENT_CODE ON) 66 | set_target_properties(flutter_wrapper_plugin PROPERTIES 67 | CXX_VISIBILITY_PRESET hidden) 68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 69 | target_include_directories(flutter_wrapper_plugin PUBLIC 70 | "${WRAPPER_ROOT}/include" 71 | ) 72 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 73 | 74 | # Wrapper sources needed for the runner. 75 | add_library(flutter_wrapper_app STATIC 76 | ${CPP_WRAPPER_SOURCES_CORE} 77 | ${CPP_WRAPPER_SOURCES_APP} 78 | ) 79 | apply_standard_settings(flutter_wrapper_app) 80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 81 | target_include_directories(flutter_wrapper_app PUBLIC 82 | "${WRAPPER_ROOT}/include" 83 | ) 84 | add_dependencies(flutter_wrapper_app flutter_assemble) 85 | 86 | # === Flutter tool backend === 87 | # _phony_ is a non-existent file to force this command to run every time, 88 | # since currently there's no way to get a full input/output list from the 89 | # flutter tool. 90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 92 | add_custom_command( 93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 95 | ${CPP_WRAPPER_SOURCES_APP} 96 | ${PHONY_OUTPUT} 97 | COMMAND ${CMAKE_COMMAND} -E env 98 | ${FLUTTER_TOOL_ENVIRONMENT} 99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 100 | ${FLUTTER_TARGET_PLATFORM} $ 101 | VERBATIM 102 | ) 103 | add_custom_target(flutter_assemble DEPENDS 104 | "${FLUTTER_LIBRARY}" 105 | ${FLUTTER_LIBRARY_HEADERS} 106 | ${CPP_WRAPPER_SOURCES_CORE} 107 | ${CPP_WRAPPER_SOURCES_PLUGIN} 108 | ${CPP_WRAPPER_SOURCES_APP} 109 | ) 110 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2024 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | // Flutter can complete the first frame before the "show window" callback is 35 | // registered. The following call ensures a frame is pending to ensure the 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. 37 | flutter_controller_->ForceRedraw(); 38 | 39 | return true; 40 | } 41 | 42 | void FlutterWindow::OnDestroy() { 43 | if (flutter_controller_) { 44 | flutter_controller_ = nullptr; 45 | } 46 | 47 | Win32Window::OnDestroy(); 48 | } 49 | 50 | LRESULT 51 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 52 | WPARAM const wparam, 53 | LPARAM const lparam) noexcept { 54 | // Give Flutter, including plugins, an opportunity to handle window messages. 55 | if (flutter_controller_) { 56 | std::optional result = 57 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 58 | lparam); 59 | if (result) { 60 | return *result; 61 | } 62 | } 63 | 64 | switch (message) { 65 | case WM_FONTCHANGE: 66 | flutter_controller_->engine()->ReloadSystemFonts(); 67 | break; 68 | } 69 | 70 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 71 | } 72 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/lucid_validation/0b11ff6b08fb7c8d55a9c92757e2398c7050d9ec/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | unsigned int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr) 51 | -1; // remove the trailing null character 52 | int input_length = (int)wcslen(utf16_string); 53 | std::string utf8_string; 54 | if (target_length == 0 || target_length > utf8_string.max_size()) { 55 | return utf8_string; 56 | } 57 | utf8_string.resize(target_length); 58 | int converted_length = ::WideCharToMultiByte( 59 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 60 | input_length, utf8_string.data(), target_length, nullptr, nullptr); 61 | if (converted_length == 0) { 62 | return std::string(); 63 | } 64 | return utf8_string; 65 | } 66 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates a win32 window with |title| that is positioned and sized using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | -------------------------------------------------------------------------------- /lib/lucid_validation.dart: -------------------------------------------------------------------------------- 1 | /// LucidValidation 2 | /// 3 | /// A Dart/Flutter package for building strongly typed validation rules, inspired by FluentValidation. 4 | /// Created by the Flutterando community, this package aims to provide a flexible and powerful way 5 | /// to validate your models in Flutter and Dart projects. 6 | /// 7 | /// ## Features 8 | /// 9 | /// - Strongly typed validation rules. 10 | /// - Fluent API for defining validations. 11 | /// - Extensible with custom validators. 12 | /// - Easy to integrate with any Dart or Flutter project. 13 | /// 14 | /// ## Example 15 | /// 16 | /// ```dart 17 | /// import 'package:lucid_validation/lucid_validation.dart'; 18 | /// 19 | /// class UserModel { 20 | /// String email; 21 | /// String password; 22 | /// int age; 23 | /// String phone; 24 | /// 25 | /// UserModel({ 26 | /// required this.email, 27 | /// required this.password, 28 | /// required this.age, 29 | /// required this.phone, 30 | /// }); 31 | /// 32 | /// factory UserModel.empty() => UserModel(email: '', password: '', age: 18, phone: ''); 33 | /// } 34 | /// 35 | /// class UserValidation extends LucidValidation { 36 | /// UserValidation() { 37 | /// ruleFor((user) => user.email, key: 'email') 38 | /// .notEmpty() 39 | /// .validEmail(); 40 | /// 41 | /// ruleFor((user) => user.password, key: 'password') 42 | /// .customValidPassword(); 43 | /// 44 | /// ruleFor((user) => user.age, key: 'age') 45 | /// .min(18, message: 'Minimum age is 18 years'); 46 | /// 47 | /// ruleFor((user) => user.phone, key: 'phone') 48 | /// .customValidPhone('Phone invalid format'); 49 | /// } 50 | /// } 51 | /// ``` 52 | /// 53 | /// For more details, check out the full documentation and examples. 54 | /// 55 | library lucid_validation; 56 | 57 | import 'lucid_validation.dart'; 58 | 59 | export 'src/localization/language_manager.dart'; 60 | export 'src/localization/localization.dart'; 61 | export 'src/lucid_validation_builder.dart'; 62 | export 'src/lucid_validator.dart'; 63 | export 'src/types/types.dart'; 64 | export 'src/validations/validations.dart'; 65 | export 'src/utils/utils.dart'; 66 | 67 | sealed class LucidValidation { 68 | static final global = _GlobalConfig( 69 | languageManager: DefaultLanguageManager(), 70 | cascadeMode: CascadeMode.continueExecution, 71 | culture: Culture('en'), 72 | ); 73 | } 74 | 75 | class _GlobalConfig { 76 | LanguageManager languageManager; 77 | Culture culture; 78 | CascadeMode cascadeMode; 79 | 80 | _GlobalConfig({ 81 | required this.languageManager, 82 | required this.cascadeMode, 83 | required this.culture, 84 | }); 85 | } 86 | -------------------------------------------------------------------------------- /lib/src/localization/culture.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: public_member_api_docs, sort_constructors_first 2 | class Culture { 3 | final String languageCode; 4 | final String countryCode; 5 | 6 | Culture(this.languageCode, [this.countryCode = '']); 7 | 8 | @override 9 | bool operator ==(covariant Culture other) { 10 | if (identical(this, other)) return true; 11 | 12 | return other.languageCode == languageCode && 13 | other.countryCode == countryCode; 14 | } 15 | 16 | @override 17 | int get hashCode => languageCode.hashCode ^ countryCode.hashCode; 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/localization/language_manager.dart: -------------------------------------------------------------------------------- 1 | import '../../lucid_validation.dart'; 2 | import 'languages/portuguese_brazillian_language.dart'; 3 | import 'languages/spanish_language.dart'; 4 | 5 | final _avaliableLanguages = { 6 | Culture('pt'): PortugueseBrasillianLanguage(), 7 | Culture('pt', 'BR'): PortugueseBrasillianLanguage(), 8 | Culture('en'): EnglishLanguage(), 9 | Culture('en', 'US'): EnglishLanguage(), 10 | Culture('en', 'UA'): EnglishLanguage(), 11 | Culture('en', 'NZ'): EnglishLanguage(), 12 | Culture('en', 'ZA'): EnglishLanguage(), 13 | Culture('en', 'GB'): EnglishLanguage(), 14 | Culture('en', 'CA'): EnglishLanguage(), 15 | Culture('en', 'AU'): EnglishLanguage(), 16 | Culture('en', 'IE'): EnglishLanguage(), 17 | Culture('en', 'IN'): EnglishLanguage(), 18 | Culture('en', 'SG'): EnglishLanguage(), 19 | Culture('en', 'PH'): EnglishLanguage(), 20 | Culture('en', 'MY'): EnglishLanguage(), 21 | Culture('en', 'PK'): EnglishLanguage(), 22 | Culture('en', 'NG'): EnglishLanguage(), 23 | Culture('en', 'KE'): EnglishLanguage(), 24 | Culture('en', 'GH'): EnglishLanguage(), 25 | Culture('en', 'UG'): EnglishLanguage(), 26 | Culture('en', 'TT'): EnglishLanguage(), 27 | Culture('es'): SpanishLanguage(), 28 | Culture('es', 'ES'): SpanishLanguage(), 29 | Culture('es', 'MX'): SpanishLanguage(), 30 | Culture('es', 'AR'): SpanishLanguage(), 31 | Culture('es', 'CR'): SpanishLanguage(), 32 | Culture('es', 'DO'): SpanishLanguage(), 33 | Culture('es', 'CO'): SpanishLanguage(), 34 | Culture('es', 'CL'): SpanishLanguage(), 35 | Culture('es', 'PY'): SpanishLanguage(), 36 | Culture('es', 'SV'): SpanishLanguage(), 37 | Culture('es', 'NI'): SpanishLanguage(), 38 | Culture('es', 'GT'): SpanishLanguage(), 39 | Culture('es', 'PA'): SpanishLanguage(), 40 | Culture('es', 'VE'): SpanishLanguage(), 41 | Culture('es', 'PE'): SpanishLanguage(), 42 | Culture('es', 'EC'): SpanishLanguage(), 43 | Culture('es', 'UY'): SpanishLanguage(), 44 | Culture('es', 'PO'): SpanishLanguage(), 45 | Culture('es', 'HN'): SpanishLanguage(), 46 | Culture('es', 'PR'): SpanishLanguage(), 47 | }; 48 | 49 | abstract class LanguageManager { 50 | final _globalTranslations = >{}; 51 | 52 | void addTranslation(Culture culture, String code, String value) { 53 | if (!_globalTranslations.containsKey(culture)) { 54 | _globalTranslations[culture] = {}; 55 | } 56 | _globalTranslations[culture]![code] = value; 57 | } 58 | 59 | List avaliableCultures() { 60 | return _avaliableLanguages.keys.toList(); 61 | } 62 | 63 | bool isSupported(String languageCode, String? countryCode) { 64 | return _avaliableLanguages 65 | .containsKey(Culture(languageCode, countryCode ?? '')); 66 | } 67 | 68 | String translate(String key, 69 | {Map parameters = const {}, String? defaultMessage}) { 70 | final culture = LucidValidation.global.culture; 71 | final currentLanguage = getLanguage(culture); 72 | final translations = _globalTranslations[culture] ?? {}; 73 | var message = defaultMessage ?? 74 | translations[key] ?? 75 | currentLanguage.getTranslation(key) ?? 76 | key; 77 | for (var key in parameters.keys) { 78 | final value = parameters[key]!; 79 | message = message.replaceAll('{$key}', value); 80 | } 81 | return message; 82 | } 83 | 84 | Language getLanguage(Culture culture) { 85 | return _avaliableLanguages[culture] ?? _avaliableLanguages[Culture('en')]!; 86 | } 87 | } 88 | 89 | class DefaultLanguageManager extends LanguageManager {} 90 | -------------------------------------------------------------------------------- /lib/src/localization/languages/english_language.dart: -------------------------------------------------------------------------------- 1 | import '../language.dart'; 2 | 3 | class EnglishLanguage extends Language { 4 | EnglishLanguage(); 5 | } 6 | -------------------------------------------------------------------------------- /lib/src/localization/languages/portuguese_brazillian_language.dart: -------------------------------------------------------------------------------- 1 | import '../language.dart'; 2 | 3 | class PortugueseBrasillianLanguage extends Language { 4 | PortugueseBrasillianLanguage() 5 | : super({ 6 | Language.code.equalTo: 7 | "'{PropertyName}' deve ser igual a '{ComparisonValue}'.", 8 | Language.code.greaterThan: 9 | "'{PropertyName}' deve ser maior que '{ComparisonValue}'.", 10 | Language.code.isEmpty: "'{PropertyName}' deve estar vazio.", 11 | Language.code.isNotNull: "'{PropertyName}' não pode ser nulo.", 12 | Language.code.isNull: "'{PropertyName}' deve ser nulo.", 13 | Language.code.lessThan: 14 | "'{PropertyName}' deve ser menor que '{ComparisonValue}'.", 15 | Language.code.matchesPattern: 16 | "'{PropertyName}' não está no formato correto.", 17 | Language.code.max: 18 | "'{PropertyName}' deve ser menor ou igual a {MaxValue}. Você digitou {PropertyValue}.", 19 | Language.code.maxLength: 20 | "O tamanho de '{PropertyName}' deve ser de {MaxLength} caracteres ou menos. Você digitou {TotalLength} caracteres.", 21 | Language.code.min: 22 | "'{PropertyName}' deve ser maior ou igual a {MinValue}. Você digitou {PropertyValue}.", 23 | Language.code.minLength: 24 | "O tamanho de '{PropertyName}' deve ser de pelo menos {MinLength} caracteres. Você digitou {TotalLength} caracteres.", 25 | Language.code.mustHaveLowercase: 26 | "'{PropertyName}' deve ter pelo menos uma letra minúscula.", 27 | Language.code.mustHaveNumber: 28 | "'{PropertyName}' deve ter pelo menos um dígito ('0'-'9').", 29 | Language.code.mustHaveSpecialCharacter: 30 | "'{PropertyName}' deve ter pelo menos um caractere não alfanumérico.", 31 | Language.code.mustHaveUppercase: 32 | "'{PropertyName}' deve ter pelo menos uma letra maiúscula.", 33 | Language.code.notEmpty: "'{PropertyName}' não pode estar vazio.", 34 | Language.code.notEqualTo: 35 | "'{PropertyName}' não pode ser igual a '{ComparisonValue}'.", 36 | Language.code.range: 37 | "'{PropertyName}' deve estar entre {From} e {To}. Você digitou {PropertyValue}.", 38 | Language.code.validCEP: "'{PropertyName}' não é um CEP válido.", 39 | Language.code.validCPF: "'{PropertyName}' não é um CPF válido.", 40 | Language.code.validCNPJ: "'{PropertyName}' não é um CNPJ válido.", 41 | Language.code.validCreditCard: 42 | "'{PropertyName}' não é um número de cartão de crédito válido.", 43 | Language.code.validEmail: 44 | "'{PropertyName}' não é um endereço de e-mail válido.", 45 | Language.code.greaterThanOrEqualToDateTime: 46 | "'{PropertyName}' deve ser maior ou igual à data '{ComparisonValue}'.", 47 | Language.code.greaterThanDatetime: 48 | "'{PropertyName}' deve ser maior que a data '{ComparisonValue}'.", 49 | Language.code.lessThanOrEqualToDateTime: 50 | "'{PropertyName}' deve ser menor ou igual à data '{ComparisonValue}'.", 51 | Language.code.lessThanDateTime: 52 | "'{PropertyName}' deve ser menor que a data '{ComparisonValue}'.", 53 | Language.code.inclusiveBetweenDatetime: 54 | "'{PropertyName}' deve ser maior ou igual à data '{StartValue}' e menor ou igual à data '{EndValue}'.", 55 | Language.code.exclusiveBetweenDatetime: 56 | "'{PropertyName}' deve ser maior que a data '{StartValue}' e menor que a data '{EndValue}'.", 57 | Language.code.validPhoneBr: "'{PropertyName}' não é um telefone válido.", 58 | Language.code.validPhoneDdiBr: "'{PropertyName}' não é um telefone DDI válido." 59 | "'{PropertyName}' deve ser maior que a data '{StartValue}' e menor que a data '{EndValue}'.", 60 | Language.code.sequentialRepeatedCharacters: 61 | "'{PropertyName}' não pode ter caracteres repetidos em sequência.", 62 | Language.code.sequentialCharactersNotAllowed: 63 | "'{PropertyName}' não pode ter sequências como '123' ou 'abc'." 64 | }); 65 | } 66 | -------------------------------------------------------------------------------- /lib/src/localization/languages/spanish_language.dart: -------------------------------------------------------------------------------- 1 | import '../language.dart'; 2 | 3 | class SpanishLanguage extends Language { 4 | SpanishLanguage() 5 | : super({ 6 | Language.code.equalTo: 7 | "'{PropertyName}' debe ser igual a '{ComparisonValue}'.", 8 | Language.code.greaterThan: 9 | "'{PropertyName}' debe ser mayor que '{ComparisonValue}'.", 10 | Language.code.isEmpty: "'{PropertyName}' debe estar vacío.", 11 | Language.code.isNotNull: "'{PropertyName}' no puede ser nulo.", 12 | Language.code.isNull: "'{PropertyName}' debe ser nulo.", 13 | Language.code.lessThan: 14 | "'{PropertyName}' debe ser menor que '{ComparisonValue}'.", 15 | Language.code.matchesPattern: 16 | "'{PropertyName}' no tiene el formato correcto.", 17 | Language.code.max: 18 | "'{PropertyName}' debe ser menor o igual a {MaxValue}. Has ingresado {PropertyValue}.", 19 | Language.code.maxLength: 20 | "El tamaño de '{PropertyName}' debe ser de {MaxLength} caracteres o menos. Has ingresado {TotalLength} caracteres.", 21 | Language.code.min: 22 | "'{PropertyName}' debe ser mayor o igual a {MinValue}. Has ingresado {PropertyValue}.", 23 | Language.code.minLength: 24 | "El tamaño de '{PropertyName}' debe ser de al menos {MinLength} caracteres. Has ingresado {TotalLength} caracteres.", 25 | Language.code.mustHaveLowercase: 26 | "'{PropertyName}' debe tener al menos una letra minúscula.", 27 | Language.code.mustHaveNumber: 28 | "'{PropertyName}' debe tener al menos un dígito ('0'-'9').", 29 | Language.code.mustHaveSpecialCharacter: 30 | "'{PropertyName}' debe tener al menos un carácter no alfanumérico.", 31 | Language.code.mustHaveUppercase: 32 | "'{PropertyName}' debe tener al menos una letra mayúscula.", 33 | Language.code.notEmpty: "'{PropertyName}' no puede estar vacío.", 34 | Language.code.notEqualTo: 35 | "'{PropertyName}' no puede ser igual a '{ComparisonValue}'.", 36 | Language.code.range: 37 | "'{PropertyName}' debe estar entre {From} y {To}. Has ingresado {PropertyValue}.", 38 | Language.code.validCEP: "'{PropertyName}' no es un CEP válido.", 39 | Language.code.validCPF: "'{PropertyName}' no es un CPF válido.", 40 | Language.code.validCNPJ: "'{PropertyName}' no es un CNPJ válido.", 41 | Language.code.validCreditCard: 42 | "'{PropertyName}' no es un número de tarjeta de crédito válido.", 43 | Language.code.validEmail: 44 | "'{PropertyName}' no es una dirección de correo electrónico válida.", 45 | Language.code.greaterThanOrEqualToDateTime: 46 | "'{PropertyName}' debe ser mayor o igual a la fecha '{ComparisonValue}'.", 47 | Language.code.greaterThanDatetime: 48 | "'{PropertyName}' debe ser mayor que la fecha '{ComparisonValue}'.", 49 | Language.code.lessThanOrEqualToDateTime: 50 | "'{PropertyName}' debe ser menor o igual a la fecha '{ComparisonValue}'.", 51 | Language.code.lessThanDateTime: 52 | "'{PropertyName}' debe ser menor que la fecha '{ComparisonValue}'.", 53 | Language.code.inclusiveBetweenDatetime: 54 | "'{PropertyName}' debe ser mayor o igual a la fecha '{StartValue}' y menor o igual a la fecha '{EndValue}'.", 55 | Language.code.exclusiveBetweenDatetime: 56 | "'{PropertyName}' debe ser mayor que la fecha '{StartValue}' y menor que la fecha '{EndValue}'.", 57 | Language.code.validPhoneBr: "'{PropertyName}' no es un teléfono válido.", 58 | Language.code.validPhoneDdiBr: "'{PropertyName}' no es un teléfono DDI válido." 59 | "'{PropertyName}' debe ser mayor que la fecha '{StartValue}' y menor que la fecha '{EndValue}'.", 60 | Language.code.sequentialRepeatedCharacters: 61 | "'{PropertyName}' no puede tener caracteres repetidos en secuencia.", 62 | Language.code.sequentialCharactersNotAllowed: 63 | "'{PropertyName}' no puede tener secuencias como '123' o 'abc'." 64 | }); 65 | } 66 | -------------------------------------------------------------------------------- /lib/src/localization/localization.dart: -------------------------------------------------------------------------------- 1 | export 'culture.dart'; 2 | export 'language.dart'; 3 | export 'language_manager.dart'; 4 | export 'languages/english_language.dart'; 5 | -------------------------------------------------------------------------------- /lib/src/types/types.dart: -------------------------------------------------------------------------------- 1 | export 'validation_exception.dart'; 2 | export 'validation_result.dart'; 3 | -------------------------------------------------------------------------------- /lib/src/types/validation_exception.dart: -------------------------------------------------------------------------------- 1 | /// Represents an error that occurs during validation. 2 | /// 3 | /// [ValidationException] provides details about the validation error, including 4 | /// an optional key that identifies which field or property the error is associated with. 5 | class ValidationException implements Exception { 6 | /// The error message describing what went wrong during validation. 7 | final String message; 8 | 9 | /// An optional key that identifies the specific field or property related to the error. 10 | final String key; 11 | 12 | /// An optional code that identifies the specific validation error. 13 | final String code; 14 | 15 | /// The index of the item in a collection, if the validation error occurred within a list. 16 | /// 17 | /// This is useful when validating collections using `setEach`, allowing errors 18 | /// to be associated with the correct item by its position in the list. 19 | final int? index; 20 | 21 | /// The name of the entity (usually the class name) where the validation error occurred. 22 | /// 23 | /// This helps to contextualize the error by specifying which entity the error is associated with, 24 | /// especially in scenarios involving nested or complex validations. 25 | final String entity; 26 | 27 | /// Constructs a [ValidationException]. 28 | /// 29 | /// [message] provides a description of the error. 30 | /// [key] optionally identifies the field or property related to the error. 31 | const ValidationException({ 32 | required this.message, 33 | required this.code, 34 | required this.entity, 35 | this.key = '', 36 | this.index, 37 | }); 38 | 39 | Map toJson() { 40 | return { 41 | 'message': message, 42 | if (key.isNotEmpty) 'key': key, 43 | if (entity.isNotEmpty) 'entity': entity, 44 | if (code.isNotEmpty) 'code': code, 45 | if (index != null) 'index': index, 46 | }; 47 | } 48 | 49 | ValidationException copyWith({ 50 | String? message, 51 | String? entity, 52 | String? key, 53 | String? code, 54 | int? index, 55 | }) { 56 | return ValidationException( 57 | message: message ?? this.message, 58 | entity: entity ?? this.entity, 59 | code: code ?? this.code, 60 | key: key ?? this.key, 61 | index: index ?? this.index, 62 | ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /lib/src/types/validation_result.dart: -------------------------------------------------------------------------------- 1 | import 'validation_exception.dart'; 2 | 3 | /// Represents the result of a validation rule. 4 | /// 5 | /// [ValidationResult] encapsulates whether the validation was successful 6 | /// and, if not, provides the associated [ValidationException]. 7 | class ValidationResult { 8 | /// Indicates whether the validation was successful. 9 | final bool isValid; 10 | 11 | /// Provides details about the validation error if the validation failed. 12 | final List exceptions; 13 | 14 | /// Constructs a [ValidationResult]. 15 | /// 16 | /// [isValid] specifies whether the validation passed or failed. 17 | /// [exceptions] provides the exceptions details in case of a validation failure. 18 | const ValidationResult({ 19 | required this.isValid, 20 | required this.exceptions, 21 | }); 22 | 23 | List> exceptionToJson() { 24 | return exceptions.map((e) => e.toJson()).toList(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/src/utils/utils.dart: -------------------------------------------------------------------------------- 1 | String extractClassName(String input) { 2 | final regex = RegExp(r"Instance of '(\w+)'"); 3 | final match = regex.firstMatch(input); 4 | return match?.group(1) ?? ''; 5 | } 6 | -------------------------------------------------------------------------------- /lib/src/validations/equal_validation.dart: -------------------------------------------------------------------------------- 1 | part of 'validations.dart'; 2 | 3 | /// Extension on [LucidValidationBuilder] for [T] properties to add an equality validation. 4 | /// 5 | /// This extension adds an `equalTo` method that can be used to ensure that a value 6 | /// is equal to a specific value. 7 | extension EqualValidation on LucidValidationBuilder { 8 | /// Adds a validation rule that checks if the value is equal to [comparison]. 9 | /// 10 | /// [predicate] is a function that returns the value to compare against. 11 | /// [message] is the error message returned if the validation fails. 12 | /// [code] is an optional error code for translation purposes. 13 | /// 14 | /// Returns the [LucidValidationBuilder] to allow for method chaining. 15 | /// 16 | /// Example: 17 | /// ```dart 18 | /// ... 19 | /// ruleFor((user) => user.confirmPassword, key: 'confirmPassword') 20 | /// .equalTo((user) => user.password); 21 | /// 22 | /// ``` 23 | /// 24 | /// String format args: 25 | /// - **{PropertyName}**: The name of the property. 26 | /// - **{ComparisonValue}**: The value to compare against. 27 | /// 28 | LucidValidationBuilder equalTo( 29 | T Function(E entity) predicate, { 30 | String? message, 31 | String? code, 32 | }) { 33 | return use( 34 | (value, entity) { 35 | final comparison = predicate(entity); 36 | if (value == comparison) return null; 37 | 38 | final currentCode = code ?? Language.code.equalTo; 39 | final currentMessage = LucidValidation.global.languageManager.translate( 40 | currentCode, 41 | parameters: { 42 | 'PropertyName': label.isNotEmpty ? label : key, 43 | 'ComparisonValue': '$comparison', 44 | }, 45 | defaultMessage: message, 46 | ); 47 | 48 | return ValidationException( 49 | entity: extractClassName(entity.toString()), 50 | message: currentMessage, 51 | code: currentCode, 52 | key: key, 53 | ); 54 | }, 55 | ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lib/src/validations/is_empty_validation.dart: -------------------------------------------------------------------------------- 1 | part of 'validations.dart'; 2 | 3 | /// Extension on [LucidValidationBuilder] for [String] properties to add an empty string validation. 4 | /// 5 | /// This extension adds an `isEmpty` method that can be used to ensure that a string 6 | /// is empty. 7 | extension IsEmptyValidation on SimpleValidationBuilder { 8 | /// Adds a validation rule that checks if the [String] is empty. 9 | /// 10 | /// [message] is the error message returned if the validation fails. 11 | /// [code] is an optional error code for translation purposes. 12 | /// 13 | /// Returns the [LucidValidationBuilder] to allow for method chaining. 14 | /// 15 | /// Example: 16 | /// ```dart 17 | /// ... 18 | /// ruleFor((user) => user.name, key: 'name') 19 | /// .isEmpty(); 20 | /// ``` 21 | /// 22 | /// String format args: 23 | /// - **{PropertyName}**: The name of the property. 24 | /// 25 | SimpleValidationBuilder isEmpty({String? message, String? code}) { 26 | return use((value, entity) { 27 | if (value.isEmpty) return null; 28 | 29 | final currentCode = code ?? Language.code.isEmpty; 30 | final currentMessage = LucidValidation.global.languageManager.translate( 31 | currentCode, 32 | parameters: { 33 | 'PropertyName': label.isNotEmpty ? label : key, 34 | }, 35 | defaultMessage: message, 36 | ); 37 | 38 | return ValidationException( 39 | entity: extractClassName(entity.toString()), 40 | message: currentMessage, 41 | code: currentCode, 42 | key: key, 43 | ); 44 | }); 45 | } 46 | } 47 | 48 | extension IsEmptyNullableValidation on SimpleValidationBuilder { 49 | /// Adds a validation rule that checks if the [String?] is empty. 50 | /// 51 | /// [message] is the error message returned if the validation fails. 52 | /// [code] is an optional error code for translation purposes. 53 | /// 54 | /// Returns the [LucidValidationBuilder] to allow for method chaining. 55 | /// 56 | /// Example: 57 | /// ```dart 58 | /// ... 59 | /// ruleFor((user) => user.name, key: 'name') // user.name is nullable 60 | /// .isEmpty(); 61 | /// ``` 62 | /// 63 | /// String format args: 64 | /// - **{PropertyName}**: The name of the property. 65 | /// 66 | SimpleValidationBuilder isEmpty({String? message, String? code}) { 67 | return use((value, entity) { 68 | if (value != null && value.isEmpty) return null; 69 | 70 | final currentCode = code ?? Language.code.isEmpty; 71 | final currentMessage = LucidValidation.global.languageManager.translate( 72 | currentCode, 73 | parameters: { 74 | 'PropertyName': label.isNotEmpty ? label : key, 75 | }, 76 | defaultMessage: message, 77 | ); 78 | 79 | return ValidationException( 80 | entity: extractClassName(entity.toString()), 81 | message: currentMessage, 82 | code: currentCode, 83 | key: key, 84 | ); 85 | }); 86 | } 87 | } 88 | 89 | extension IsEmptyOrNullableValidation on SimpleValidationBuilder { 90 | /// Adds a validation rule that checks if the [String?] is empty. 91 | /// 92 | /// [message] is the error message returned if the validation fails. 93 | /// [code] is an optional error code for translation purposes. 94 | /// 95 | /// Returns the [LucidValidationBuilder] to allow for method chaining. 96 | /// 97 | /// Example: 98 | /// ```dart 99 | /// ... 100 | /// ruleFor((user) => user.name, key: 'name') 101 | /// .isEmptyOrNull(); 102 | /// ``` 103 | /// 104 | /// String format args: 105 | /// - **{PropertyName}**: The name of the property. 106 | /// 107 | SimpleValidationBuilder isEmptyOrNull( 108 | {String? message, String? code}) { 109 | return use((value, entity) { 110 | if (value == null || value.isEmpty) return null; 111 | 112 | final currentCode = code ?? Language.code.isEmpty; 113 | final currentMessage = LucidValidation.global.languageManager.translate( 114 | currentCode, 115 | parameters: { 116 | 'PropertyName': label.isNotEmpty ? label : key, 117 | }, 118 | defaultMessage: message, 119 | ); 120 | 121 | return ValidationException( 122 | entity: extractClassName(entity.toString()), 123 | message: currentMessage, 124 | code: currentCode, 125 | key: key, 126 | ); 127 | }); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /lib/src/validations/is_not_null_validation.dart: -------------------------------------------------------------------------------- 1 | part of 'validations.dart'; 2 | 3 | /// Extension on [LucidValidationBuilder] for [T?] properties to add a not null validation. 4 | /// 5 | /// This extension adds an `isNotNull` method that can be used to ensure that a value 6 | /// is not null. 7 | extension IsNotNullValidation on SimpleValidationBuilder { 8 | /// Adds a validation rule that checks if the value is not null. 9 | /// 10 | /// [message] is the error message returned if the validation fails. 11 | /// [code] is an optional error code for translation purposes. 12 | /// 13 | /// Returns the [LucidValidationBuilder] to allow for method chaining. 14 | /// 15 | /// Example: 16 | /// ```dart 17 | /// ... 18 | /// ruleFor((user) => user.name, key: 'name') // required field 19 | /// .isNotNull(); 20 | /// ``` 21 | /// 22 | /// String format args: 23 | /// - **{PropertyName}**: The name of the property. 24 | /// 25 | SimpleValidationBuilder isNotNull({String? message, String? code}) { 26 | return useNotNull( 27 | (value, entity) { 28 | if (value != null) return null; 29 | 30 | final currentCode = code ?? Language.code.isNotNull; 31 | final currentMessage = LucidValidation.global.languageManager.translate( 32 | currentCode, 33 | parameters: { 34 | 'PropertyName': label.isNotEmpty ? label : key, 35 | }, 36 | defaultMessage: message, 37 | ); 38 | 39 | return ValidationException( 40 | entity: extractClassName(entity.toString()), 41 | message: currentMessage, 42 | code: currentCode, 43 | key: key, 44 | ); 45 | }, 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/validations/is_null_validation.dart: -------------------------------------------------------------------------------- 1 | part of 'validations.dart'; 2 | 3 | /// Extension on [LucidValidationBuilder] for [T?] properties to add a null validation. 4 | /// 5 | /// This extension adds an `isNull` method that can be used to ensure that a value 6 | /// is null. 7 | extension IsNullValidation on SimpleValidationBuilder { 8 | /// Adds a validation rule that checks if the value is null. 9 | /// 10 | /// [message] is the error message returned if the validation fails. Defaults to "Must be null". 11 | /// [code] is an optional error code for translation purposes. 12 | /// 13 | /// Returns the [LucidValidationBuilder] to allow for method chaining. 14 | /// 15 | /// Example: 16 | /// ```dart 17 | /// ... 18 | /// ruleFor((user) => user.name, key: 'name') // optional field 19 | /// .isNull(); 20 | /// ``` 21 | /// 22 | /// String format args: 23 | /// - **{PropertyName}**: The name of the property. 24 | /// 25 | SimpleValidationBuilder isNull({String? message, String? code}) { 26 | return use( 27 | (value, entity) { 28 | if (value == null) return null; 29 | 30 | final currentCode = code ?? Language.code.isNull; 31 | final currentMessage = LucidValidation.global.languageManager.translate( 32 | currentCode, 33 | parameters: { 34 | 'PropertyName': label.isNotEmpty ? label : key, 35 | }, 36 | defaultMessage: message, 37 | ); 38 | 39 | return ValidationException( 40 | entity: extractClassName(entity.toString()), 41 | message: currentMessage, 42 | code: currentCode, 43 | key: key, 44 | ); 45 | }, 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/validations/not_equal_validation.dart: -------------------------------------------------------------------------------- 1 | part of 'validations.dart'; 2 | 3 | /// Extension on [LucidValidationBuilder] for [T] properties to add a non-equality validation. 4 | /// 5 | /// This extension adds a `notEqualTo` method that can be used to ensure that a value 6 | /// is not equal to a specific value. 7 | extension NotEqualValidation on LucidValidationBuilder { 8 | /// Adds a validation rule that checks if the value is not equal to [comparison]. 9 | /// 10 | /// [predicate] is the value that the field must not match. 11 | /// [message] is the error message returned if the validation fails. Defaults to "Must not be equal to $comparison". 12 | /// [code] is an optional error code for translation purposes. 13 | /// 14 | /// Returns the [LucidValidationBuilder] to allow for method chaining. 15 | /// 16 | /// Example: 17 | /// ```dart 18 | /// ... 19 | /// ruleFor((user) => user.newUsername, key: 'newUsername') 20 | /// .notEqualTo((user) => user.oldUsername); 21 | /// ``` 22 | /// 23 | /// String format args: 24 | /// - **{PropertyName}**: The name of the property. 25 | /// - **{ComparisonValue}**: The value to compare against. 26 | /// 27 | LucidValidationBuilder notEqualTo(T Function(E entity) predicate, 28 | {String? message, String? code}) { 29 | return use( 30 | (value, entity) { 31 | final comparison = predicate(entity); 32 | if (value != comparison) return null; 33 | 34 | final currentCode = code ?? Language.code.notEqualTo; 35 | final currentMessage = LucidValidation.global.languageManager.translate( 36 | currentCode, 37 | parameters: { 38 | 'PropertyName': label.isNotEmpty ? label : key, 39 | 'ComparisonValue': '$comparison', 40 | }, 41 | defaultMessage: message, 42 | ); 43 | 44 | return ValidationException( 45 | entity: extractClassName(entity.toString()), 46 | message: currentMessage, 47 | code: currentCode, 48 | key: key, 49 | ); 50 | }, 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/src/validations/validations.dart: -------------------------------------------------------------------------------- 1 | import '../../lucid_validation.dart'; 2 | import '../utils/utils.dart'; 3 | 4 | part 'equal_validation.dart'; 5 | part 'greater_than_validation.dart'; 6 | part 'greater_than_datetime_validation.dart'; 7 | part 'greater_than_or_equal_to_datetime_validation.dart'; 8 | part 'less_than_or_equal_to_datetime_validation.dart'; 9 | part 'less_than_datetime_validation.dart'; 10 | part 'inclusive_between_datetime_validation.dart'; 11 | part 'exclusive_between_datetime_validation.dart'; 12 | part 'is_empty_validation.dart'; 13 | part 'is_not_null_validation.dart'; 14 | part 'is_null_validation.dart'; 15 | part 'less_then_validation.dart'; 16 | part 'matches_pattern_validation.dart'; 17 | part 'max_length_validation.dart'; 18 | part 'max_validation.dart'; 19 | part 'min_length_validation.dart'; 20 | part 'min_validation.dart'; 21 | part 'must_have_lowercase_validation.dart'; 22 | part 'must_have_number_validation.dart'; 23 | part 'must_have_special_character_validation.dart'; 24 | part 'must_have_uppercase_validation.dart'; 25 | part 'not_empty_validation.dart'; 26 | part 'not_equal_validation.dart'; 27 | part 'range_validation.dart'; 28 | part 'valid_cep_validation.dart'; 29 | part 'valid_cnpj_validation.dart'; 30 | part 'valid_cpf_validation.dart'; 31 | part 'valid_creditcard_validation.dart'; 32 | part 'valid_email_validation.dart'; 33 | part 'valid_cpf_or_cnpj_validation.dart'; 34 | part 'valid_phone_validation.dart'; 35 | part 'repeated_characters_validation.dart'; 36 | part 'sequential_characters_validation.dart'; -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: lucid_validation 2 | description: "A Dart/Flutter package for building strongly typed validation rules inspired by FluentValidation and created by the Flutterando community." 3 | repository: https://github.com/Flutterando/lucid_validation 4 | homepage: https://pub.dev/documentation/lucid_validation/latest/ 5 | 6 | version: 1.3.1 7 | 8 | environment: 9 | sdk: ">=3.0.0 <4.0.0" 10 | 11 | # dependencies: 12 | 13 | 14 | dev_dependencies: 15 | lints: ">=3.0.0 <4.0.0" 16 | test: ">=1.20.0 <2.0.0" 17 | -------------------------------------------------------------------------------- /test/byfield_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import 'mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('byfield normal', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator.ruleFor((model) => model.age, key: 'age').greaterThan(17); 11 | validator.ruleFor((model) => model.email, key: 'email').notEmpty(); 12 | 13 | final user = UserModel()..age = 16; 14 | 15 | final ageValidator = validator.byField(user, 'age'); 16 | 17 | expect(ageValidator(), isNotNull); 18 | 19 | user.age = 18; 20 | 21 | expect(ageValidator(), null); 22 | 23 | final emailValidator = validator.byField(user, 'email'); 24 | 25 | expect(emailValidator(), isNotNull); 26 | 27 | user.email = 'test@gmail.com'; 28 | 29 | expect(emailValidator(), null); 30 | 31 | final phoneValidator = validator.byField(user, 'phone'); 32 | user.phone = '75912345678'; 33 | 34 | expect(phoneValidator(), null); 35 | }); 36 | 37 | group('nested byfield normal', () { 38 | final flagValidator = TestLucidValidator(); 39 | flagValidator.ruleFor((flag) => flag.value, key: 'value').equalTo((entity) => true); 40 | 41 | final categoryValidator = TestLucidValidator(); 42 | categoryValidator.ruleFor((category) => category.name, key: 'name').notEmpty(); 43 | categoryValidator.ruleFor((category) => category.flag, key: 'flag').setValidator(flagValidator); 44 | 45 | final productValidator = TestLucidValidator(); 46 | productValidator.ruleFor((product) => product.name, key: 'name').notEmpty(); 47 | productValidator.ruleFor((product) => product.price, key: 'price').greaterThan(0); 48 | productValidator.ruleFor((product) => product.category, key: 'category').setValidator(categoryValidator); 49 | 50 | final product = ProductModel(); 51 | 52 | test('nameValidator', () { 53 | final nameValidator = productValidator.byField(product, 'name'); 54 | expect(nameValidator(), isNotNull); 55 | }); 56 | 57 | test('priceValidator', () { 58 | final priceValidator = productValidator.byField(product, 'price'); 59 | expect(priceValidator(), isNotNull); 60 | }); 61 | 62 | test('categoryValidator', () { 63 | final categoryValidatorFn = productValidator.byField(product, 'category'); 64 | expect(categoryValidatorFn(), isNotNull); 65 | }); 66 | 67 | test('categoryNameValidator', () { 68 | final categoryNameValidatorFn = productValidator.byField(product, 'category.name'); 69 | expect(categoryNameValidatorFn(), isNotNull); 70 | }); 71 | 72 | test('flagValidator', () { 73 | final flagValidatorFn = productValidator.byField(product, 'category.flag'); 74 | expect(flagValidatorFn(), isNotNull); 75 | }); 76 | 77 | test('flagValueValidator', () { 78 | final flagValueValidatorFn = productValidator.byField(product, 'category.flag.value'); 79 | expect(flagValueValidatorFn(), isNotNull); 80 | }); 81 | 82 | test('must return null if not found key', () { 83 | final flagValueValidatorFn = productValidator.byField(product, 'category.flag.notExists'); 84 | expect(flagValueValidatorFn(), null); 85 | }); 86 | 87 | test('all validators', () { 88 | product.name = 'Product'; 89 | product.price = 10; 90 | product.category.name = 'Category'; 91 | product.category.flag.value = true; 92 | 93 | final nameValidator = productValidator.byField(product, 'name'); 94 | final priceValidator = productValidator.byField(product, 'price'); 95 | final categoryValidatorFn = productValidator.byField(product, 'category'); 96 | final categoryNameValidatorFn = productValidator.byField(product, 'category.name'); 97 | final flagValidatorFn = productValidator.byField(product, 'category.flag'); 98 | final flagValueValidatorFn = productValidator.byField(product, 'category.flag.value'); 99 | 100 | expect(nameValidator(), null); 101 | expect(priceValidator(), null); 102 | expect(categoryValidatorFn(), null); 103 | expect(categoryNameValidatorFn(), null); 104 | expect(flagValidatorFn(), null); 105 | expect(flagValueValidatorFn(), null); 106 | }); 107 | }); 108 | } 109 | 110 | class ProductModel { 111 | String name = ''; 112 | double price = 0.0; 113 | CategoryModel category = CategoryModel(); 114 | } 115 | 116 | class CategoryModel { 117 | String name = ''; 118 | Flag flag = Flag(); 119 | } 120 | 121 | class Flag { 122 | bool value = false; 123 | } 124 | -------------------------------------------------------------------------------- /test/list_validations_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import 'mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('complex validations', () { 8 | 9 | final studentValidator = StudentValidator(); 10 | final validator = TestLucidValidator(); 11 | 12 | validator.ruleFor((c) => c.className, key: 'className').notEmpty(); 13 | 14 | validator.ruleFor((c) => c.teacher, key: 'teacher') 15 | .setValidator(TeacherModelValidator()); 16 | 17 | validator 18 | .ruleFor((c) => c.students, key: 'students') 19 | .setEach(studentValidator); 20 | 21 | final model = Classroom( 22 | teacher: TeacherModel() 23 | ..name = '', 24 | students: [ 25 | // invalid 26 | StudentModel() 27 | ..email = 'teste@gmail.com' 28 | ..name = '', 29 | // invalid 30 | StudentModel() 31 | ..email = '' 32 | ..name = 'test', 33 | // valid 34 | StudentModel() 35 | ..email = 'teste@gmail.com' 36 | ..name = 'test', 37 | ], 38 | ); 39 | 40 | final result = validator.validate(model); 41 | final exceptions = result.exceptions; 42 | 43 | expect(exceptions[0].key, "className"); 44 | expect(exceptions[0].entity, "Classroom"); 45 | 46 | expect(exceptions[1].key, "name"); 47 | expect(exceptions[1].entity, "TeacherModel"); 48 | 49 | expect(exceptions[2].key, "name"); 50 | expect(exceptions[2].entity, "StudentModel"); 51 | expect(exceptions[2].index, 0); 52 | 53 | expect(exceptions[3].key, "email"); 54 | expect(exceptions[3].entity, "StudentModel"); 55 | expect(exceptions[3].index, 1); 56 | 57 | expect(exceptions.length, 4); 58 | }); 59 | } 60 | -------------------------------------------------------------------------------- /test/lucid_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | import 'mocks/mocks.dart'; 4 | 5 | void main() { 6 | test('when validating [UserEntityMock] should return a list of error messages for the email field', () { 7 | final validator = UserValidator(); 8 | final userEntity = UserModel() 9 | ..age = 18 10 | ..email = '' 11 | ..phone = '(11) 99999-9999' 12 | ..password = 'Teste@1234'; 13 | 14 | final result = validator.validate(userEntity); 15 | final exceptions = result.exceptions; 16 | 17 | expect(exceptions.length, 2); 18 | }); 19 | 20 | test('when validating [UserModel] should return a list of error messages for the password field', () { 21 | final validator = UserValidator(); 22 | final userEntity = UserModel() 23 | ..age = 18 24 | ..email = 'teste@gmail.com' 25 | ..phone = '(11) 99999-9999' 26 | ..password = ''; 27 | 28 | final result = validator.validate(userEntity); 29 | final exceptions = result.exceptions; 30 | 31 | expect(exceptions.length, 6); 32 | }); 33 | 34 | test('when validating [UserModel] should return a list of error messages for the age field', () { 35 | final validator = UserValidator(); 36 | final userEntity = UserModel() 37 | ..age = 15 38 | ..email = 'teste@gmail.com' 39 | ..phone = '(11) 99999-9999' 40 | ..password = 'Teste@1234'; 41 | 42 | final result = validator.validate(userEntity); 43 | final exceptions = result.exceptions; 44 | 45 | expect(exceptions.length, 1); 46 | }); 47 | 48 | test('when validating [UserModel] should return a list of error messages for the phone field', () { 49 | final validator = UserValidator(); 50 | 51 | final userEntity = UserModel() 52 | ..age = 18 53 | ..email = 'teste@gmail.com' 54 | ..phone = '' 55 | ..password = 'Teste@1234'; 56 | 57 | final result = validator.validate(userEntity); 58 | final exceptions = result.exceptions; 59 | 60 | expect(exceptions.length, 1); 61 | }); 62 | 63 | test('when validating [UserModel] should return a list of error messages for all fields', () { 64 | final validator = UserValidator(); 65 | final userEntity = UserModel()..age = 15; 66 | 67 | final result = validator.validate(userEntity); 68 | final exceptions = result.exceptions; 69 | 70 | expect(exceptions.length, 10); 71 | }); 72 | 73 | test('EqualTo', () { 74 | var credentials = CredentialsRegister( 75 | email: 'test@test.com', 76 | confirmPassword: '123asdASD@', 77 | password: '123asdASD@', 78 | ); 79 | final validator = CredentialsRegisterValidator(); 80 | 81 | var result = validator.validate(credentials); 82 | var exceptions = result.exceptions; 83 | 84 | expect(exceptions.length, 0); 85 | 86 | credentials = credentials.copyWith(confirmPassword: '123asdASDsdsdw'); 87 | result = validator.validate(credentials); 88 | exceptions = result.exceptions; 89 | expect(exceptions.length, 2); 90 | }); 91 | 92 | test('setValidator', () { 93 | var customer = Customer( 94 | name: 'John Doe', 95 | address: Address( 96 | country: 'Brazil', 97 | postcode: '12345-678', 98 | ), 99 | cnpj: '63.288.044/0001-89', 100 | ); 101 | 102 | final validator = CustomerValidator(); 103 | 104 | var result = validator.validate(customer); 105 | expect(result.isValid, isTrue); 106 | 107 | customer.address = Address( 108 | country: 'Brazil', 109 | postcode: '', 110 | ); 111 | 112 | result = validator.validate(customer); 113 | 114 | expect(result.isValid, isFalse); 115 | 116 | final stringError = validator.byField(customer, 'address')(); 117 | expect(stringError, '\'postcode\' must not be empty.'); 118 | }); 119 | 120 | test('getExceptionsByKey', () { 121 | var user = UserModel(); 122 | 123 | final validator = UserValidator(); 124 | 125 | var exceptions = validator.getExceptionsByKey(user, 'email'); 126 | 127 | var codes = exceptions.map((exception) => exception.code).toList(); 128 | 129 | expect(exceptions.length, 2); 130 | expect(codes[0], 'notEmpty'); 131 | expect(codes[1], 'validEmail'); 132 | }); 133 | 134 | test('byField with override callback', () { 135 | var user = UserModel(); 136 | 137 | final validator = UserValidator(); 138 | List codes = []; 139 | 140 | validator.byField(user, 'email', overrideCallback: (exceptions) { 141 | codes = exceptions.map((exception) => exception.code).toList(); 142 | })(); 143 | 144 | expect(codes.length, 2); 145 | expect(codes[0], 'notEmpty'); 146 | expect(codes[1], 'validEmail'); 147 | }); 148 | } 149 | -------------------------------------------------------------------------------- /test/src/validations/equal_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('equal validation', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.confirmPassword, key: 'confirmPassword') // 11 | .equalTo((user) => user.password); 12 | 13 | final user = UserModel() 14 | ..password = 'password' 15 | ..confirmPassword = 'password2'; 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | expect(result.exceptions.length, 1); 20 | 21 | final error = result.exceptions.first; 22 | expect(error.message, r"'confirmPassword' must be equal to 'password'."); 23 | }); 24 | 25 | test('equal validation with local message', () { 26 | final validator = TestLucidValidator(); 27 | validator 28 | .ruleFor((user) => user.confirmPassword, key: 'confirmPassword') // 29 | .equalTo((user) => user.password, 30 | message: 31 | "Campo '{PropertyName}' deve ser igual ao campo '{ComparisonValue}'."); 32 | 33 | final user = UserModel() 34 | ..password = 'password' 35 | ..confirmPassword = 'password2'; 36 | final result = validator.validate(user); 37 | 38 | expect(result.isValid, false); 39 | expect(result.exceptions.length, 1); 40 | 41 | final error = result.exceptions.first; 42 | expect(error.message, 43 | r"Campo 'confirmPassword' deve ser igual ao campo 'password'."); 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /test/src/validations/exclusive_between_datetime_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test( 8 | 'should fail exclusive between validation when the event date is exactly on the start boundary', 9 | () { 10 | final validator = TestLucidValidator(); 11 | final now = DateTime.now(); 12 | final tomorrow = now.add(Duration(days: 1)); 13 | final afterTomorrow = now.add(Duration(days: 2)); 14 | 15 | validator 16 | .ruleFor((event) => event.dateEvent, key: 'dateEvent') // 17 | .exclusiveBetween(start: tomorrow, end: afterTomorrow); 18 | 19 | final event = EventModel()..dateEvent = tomorrow; 20 | 21 | final result = validator.validate(event); 22 | 23 | expect(result.isValid, false); 24 | expect(result.exceptions.length, 1); 25 | expect(result.exceptions.first.message, 26 | "'dateEvent' must be greater than the '${tomorrow.toString()}' date and less than the '${afterTomorrow.toString()}' date."); 27 | }); 28 | 29 | test( 30 | 'should fail exclusive between validation when the event date is exactly on the end boundary', 31 | () { 32 | final validator = TestLucidValidator(); 33 | final now = DateTime.now(); 34 | final tomorrow = now.add(Duration(days: 1)); 35 | final afterTomorrow = now.add(Duration(days: 2)); 36 | 37 | validator 38 | .ruleFor((event) => event.dateEvent, key: 'dateEvent') // 39 | .exclusiveBetween(start: tomorrow, end: afterTomorrow); 40 | 41 | final event = EventModel()..dateEvent = afterTomorrow; 42 | 43 | final result = validator.validate(event); 44 | 45 | expect(result.isValid, false); 46 | expect(result.exceptions.length, 1); 47 | expect(result.exceptions.first.message, 48 | "'dateEvent' must be greater than the '${tomorrow.toString()}' date and less than the '${afterTomorrow.toString()}' date."); 49 | }); 50 | 51 | test( 52 | 'should fail exclusive between validation when the event date is exactly on the end boundary', 53 | () { 54 | final validator = TestLucidValidator(); 55 | final now = DateTime.now(); 56 | final tomorrow = now.add(Duration(days: 1)); 57 | final afterTomorrow = now.add(Duration(days: 2)); 58 | 59 | validator 60 | .ruleFor((event) => event.dateEvent, key: 'dateEvent') // 61 | .exclusiveBetween(start: now, end: afterTomorrow); 62 | 63 | final event = EventModel()..dateEvent = tomorrow; 64 | 65 | final result = validator.validate(event); 66 | 67 | expect(result.isValid, true); 68 | }); 69 | 70 | test( 71 | 'must return valid exclusively between validation when the event date is null', 72 | () { 73 | final validator = TestLucidValidator(); 74 | final now = DateTime.now(); 75 | final afterTomorrow = now.add(Duration(days: 2)); 76 | 77 | validator 78 | .ruleFor((event) => event.dateEvent, key: 'dateEvent') // 79 | .exclusiveBetweenOrNull(start: now, end: afterTomorrow); 80 | 81 | final event = EventNullableModel()..dateEvent = null; 82 | 83 | final result = validator.validate(event); 84 | 85 | expect(result.isValid, true); 86 | }); 87 | } 88 | -------------------------------------------------------------------------------- /test/src/validations/greater_than_datetime_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('greater than validation ...', () { 8 | final validator = TestLucidValidator(); 9 | final now = DateTime.now(); 10 | 11 | validator 12 | .ruleFor((event) => event.start, key: 'start') // 13 | .greaterThan(now); 14 | 15 | final event = EventModel()..start = DateTime(2024, 8, 26); 16 | 17 | final result = validator.validate(event); 18 | 19 | expect(result.isValid, false); 20 | expect(result.exceptions.length, 1); 21 | expect(result.exceptions.first.message, 22 | "'start' must be greater than date '${now.toString()}'."); 23 | }); 24 | 25 | test('greater than validation or null ...', () { 26 | final validator = TestLucidValidator(); 27 | final now = DateTime.now(); 28 | 29 | validator 30 | .ruleFor((event) => event.start, key: 'start') // 31 | .greaterThanOrNull(now); 32 | 33 | final event = EventNullableModel()..start = null; 34 | 35 | final result = validator.validate(event); 36 | 37 | expect(result.isValid, true); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /test/src/validations/greater_than_or_equal_to_datetime_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('greater than validation ...', () { 8 | final validator = TestLucidValidator(); 9 | final now = DateTime.now(); 10 | 11 | validator 12 | .ruleFor((event) => event.start, key: 'start') // 13 | .greaterThanOrEqualTo(now); 14 | 15 | final event = EventModel()..start = DateTime(2024, 8, 27); 16 | 17 | final result = validator.validate(event); 18 | 19 | expect(result.isValid, false); 20 | expect(result.exceptions.length, 1); 21 | expect(result.exceptions.first.message, 22 | "'start' must be greater than or equal to date '${now.toString()}'."); 23 | }); 24 | 25 | test('greater than or equal to validation ...', () { 26 | final validator = TestLucidValidator(); 27 | final now = DateTime.now(); 28 | 29 | validator 30 | .ruleFor((event) => event.start, key: 'start') // 31 | .greaterThanOrEqualTo(now); 32 | 33 | final event = EventModel()..start = now; 34 | 35 | final result = validator.validate(event); 36 | 37 | expect(result.isValid, true); 38 | }); 39 | 40 | test('greater than or equal to validation or null ...', () { 41 | final validator = TestLucidValidator(); 42 | final now = DateTime.now(); 43 | 44 | validator 45 | .ruleFor((event) => event.start, key: 'start') // 46 | .greaterThanOrEqualToOrNull(now); 47 | 48 | final event = EventNullableModel()..start = null; 49 | 50 | final result = validator.validate(event); 51 | 52 | expect(result.isValid, true); 53 | }); 54 | } 55 | -------------------------------------------------------------------------------- /test/src/validations/greater_than_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('greater than validation ...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.age, key: 'age') // 11 | .greaterThan(17); 12 | 13 | final user = UserModel()..age = 15; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, "'age' must be greater than '17'."); 20 | }); 21 | 22 | test('greater than validation or null ...', () { 23 | final validator = TestLucidValidator(); 24 | validator 25 | .ruleFor((user) => user.age, key: 'age') // 26 | .greaterThanOrNull(17); 27 | 28 | final user = UserNullableModel()..age = null; 29 | 30 | final result = validator.validate(user); 31 | 32 | expect(result.isValid, true); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/src/validations/inclusive_between_datetime_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('inclusive between validation ...', () { 8 | final validator = TestLucidValidator(); 9 | final now = DateTime.now(); 10 | final tomorrow = now.add(Duration(days: 1)); 11 | final afterTomorrow = now.add(Duration(days: 2)); 12 | 13 | validator 14 | .ruleFor((event) => event.dateEvent, key: 'dateEvent') // 15 | .inclusiveBetween(start: tomorrow, end: afterTomorrow); 16 | 17 | final event = EventModel()..dateEvent = now; 18 | 19 | final result = validator.validate(event); 20 | 21 | expect(result.isValid, false); 22 | expect(result.exceptions.length, 1); 23 | expect(result.exceptions.first.message, 24 | "'dateEvent' must be greater than or equal to '${tomorrow.toString()}' date and less than or equal to '${afterTomorrow.toString()}' date."); 25 | }); 26 | 27 | test('inclusive between validation or null...', () { 28 | final validator = TestLucidValidator(); 29 | final now = DateTime.now(); 30 | final tomorrow = now.add(Duration(days: 1)); 31 | final afterTomorrow = now.add(Duration(days: 2)); 32 | 33 | validator 34 | .ruleFor((event) => event.dateEvent, key: 'dateEvent') // 35 | .inclusiveBetweenOrNull(start: tomorrow, end: afterTomorrow); 36 | 37 | final event = EventNullableModel()..dateEvent = null; 38 | 39 | final result = validator.validate(event); 40 | 41 | expect(result.isValid, true); 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /test/src/validations/is_empty_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('is empty validation ...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.email, key: 'email') // 11 | .isEmpty(); 12 | 13 | final user = UserModel()..email = 'ss'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | 19 | expect(result.exceptions.length, 1); 20 | 21 | expect(result.exceptions.first.message, "'email' must be empty."); 22 | }); 23 | 24 | test('is empty validation or null...', () { 25 | final validator = TestLucidValidator(); 26 | validator 27 | .ruleFor((user) => user.email, key: 'email') // 28 | .isEmptyOrNull(); 29 | 30 | final user = UserNullableModel()..email = null; 31 | 32 | final result = validator.validate(user); 33 | 34 | expect(result.isValid, true); 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /test/src/validations/is_not_null_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('is not null validation ...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((e) => e.description, key: 'description') // 11 | .isNotNull(); 12 | 13 | final user = UserModel(); 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | 19 | expect(result.exceptions.length, 1); 20 | 21 | final error = result.exceptions.first; 22 | 23 | expect(error.message, r"'description' must not be null."); 24 | }); 25 | 26 | test('is not null validation is valid...', () { 27 | final validator = TestLucidValidator(); 28 | validator 29 | .ruleFor((e) => e.description, key: 'description') // 30 | .isNotNull() 31 | .maxLength(4); 32 | 33 | final user = UserModel()..description = 'desc'; 34 | 35 | final result = validator.validate(user); 36 | 37 | expect(result.isValid, true); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /test/src/validations/is_null_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('is null validation ...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.description, key: 'description') // 12 | .isNull(); 13 | 14 | final user = UserModel()..description = 'description'; 15 | 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | 20 | expect(result.exceptions.length, 1); 21 | 22 | final error = result.exceptions.first; 23 | 24 | expect(error.message, r"'description' must be null."); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /test/src/validations/less_than_datetime_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('less than validation ...', () { 8 | final validator = TestLucidValidator(); 9 | final now = DateTime.now(); 10 | final tomorrow = now.add(Duration(days: 1)); 11 | 12 | validator 13 | .ruleFor((event) => event.end, key: 'end') // 14 | .lessThan(now); 15 | 16 | final event = EventModel()..end = tomorrow; 17 | 18 | final result = validator.validate(event); 19 | 20 | expect(result.isValid, false); 21 | expect(result.exceptions.length, 1); 22 | expect(result.exceptions.first.message, 23 | "'end' must be less than date '${now.toString()}'."); 24 | }); 25 | 26 | test('less than validation ...', () { 27 | final validator = TestLucidValidator(); 28 | final now = DateTime.now(); 29 | 30 | validator 31 | .ruleFor((event) => event.end, key: 'end') // 32 | .lessThanOrNull(now); 33 | 34 | final event = EventNullableModel()..end = null; 35 | 36 | final result = validator.validate(event); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/src/validations/less_than_or_equal_to_datetime_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('less than validation ...', () { 8 | final validator = TestLucidValidator(); 9 | final now = DateTime.now(); 10 | final tomorrow = now.add(Duration(days: 1)); 11 | 12 | validator 13 | .ruleFor((event) => event.end, key: 'end') // 14 | .lessThanOrEqualTo(now); 15 | 16 | final user = EventModel()..start = tomorrow; 17 | 18 | final result = validator.validate(user); 19 | 20 | expect(result.isValid, false); 21 | expect(result.exceptions.length, 1); 22 | expect(result.exceptions.first.message, 23 | "'end' must be less than or equal to date '${now.toString()}'."); 24 | }); 25 | 26 | test('less than or equal to validation ...', () { 27 | final validator = TestLucidValidator(); 28 | final now = DateTime.now(); 29 | 30 | validator 31 | .ruleFor((event) => event.end, key: 'end') // 32 | .lessThanOrEqualTo(now); 33 | 34 | final event = EventModel()..end = now; 35 | 36 | final result = validator.validate(event); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | 41 | test('less than or equal to validation or null ...', () { 42 | final validator = TestLucidValidator(); 43 | final now = DateTime.now(); 44 | 45 | validator 46 | .ruleFor((event) => event.end, key: 'end') // 47 | .lessThanOrEqualToOrNull(now); 48 | 49 | final event = EventNullableModel()..end = null; 50 | 51 | final result = validator.validate(event); 52 | 53 | expect(result.isValid, true); 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /test/src/validations/less_then_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('less than validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.age, key: 'age') // 11 | .lessThan(17); 12 | 13 | final user = UserModel()..age = 20; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, "'age' must be less than '17'."); 20 | }); 21 | 22 | test('less than validation or null...', () { 23 | final validator = TestLucidValidator(); 24 | validator 25 | .ruleFor((user) => user.age, key: 'age') // 26 | .lessThanOrNull(17); 27 | 28 | final user = UserNullableModel()..age = null; 29 | 30 | final result = validator.validate(user); 31 | 32 | expect(result.isValid, true); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/src/validations/matches_pattern_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('matches pattern validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.email, key: 'email') // 11 | .matchesPattern(r'^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$'); 12 | 13 | final user = UserModel()..email = 'teste.com'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "'email' is not in the correct format."); 21 | }); 22 | 23 | test('matches pattern validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.email, key: 'email') // 27 | .matchesPatternOrNull(r'^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$'); 28 | 29 | final user = UserNullableModel()..email = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/max_length_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('max length validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.password, key: 'password') // 11 | .maxLength(8); 12 | 13 | final user = UserModel()..password = '123456789'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "The length of 'password' must be 8 characters or fewer. You entered 9 characters."); 21 | }); 22 | 23 | test('max length validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.password, key: 'password') // 27 | .maxLengthOrNull(8); 28 | 29 | final user = UserNullableModel()..password = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/max_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('max validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.age, key: 'age') // 11 | .max(18); 12 | 13 | final user = UserModel()..age = 20; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "'age' must be less than or equal to 18. You entered 20."); 21 | }); 22 | 23 | test('max validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.age, key: 'age') // 27 | .maxOrNull(18); 28 | 29 | final user = UserNullableModel()..age = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/min_length_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('max length validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.password, key: 'password') // 11 | .minLength(8); 12 | 13 | final user = UserModel()..password = '123456'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "The length of 'password' must be at least 8 characters. You entered 6 characters."); 21 | }); 22 | 23 | test('max length validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.password, key: 'password') // 27 | .minLengthOrNull(8); 28 | 29 | final user = UserNullableModel()..password = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/min_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('min validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.age, key: 'age') // 11 | .min(18); 12 | 13 | final user = UserModel()..age = 17; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "'age' must be greater than or equal to 18. You entered 17."); 21 | }); 22 | 23 | test('min validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.age, key: 'age') // 27 | .minOrNull(18); 28 | 29 | final user = UserNullableModel()..age = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/must_have_lowercase_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('must have lowercase validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.password, key: 'password') // 11 | .mustHaveLowercase(); 12 | 13 | final user = UserModel()..password = 'AAAA'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "'password' must have at least one lowercase letter."); 21 | }); 22 | 23 | test('must have lowercase validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.password, key: 'password') // 27 | .mustHaveLowercaseOrNull(); 28 | 29 | final user = UserNullableModel()..password = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/must_have_number_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('must have number validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.password, key: 'password') // 11 | .mustHaveNumber(); 12 | 13 | final user = UserModel()..password = 'AAAAaaa'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "'password' must have at least one digit ('0'-'9')."); 21 | }); 22 | 23 | test('must have number validation or null ...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.password, key: 'password') // 27 | .mustHaveNumberOrNull(); 28 | 29 | final user = UserNullableModel()..password = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/must_have_special_character_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('must have special character validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.password, key: 'password') // 11 | .mustHaveSpecialCharacter(); 12 | 13 | final user = UserModel()..password = 'AAAAaaa124'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "'password' must have at least one non-alphanumeric character."); 21 | }); 22 | 23 | test('must have special character validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.password, key: 'password') // 27 | .mustHaveSpecialCharacterOrNull(); 28 | 29 | final user = UserNullableModel()..password = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/must_have_uppercase_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('must have uppercase validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.password, key: 'password') // 11 | .mustHaveUppercase(); 12 | 13 | final user = UserModel()..password = 'aaa124@'; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, 20 | "'password' must have at least one uppercase letter."); 21 | }); 22 | 23 | test('must have uppercase validation or null...', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.password, key: 'password') // 27 | .mustHaveUppercaseOrNull(); 28 | 29 | final user = UserNullableModel()..password = null; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/validations/not_empty_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('not empty validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.password, key: 'password') // 11 | .notEmpty(); 12 | 13 | final user = UserModel()..password = ''; 14 | 15 | final result = validator.validate(user); 16 | 17 | expect(result.isValid, false); 18 | expect(result.exceptions.length, 1); 19 | expect(result.exceptions.first.message, "'password' must not be empty."); 20 | }); 21 | 22 | test('not empty validation or null...', () { 23 | final validator = TestLucidValidator(); 24 | validator 25 | .ruleFor((user) => user.password, key: 'password') // 26 | .notEmptyOrNull(); 27 | 28 | final user = UserNullableModel()..password = null; 29 | 30 | final result = validator.validate(user); 31 | 32 | expect(result.isValid, true); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /test/src/validations/not_equal_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('not equal validation...', () { 8 | final validator = TestLucidValidator(); 9 | validator 10 | .ruleFor((user) => user.confirmPassword, key: 'confirmPassword') // 11 | .notEqualTo((user) => user.password); 12 | 13 | final user = UserModel() // 14 | ..password = 'teste123' 15 | ..confirmPassword = 'teste123'; 16 | 17 | final result = validator.validate(user); 18 | 19 | expect(result.isValid, false); 20 | expect(result.exceptions.length, 1); 21 | expect(result.exceptions.first.message, 22 | "'confirmPassword' must not be equal to 'teste123'."); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/src/validations/range_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('range validation ...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.age, key: 'age') // 12 | .range(18, 60); 13 | 14 | var user = UserModel()..age = 17; 15 | 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | 20 | expect(result.exceptions.length, 1); 21 | 22 | final error = result.exceptions.first; 23 | 24 | expect(error.message, "'age' must be between 18 and 60. You entered 17."); 25 | }); 26 | 27 | test('range validation ...', () { 28 | final validator = TestLucidValidator(); 29 | 30 | validator 31 | .ruleFor((e) => e.age, key: 'age') // 32 | .rangeOrNull(18, 60); 33 | 34 | var user = UserNullableModel()..age = null; 35 | 36 | final result = validator.validate(user); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/src/validations/repeated_characters_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/src/validations/validations.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | group('hasNoSequentialRepeatedCharacters', () { 8 | test('should fail when repeated characters sequence is present', () { 9 | final validator = TestLucidValidator(); 10 | validator 11 | .ruleFor((user) => user.password, key: 'password') 12 | .hasNoSequentialRepeatedCharacters(sequenceLength: 3); 13 | 14 | final user = UserModel()..password = 'aaabbb'; 15 | 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | expect(result.exceptions.length, 1); 20 | expect(result.exceptions.first.code, 'sequentialRepeatedCharacters'); 21 | }); 22 | 23 | test('should pass when no repeated character sequence is present', () { 24 | final validator = TestLucidValidator(); 25 | validator 26 | .ruleFor((user) => user.password, key: 'password') 27 | .hasNoSequentialRepeatedCharacters(sequenceLength: 3); 28 | 29 | final user = UserModel()..password = 'abcde'; 30 | 31 | final result = validator.validate(user); 32 | 33 | expect(result.isValid, true); 34 | }); 35 | }); 36 | 37 | group('hasNoSequentialRepeatedCharacters (nullable)', () { 38 | test('should fail when repeated characters sequence is present', () { 39 | final validator = TestLucidValidator(); 40 | validator 41 | .ruleFor((user) => user.password, key: 'password') 42 | .hasNoSequentialRepeatedCharacters(sequenceLength: 3); 43 | 44 | final user = UserNullableModel()..password = '1111'; 45 | 46 | final result = validator.validate(user); 47 | 48 | expect(result.isValid, false); 49 | expect(result.exceptions.length, 1); 50 | expect(result.exceptions.first.code, 'sequentialRepeatedCharacters'); 51 | }); 52 | 53 | test('should pass when nullable string has no repeated character sequence', () { 54 | final validator = TestLucidValidator(); 55 | validator 56 | .ruleFor((user) => user.password, key: 'password') 57 | .hasNoSequentialRepeatedCharacters(sequenceLength: 3); 58 | 59 | final user = UserNullableModel()..password = 'abcd'; 60 | 61 | final result = validator.validate(user); 62 | 63 | expect(result.isValid, true); 64 | }); 65 | 66 | test('should pass when nullable string is null', () { 67 | final validator = TestLucidValidator(); 68 | validator 69 | .ruleFor((user) => user.password, key: 'password') 70 | .hasNoSequentialRepeatedCharacters(sequenceLength: 3); 71 | 72 | final user = UserNullableModel()..password = null; 73 | 74 | final result = validator.validate(user); 75 | 76 | expect(result.isValid, true); 77 | }); 78 | }); 79 | 80 | group('hasNoSequentialRepeatedCharactersOrNull', () { 81 | test('should fail when repeated characters sequence is present', () { 82 | final validator = TestLucidValidator(); 83 | validator 84 | .ruleFor((user) => user.password, key: 'password') 85 | .hasNoSequentialRepeatedCharactersOrNull(sequenceLength: 3); 86 | 87 | final user = UserNullableModel()..password = 'zzzzy'; 88 | 89 | final result = validator.validate(user); 90 | 91 | expect(result.isValid, false); 92 | expect(result.exceptions.length, 1); 93 | expect(result.exceptions.first.code, 'sequentialRepeatedCharacters'); 94 | }); 95 | 96 | test('should pass when repeated characters sequence is not present', () { 97 | final validator = TestLucidValidator(); 98 | validator 99 | .ruleFor((user) => user.password, key: 'password') 100 | .hasNoSequentialRepeatedCharactersOrNull(sequenceLength: 3); 101 | 102 | final user = UserNullableModel()..password = 'abcd123'; 103 | 104 | final result = validator.validate(user); 105 | 106 | expect(result.isValid, true); 107 | }); 108 | 109 | test('should pass when value is null', () { 110 | final validator = TestLucidValidator(); 111 | validator 112 | .ruleFor((user) => user.password, key: 'password') 113 | .hasNoSequentialRepeatedCharactersOrNull(sequenceLength: 3); 114 | 115 | final user = UserNullableModel()..password = null; 116 | 117 | final result = validator.validate(user); 118 | 119 | expect(result.isValid, true); 120 | }); 121 | }); 122 | } 123 | -------------------------------------------------------------------------------- /test/src/validations/valid_cep_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('valid cep validation ...', () { 8 | final validator = TestLucidValidator
(); 9 | 10 | validator 11 | .ruleFor((e) => e.postcode, key: 'postcode') // 12 | .validCEP(); 13 | 14 | var customer = Address( 15 | country: 'Brazil', 16 | postcode: '1234578', 17 | ); 18 | 19 | final result = validator.validate(customer); 20 | 21 | expect(result.isValid, false); 22 | 23 | expect(result.exceptions.length, 1); 24 | 25 | final error = result.exceptions.first; 26 | 27 | expect(error.message, "'postcode' is not a valid CEP."); 28 | }); 29 | 30 | test('valid cep validation or null ...', () { 31 | final validator = TestLucidValidator(); 32 | 33 | validator 34 | .ruleFor((e) => e.postcode, key: 'postcode') // 35 | .validCEPOrNull(); 36 | 37 | var customer = AddressNullable(); 38 | 39 | final result = validator.validate(customer); 40 | 41 | expect(result.isValid, true); 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /test/src/validations/valid_cnpj_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('valid cnpj validation ...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.cnpj, key: 'cnpj') // 12 | .validCNPJ(); 13 | 14 | var customer = Customer( 15 | name: 'John Doe', 16 | address: Address( 17 | country: 'Brazil', 18 | postcode: '12345-678', 19 | ), 20 | cnpj: '12345678901234', 21 | ); 22 | 23 | final result = validator.validate(customer); 24 | 25 | expect(result.isValid, false); 26 | 27 | expect(result.exceptions.length, 1); 28 | 29 | final error = result.exceptions.first; 30 | 31 | expect(error.message, "'cnpj' is not a valid CNPJ."); 32 | }); 33 | 34 | test('valid cnpj validation ...', () { 35 | final validator = TestLucidValidator(); 36 | 37 | validator 38 | .ruleFor((e) => e.cnpj, key: 'cnpj') // 39 | .validCNPJOrNull(); 40 | 41 | var customer = CustomerNullable()..cnpj = null; 42 | 43 | final result = validator.validate(customer); 44 | 45 | expect(result.isValid, true); 46 | }); 47 | } 48 | -------------------------------------------------------------------------------- /test/src/validations/valid_cpf_or_cnpj_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('valid cpf or cnpj validation ...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.cpfOrCnpj, key: 'cpfOrCnpj', label: 'document') // 12 | .validCPFOrCNPJ(); 13 | 14 | final user = UserModel()..cpfOrCnpj = null; 15 | 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | 20 | expect(result.exceptions.length, 1); 21 | 22 | final error = result.exceptions.first; 23 | 24 | expect(error.message, "'document' is not a valid CPF or CNPJ."); 25 | }); 26 | 27 | test('valid cpf validation or null ...', () { 28 | final validator = TestLucidValidator(); 29 | 30 | validator 31 | .ruleFor((e) => e.cpfOrCnpj, key: 'cpfOrCnpj', label: 'document') // 32 | .validCPFOrCNPJOrNull(); 33 | 34 | final user = UserModel()..cpfOrCnpj = null; 35 | 36 | final result = validator.validate(user); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/src/validations/valid_cpf_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('valid cpf validation ...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.cpf, key: 'cpf') // 12 | .validCPF(); 13 | 14 | final user = UserModel()..cpf = null; 15 | 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | 20 | expect(result.exceptions.length, 1); 21 | 22 | final error = result.exceptions.first; 23 | 24 | expect(error.message, "'cpf' is not a valid CPF."); 25 | }); 26 | 27 | test('valid cpf validation or null ...', () { 28 | final validator = TestLucidValidator(); 29 | 30 | validator 31 | .ruleFor((e) => e.cpf, key: 'cpf') // 32 | .validCPFOrNull(); 33 | 34 | final user = UserNullableModel()..cpf = null; 35 | 36 | final result = validator.validate(user); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/src/validations/valid_creditcard_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('valid creditcard validation ...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.number, key: 'number') // 12 | .validCreditCard(); 13 | 14 | final creditCard = CreditCardModel()..number = '1'; 15 | 16 | final result = validator.validate(creditCard); 17 | 18 | expect(result.isValid, false); 19 | 20 | expect(result.exceptions.length, 1); 21 | 22 | final error = result.exceptions.first; 23 | 24 | expect(error.message, "'number' is not a valid credit card number."); 25 | }); 26 | 27 | test('valid creditcard validation or null ...', () { 28 | final validator = TestLucidValidator(); 29 | 30 | validator 31 | .ruleFor((e) => e.number, key: 'number') // 32 | .validCreditCardOrNull(); 33 | 34 | final creditCard = CreditCardNullableModel()..number = null; 35 | 36 | final result = validator.validate(creditCard); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/src/validations/valid_email_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('valid email validation ...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.email, key: 'email', label: 'E-mail') // 12 | .validEmail(); 13 | 14 | final user = UserModel()..email = 'testtest.com'; 15 | 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | 20 | expect(result.exceptions.length, 1); 21 | 22 | final error = result.exceptions.first; 23 | 24 | expect(error.message, "'E-mail' is not a valid email address."); 25 | }); 26 | 27 | test('valid email validation ...', () { 28 | final validator = TestLucidValidator(); 29 | 30 | validator 31 | .ruleFor((e) => e.email, key: 'email', label: 'E-mail') // 32 | .validEmailOrNull(); 33 | 34 | final user = UserNullableModel()..email = null; 35 | 36 | final result = validator.validate(user); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/src/validations/valid_phone_validation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:lucid_validation/lucid_validation.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../../mocks/mocks.dart'; 5 | 6 | void main() { 7 | test('valid phone validation failed...', () { 8 | final validator = TestLucidValidator(); 9 | 10 | validator 11 | .ruleFor((e) => e.phone, key: 'phone', label: 'Phone') // 12 | .validPhoneBROrNull(); 13 | 14 | final user = UserModel()..phone = '751234567'; 15 | 16 | final result = validator.validate(user); 17 | 18 | expect(result.isValid, false); 19 | 20 | expect(result.exceptions.length, 1); 21 | 22 | final error = result.exceptions.first; 23 | 24 | expect(error.message, "'Phone' is not a valid phone number."); 25 | }); 26 | 27 | test('valid phone validation ...', () { 28 | final validator = TestLucidValidator(); 29 | 30 | validator 31 | .ruleFor((e) => e.phone, key: 'phone', label: 'Phone') // 32 | .validPhoneBR(); 33 | 34 | final user = UserModel()..phone = '75912345678'; 35 | 36 | final result = validator.validate(user); 37 | 38 | expect(result.isValid, true); 39 | }); 40 | 41 | test('valid phone ddi validation failed...', () { 42 | final validator = TestLucidValidator(); 43 | 44 | validator 45 | .ruleFor((e) => e.phone, key: 'phone', label: 'Phone') // 46 | .validPhoneWithCountryCodeBR(); 47 | 48 | final user = UserModel()..phone = '751234567'; 49 | 50 | final result = validator.validate(user); 51 | 52 | expect(result.isValid, false); 53 | 54 | expect(result.exceptions.length, 1); 55 | 56 | final error = result.exceptions.first; 57 | 58 | expect(error.message, '\'Phone\' is not a valid phone number with DDI.'); 59 | }); 60 | 61 | test('valid phone ddi validation ...', () { 62 | final validator = TestLucidValidator(); 63 | 64 | validator 65 | .ruleFor((e) => e.phone, key: 'phone', label: 'Phone') // 66 | .validPhoneWithCountryCodeBR(); 67 | 68 | final user = UserModel()..phone = '+5575912345678'; 69 | 70 | final result = validator.validate(user); 71 | 72 | expect(result.isValid, true); 73 | }); 74 | } 75 | --------------------------------------------------------------------------------