├── .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 ├── lib │ ├── api │ │ └── fake_api.dart │ ├── entities │ │ ├── book.dart │ │ └── json_schema.dart │ ├── forms │ │ ├── login_form.dart │ │ ├── order_form.dart │ │ └── registration_form.dart │ └── main.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.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 ├── flutter_auto_form.dart └── src │ ├── configuration │ ├── defaults.dart │ └── typedef.dart │ ├── json_schema │ ├── form.dart │ └── json_schema.dart │ ├── models │ ├── error.dart │ ├── field │ │ ├── defaults.dart │ │ ├── field.dart │ │ ├── field_context.dart │ │ └── utils.dart │ ├── form.dart │ └── validators │ │ ├── defaults.dart │ │ ├── regex.dart │ │ └── validator.dart │ └── widgets │ ├── fields │ ├── boolean_field.dart │ ├── date_field.dart │ ├── fields.dart │ ├── interface.dart │ ├── multiple_sub_form_field.dart │ ├── search_field.dart │ ├── select_field.dart │ ├── sub_form_field.dart │ └── text_field.dart │ ├── form.dart │ ├── form_state.dart │ ├── theme.dart │ └── utils │ └── loading_widget.dart ├── pubspec.yaml └── test └── models └── validators └── default_validators_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | *.lock 7 | .DS_Store 8 | .atom/ 9 | .buildlog/ 10 | .history 11 | .svn/ 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 | **/doc/api/ 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | build/ 33 | 34 | # Android related 35 | **/android/**/gradle-wrapper.jar 36 | **/android/.gradle 37 | **/android/captures/ 38 | **/android/gradlew 39 | **/android/gradlew.bat 40 | **/android/local.properties 41 | **/android/**/GeneratedPluginRegistrant.java 42 | 43 | # iOS/XCode related 44 | **/ios/**/*.mode1v3 45 | **/ios/**/*.mode2v3 46 | **/ios/**/*.moved-aside 47 | **/ios/**/*.pbxuser 48 | **/ios/**/*.perspectivev3 49 | **/ios/**/*sync/ 50 | **/ios/**/.sconsign.dblite 51 | **/ios/**/.tags* 52 | **/ios/**/.vagrant/ 53 | **/ios/**/DerivedData/ 54 | **/ios/**/Icon? 55 | **/ios/**/Pods/ 56 | **/ios/**/.symlinks/ 57 | **/ios/**/profile 58 | **/ios/**/xcuserdata 59 | **/ios/.generated/ 60 | **/ios/Flutter/App.framework 61 | **/ios/Flutter/Flutter.framework 62 | **/ios/Flutter/Flutter.podspec 63 | **/ios/Flutter/Generated.xcconfig 64 | **/ios/Flutter/app.flx 65 | **/ios/Flutter/app.zip 66 | **/ios/Flutter/flutter_assets/ 67 | **/ios/Flutter/flutter_export_environment.sh 68 | **/ios/ServiceDefinitions.json 69 | **/ios/Runner/GeneratedPluginRegistrant.* 70 | 71 | # Exceptions to above rules. 72 | !**/ios/**/default.mode1v3 73 | !**/ios/**/default.mode2v3 74 | !**/ios/**/default.pbxuser 75 | !**/ios/**/default.perspectivev3 76 | -------------------------------------------------------------------------------- /.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: 9b2d32b605630f28625709ebd9d78ab3016b2bf6 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [2.0.0] - 04-24-2024 2 | 3 | * Migrating to Dart SDK '>=3.3.3 <4.0.0' 4 | * Updating dependencies, fixing date_field breaking changes 5 | 6 | ## [1.0.7] - 09-27-2023 7 | 8 | * Fixing README.md 9 | 10 | ## [1.0.6] - 09-27-2023 11 | 12 | * Fixing README.md 13 | * Updating dependencies 14 | 15 | ## [1.0.5] - 04-21-2023 16 | 17 | * Adding the possibility to add a callback when the value of a field changes. 18 | * Adding an updateStream for widgets to rebuild whenever the updateValue method is called 19 | * Cleaning up issues from dartanalyzer 20 | 21 | ## [1.0.4] - 03-29-2023 22 | 23 | * Improving the boolean field widget 24 | 25 | ## [1.0.3] - 03-24-2023 26 | 27 | * Fixing search field 28 | 29 | * ## [1.0.2] - 03-06-2023 30 | 31 | * Improving sub forms support 32 | 33 | ## [1.0.1] - 11-09-2022 34 | 35 | * Adding sub forms through the addition of AFMultipleSubFormField, AFSubFormField and the linked default widgets. 36 | 37 | ## [1.0.0] - 10-21-2022 38 | 39 | * Making some private endpoints public 40 | 41 | ## [1.0.0-dev.2] - 05-26-2022 42 | 43 | * Updating the dropdown search package 44 | 45 | ## [1.0.0-dev.1] - 03-09-2022 46 | 47 | * Breaking changes: 48 | * Dart 2.15 49 | * The AFTheme widget does not allow you to change the text field builder anymore. To do such a thing you should now 50 | extend the AFTextField and replace the widgetBuilder property by the one of your choice. 51 | * The AFFileField was removed due to too strong dependencies need (dart:io...). 52 | * Validators now accept null value by default. To prevent a field from being null, you should use the 53 | NotNullValidator or the NotEmptyValidator in the case of a string. 54 | * Adding new build system 55 | * Adding the possibility to make a AFTextField widget multiline 56 | >>>>>>> 49a0ce67aa037e85d7ef317e89507cf62ef52ce3 57 | 58 | ## [0.4.2] - 10-18-2021 59 | 60 | * Improving the custom field system 61 | 62 | ## [0.4.1] - 10-13-2021 63 | 64 | * Adding unit test for each validator 65 | * Normalizing the SameAsFieldValidator (constructor argument position was inverted) 66 | 67 | ## [0.4.0] - 10-13-2021 68 | 69 | * Breaking Changes: the submitButton doesn't allow the showFutureDialog parameter. You should now use the 70 | enableSubmitFormWrapper argument of the AFWidget, AFFormState or if you want to specify the global behavior, use the 71 | AFTheme widget. 72 | 73 | ## [0.3.3] - 10-12-2021 74 | 75 | * Fixing email validator 76 | 77 | ## [0.3.2] - 10-05-2021 78 | 79 | * The multiple form field can now be instantiated with already existing form instances 80 | 81 | ## [0.3.1] - 10-05-2021 82 | 83 | * Improving the way sub-forms work 84 | 85 | ## [0.3.0] - 10-05-2021 86 | 87 | * Adding a Widget suffix to each internal field's widget. 88 | * Adding support for AFFormField and AFMultipleFormField to allow sub-form system. (you now create infinite forms in a 89 | cascade) 90 | * Fixing dart:io import (for web) 91 | * Adding some documentation to internal widgets 92 | * Fixing the email validator regex 93 | 94 | ## [0.2.9] - 10-04-2021 95 | 96 | * An issue with the SimpleFile bytes property has been fixed. 97 | 98 | ## [0.2.8] - 09-28-2021 99 | 100 | * Adding SearchMultipleModelsField, AFSearchMultipleModelsField 101 | 102 | ## [0.2.7] - 09-23-2021 103 | 104 | * Adding FileField & SelectField 105 | * Moving boolean field to a widget of its own 106 | * Adding default padding on submit button 107 | 108 | ## [0.2.6] - 09-23-2021 109 | 110 | * Fixing hex color validator 111 | 112 | ## [0.2.5] - 09-23-2021 113 | 114 | * Updating the hex color validator. The validation mode can now be specified (with #, without or both). 115 | * Adding the possibility to disable the final action with the AFWidget. 116 | 117 | ## [0.2.4] - 09-23-2021 118 | 119 | * Exporting the validator.dart file inside the library main file. 120 | 121 | ## [0.2.3] - 09-09-2021 122 | 123 | * Moving to a MIT license 124 | 125 | ## [0.2.2] - 09-09-2021 126 | 127 | * Adding AFSearchModelField 128 | * Adding AFBooleanField 129 | * Improving example 130 | * Improving README.md 131 | * Adding dropdown_search as a dependency 132 | 133 | ## [0.2.1] - 09-09-2021 134 | 135 | * AFWidgetState is now a public api. 136 | 137 | ## [0.2.0] - 09-09-2021 138 | 139 | * Moving from positional to named parameters for AFTextField. 140 | * Adding support for custom parser for the Field class. 141 | * Improving doc 142 | 143 | ## [0.1.1] - 09-08-2021. 144 | 145 | * Fixing documentation 146 | 147 | ## [0.1.0] - 09-08-2021. 148 | 149 | * Adding documentation 150 | * Adding the ability to specify the type for the NotNullValidator. 151 | 152 | ## [0.0.9] - 07-21-2021. 153 | 154 | * Adding auto trim for email field validator 155 | 156 | ## [0.0.8] - 07-21-2021. 157 | 158 | * Adding auto trim for email field 159 | 160 | ## [0.0.7] - 06-27-2021. 161 | 162 | * Renaming AutoForm to AF => less verbose 163 | * Fixing a type issue 164 | * Decoupling the AFTheme into AFTheme and AFThemeData 165 | 166 | ## [0.0.6] - 04-07-2021. 167 | 168 | * Migrating to null safety 169 | 170 | ## [0.0.5] - 04-02-2021. 171 | 172 | * Fixing issue with the loading dialog 173 | * Adding first pieces of documentation 174 | 175 | ## [0.0.4] - 04-02-2021. 176 | 177 | * Removing debug code 178 | * Refactoring code 179 | * Upgrading smarted_text_field to v0.0.2 180 | 181 | ## [0.0.3] - 04-02-2021. 182 | 183 | * Renaming AutoFormFormState to AutoFormWidgetState 184 | 185 | ## [0.0.2] - 04-02-2021. 186 | 187 | * Replacing the config singleton with an InheritedWidget. 188 | * Adding the ability to handle error message on form submission 189 | 190 | ## [0.0.1] - 03-31-2021. 191 | 192 | * Init version 193 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | ----------- 3 | 4 | Copyright (c) 2021 Gaspard Merten 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter Auto Form 2 | 3 | ## [![pub package](https://img.shields.io/pub/v/flutter_auto_form.svg)](https://pub.dev/packages/flutter_auto_form) 4 | 5 | **The easiest way to create fully customizable forms with only a tiny amount of code.** 6 | 7 | ## Introduction 8 | 9 | Are you tired of writing endless lines of code to create forms in your Flutter apps? Look no further! Our Flutter Auto 10 | Form package is here to revolutionize your form-building experience. 11 | 12 | Our primary goal is to significantly reduce the amount of code required to create forms in Flutter. We achieve this by 13 | embracing a clear separation of concerns between form logic and form display. 14 | 15 | With Flutter Auto Form, you write the form logic in pure Dart, without any direct mention of widgets. Instead, we 16 | introduce the AFWidget, which dynamically renders all the necessary widgets based on a straightforward form 17 | declaration—a simple Dart class that extends the TemplateForm class. 18 | 19 | But that's not all! Our package empowers you to design your custom fields and linked widgets, making nearly any form 20 | conceivable. Whether you're working on basic forms or tackling complex ones, Flutter Auto Form has got you covered. 21 | 22 | The true magic of Flutter Auto Form shines when you're dealing with multiple forms, especially complex ones. All your 23 | validators are automatically called when you submit a form, and you can even create sub-forms that cascade into one 24 | another. 25 | 26 | Dynamic form generation is also feasible but still in experimental mode. It is accessible through the 27 | JsonSchemaForm class. 28 | 29 | 30 | 31 | ## Installation 32 | 33 | To use this plugin, add `flutter_auto_form` as 34 | a [dependency in your pubspec.yaml file](https://plus.fluttercommunity.dev/docs/overview). 35 | 36 | pubspec.yaml

37 | 38 | ```yaml 39 | dependencies: 40 | flutter: 41 | sdk: flutter 42 | 43 | # Your other packages ... 44 | 45 | flutter_auto_form: ^1.0.6 46 | ``` 47 | 48 | ## Support 49 | 50 | * Platforms: **All platforms currently supported** 51 | * Autofill hints: **Automatic support through AFTextFieldType** 52 | * Validators: **Email, Url, Hex colour, Not null, Minimum string length, Same as another field, Alphanumeric.** 53 | * Fields: **Password _(auto obscure toggle)_, Text, Number, Model _(built-in support for search through an api)_, 54 | Boolean, Sub-form _(cascading forms)_, Select _(dropdown field allowing only predefined values)_** 55 | * Custom code: **You can customize and create new fields, validators, widgets as you please without even touching the 56 | source code of this package !** 57 | 58 | ## Usage 59 | 60 | The first step in creating a form with Flutter Auto Form is to create a class inheriting from the TemplateForm class. 61 | 62 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 63 | 64 | ```dart 65 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 66 | 67 | class LoginForm extends TemplateForm { 68 | @override 69 | final List fields = [ 70 | AFTextField( 71 | id: 'identifier', 72 | name: 'Identifier', 73 | validators: [ 74 | MinimumStringLengthValidator( 75 | 5, 76 | (e) => 'Min 5 characters, currently ${e?.length ?? 0} ', 77 | ) 78 | ], 79 | type: AFTextFieldType.USERNAME, 80 | ), 81 | AFTextField( 82 | id: 'password', 83 | name: 'Password', 84 | validators: [ 85 | MinimumStringLengthValidator( 86 | 6, 87 | (e) => 'Min 6 characters, currently ${e?.length ?? 0} ', 88 | ) 89 | ], 90 | type: AFTextFieldType.PASSWORD, 91 | ), 92 | AFBooleanField( 93 | id: 'accept-condition', 94 | name: 'Accept terms', 95 | validators: [ShouldBeTrueValidator('Please accept terms to continue?')], 96 | value: false, 97 | ) 98 | ]; 99 | } 100 | 101 | ``` 102 | 103 | The second & (already) last step is to add the AFWidget wherever you would like to display a form. 104 | 105 | ```dart 106 | AFWidget( 107 | formBuilder: () => RegistrationForm(), 108 | submitButton: (Function({bool showLoadingDialog}) submit) => Padding( 109 | padding: const EdgeInsets.only(top: 32), 110 | child: MaterialButton( 111 | child: Text('Submit'), 112 | onPressed: () => submit(showLoadingDialog: true), 113 | ), 114 | ), 115 | onSubmitted: (RegistrationForm form) { 116 | // do whatever you want when the form is submitted 117 | print(form.toMap()); 118 | }, 119 | ); 120 | ``` 121 | ## Example 122 | 123 | A demo video can be found [here](https://drive.google.com/uc?id=1axi4CSEYflt3oxmnvEI9pIpOMjN4AJD2). The 124 | four forms displayed in the video are all created with Flutter Auto Form, even the model search field. 125 | 126 | The source code is located in the example folder. 127 | 128 | ## Advanced usage 129 | 130 | If you need to create your own field (color field, image field, ...) you can always create it by overriding the Field 131 | class. Then to display a custom widget, create a stateful widget that extends the FieldStatefulWidget, and of which the 132 | state extends the FieldState class. 133 | 134 | ## 135 | 136 | This package is still under construction ! Do not hesitate to create an issue on the GitHub page if you find any bug 137 | or if you would like to see a new type of validator, field ! -------------------------------------------------------------------------------- /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 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | -------------------------------------------------------------------------------- /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: "54e66469a933b60ddf175f858f82eaeb97e48c8d" 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: 54e66469a933b60ddf175f858f82eaeb97e48c8d 17 | base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d 18 | - platform: linux 19 | create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d 20 | base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d 21 | - platform: macos 22 | create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d 23 | base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d 24 | - platform: windows 25 | create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d 26 | base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d 27 | 28 | # User provided section 29 | 30 | # List of Local paths (relative to this file) that should be 31 | # ignored by the migrate tool. 32 | # 33 | # Files that are not part of the templates will be ignored by default. 34 | unmanaged_files: 35 | - 'lib/main.dart' 36 | - 'ios/Runner.xcodeproj/project.pbxproj' 37 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, samples, guidance on mobile development, and a 16 | full API reference. 17 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # Specify analysis options. 2 | # 3 | # Until there are meta linter rules, each desired lint must be explicitly enabled. 4 | # See: https://github.com/dart-lang/linter/issues/288 5 | # 6 | # For a list of lints, see: http://dart-lang.github.io/linter/lints/ 7 | # See the configuration guide for more 8 | # https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer 9 | # 10 | # There are other similar analysis options files in the flutter repos, 11 | # which should be kept in sync with this file: 12 | # 13 | # - analysis_options.yaml (this file) 14 | # - packages/flutter/lib/analysis_options_user.yaml 15 | # - https://github.com/flutter/plugins/blob/master/analysis_options.yaml 16 | # - https://github.com/flutter/engine/blob/master/analysis_options.yaml 17 | # 18 | # This file contains the analysis options used by Flutter tools, such as IntelliJ, 19 | # Android Studio, and the `flutter analyze` command. 20 | 21 | analyzer: 22 | errors: 23 | # treat missing required parameters as a warning (not a hint) 24 | missing_required_param: warning 25 | # treat missing returns as a warning (not a hint) 26 | missing_return: warning 27 | # allow having TODOs in the code 28 | todo: ignore 29 | # Ignore analyzer hints for updating pubspecs when using Future or 30 | # Stream and not importing dart:async 31 | # Please see https://github.com/flutter/flutter/pull/24528 for details. 32 | sdk_version_async_exported_from_core: ignore 33 | exclude: 34 | - "bin/cache/**" 35 | # the following two are relative to the stocks example and the flutter package respectively 36 | # see https://github.com/dart-lang/sdk/issues/28463 37 | - "lib/i18n/stock_messages_*.dart" 38 | - "lib/src/http/**" 39 | 40 | linter: 41 | rules: 42 | # these rules are documented on and in the same order as 43 | # the Dart Lint rules page to make maintenance easier 44 | # https://github.com/dart-lang/linter/blob/master/example/all.yaml 45 | - always_declare_return_types 46 | # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219 47 | - always_require_non_null_named_parameters 48 | # - always_specify_types 49 | - annotate_overrides 50 | # - avoid_annotating_with_dynamic # conflicts with always_specify_types 51 | - avoid_bool_literals_in_conditional_expressions 52 | # - avoid_catches_without_on_clauses # we do this commonly 53 | # - avoid_catching_errors # we do this commonly 54 | - avoid_classes_with_only_static_members 55 | # - avoid_double_and_int_checks # only useful when targeting JS runtime 56 | - avoid_empty_else 57 | - avoid_field_initializers_in_const_classes 58 | - avoid_function_literals_in_foreach_calls 59 | - prefer_conditional_assignment 60 | 61 | # - avoid_implementing_value_types # not yet tested 62 | - avoid_init_to_null 63 | # - avoid_js_rounded_ints # only useful when targeting JS runtime 64 | - avoid_null_checks_in_equality_operators 65 | # - avoid_positional_boolean_parameters # not yet tested 66 | # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356) 67 | - avoid_relative_lib_imports 68 | - avoid_renaming_method_parameters 69 | - avoid_return_types_on_setters 70 | # - avoid_returning_null # there are plenty of valid reasons to return null 71 | # - avoid_returning_null_for_future # not yet tested 72 | - avoid_returning_null_for_void 73 | # - avoid_returning_this # there are plenty of valid reasons to return this 74 | # - avoid_setters_without_getters # not yet tested 75 | # - avoid_shadowing_type_parameters # not yet tested 76 | # - avoid_single_cascade_in_expression_statements # not yet tested 77 | - avoid_slow_async_io 78 | - avoid_types_as_parameter_names 79 | # - avoid_types_on_closure_parameters # conflicts with always_specify_types 80 | - avoid_unused_constructor_parameters 81 | - avoid_void_async 82 | - await_only_futures 83 | - camel_case_types 84 | - cancel_subscriptions 85 | # - cascade_invocations # not yet tested 86 | # - close_sinks # not reliable enough 87 | # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765 88 | # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 89 | - control_flow_in_finally 90 | # - curly_braces_in_flow_control_structures # not yet tested 91 | # - diagnostic_describe_all_properties # not yet tested 92 | - directives_ordering 93 | - empty_catches 94 | - empty_constructor_bodies 95 | - empty_statements 96 | # - file_names # not yet tested 97 | - hash_and_equals 98 | - implementation_imports 99 | # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811 100 | - iterable_contains_unrelated_type 101 | # - join_return_with_assignment # not yet tested 102 | - library_names 103 | - library_prefixes 104 | # - lines_longer_than_80_chars # not yet tested 105 | - list_remove_unrelated_type 106 | # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181 107 | - no_adjacent_strings_in_list 108 | - no_duplicate_case_values 109 | - non_constant_identifier_names 110 | # - null_closures # not yet tested 111 | # - omit_local_variable_types # opposite of always_specify_types 112 | # - one_member_abstracts # too many false positives 113 | # - only_throw_errors # https://github.com/flutter/flutter/issues/5792 114 | - overridden_fields 115 | - package_api_docs 116 | - package_names 117 | - package_prefixed_library_names 118 | # - parameter_assignments # we do this commonly 119 | - prefer_adjacent_string_concatenation 120 | - prefer_asserts_in_initializer_lists 121 | # - prefer_asserts_with_message # not yet tested 122 | - prefer_collection_literals 123 | - prefer_const_constructors 124 | - prefer_const_constructors_in_immutables 125 | - prefer_const_declarations 126 | - prefer_const_literals_to_create_immutables 127 | # - prefer_constructors_over_static_methods # not yet tested 128 | - prefer_contains 129 | # - prefer_double_quotes # opposite of prefer_single_quotes 130 | - prefer_equal_for_default_values 131 | # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods 132 | - prefer_final_fields 133 | - prefer_final_in_for_each 134 | - prefer_final_locals 135 | # - prefer_for_elements_to_map_fromIterable # not yet tested 136 | - prefer_foreach 137 | # - prefer_function_declarations_over_variables # not yet tested 138 | # - prefer_generic_function_type_aliases 139 | # - prefer_if_elements_to_conditional_expressions # not yet tested 140 | - prefer_if_null_operators 141 | - prefer_initializing_formals 142 | - prefer_inlined_adds 143 | # - prefer_int_literals # not yet tested 144 | # - prefer_interpolation_to_compose_strings # not yet tested 145 | - prefer_is_empty 146 | - prefer_is_not_empty 147 | - prefer_iterable_whereType 148 | # - prefer_mixin # https://github.com/dart-lang/language/issues/32 149 | # - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932 150 | - prefer_single_quotes 151 | - prefer_spread_collections 152 | - prefer_typing_uninitialized_variables 153 | - prefer_void_to_null 154 | # - provide_deprecation_message # not yet tested 155 | # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml 156 | - recursive_getters 157 | - slash_for_doc_comments 158 | # - sort_child_properties_last # not yet tested 159 | - sort_constructors_first 160 | - sort_unnamed_constructors_first 161 | - test_types_in_equals 162 | - throw_in_finally 163 | # - type_annotate_public_apis # subset of always_specify_types 164 | - type_init_formals 165 | # - unawaited_futures # too many false positives 166 | # - unnecessary_await_in_return # not yet tested 167 | - unnecessary_brace_in_string_interps 168 | - unnecessary_const 169 | - unnecessary_getters_setters 170 | # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498 171 | - unnecessary_new 172 | - unnecessary_null_aware_assignments 173 | - unnecessary_null_in_if_null_operators 174 | - unnecessary_overrides 175 | - unnecessary_parenthesis 176 | - unnecessary_statements 177 | - unnecessary_this 178 | - unrelated_type_equality_checks 179 | # - unsafe_html # not yet tested 180 | - use_full_hex_values_for_flutter_colors 181 | # - use_function_type_syntax_for_parameters # not yet tested 182 | - use_rethrow_when_possible 183 | # - use_setters_to_change_properties # not yet tested 184 | # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182 185 | # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review 186 | - valid_regexps 187 | # - void_checks # not yet tested -------------------------------------------------------------------------------- /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/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion 31 30 | 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_1_8 33 | targetCompatibility JavaVersion.VERSION_1_8 34 | } 35 | 36 | kotlinOptions { 37 | jvmTarget = '1.8' 38 | } 39 | 40 | sourceSets { 41 | main.java.srcDirs += 'src/main/kotlin' 42 | } 43 | 44 | defaultConfig { 45 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 46 | applicationId "com.example.example" 47 | minSdkVersion 16 48 | targetSdkVersion 31 49 | versionCode flutterVersionCode.toInteger() 50 | versionName flutterVersionName 51 | } 52 | 53 | buildTypes { 54 | release { 55 | // TODO: Add your own signing config for the release build. 56 | // Signing with the debug keys for now, so `flutter run --release` works. 57 | signingConfig signingConfigs.debug 58 | } 59 | } 60 | } 61 | 62 | flutter { 63 | source '../..' 64 | } 65 | 66 | dependencies { 67 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 68 | } 69 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 13 | 17 | 21 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /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 | } 7 | -------------------------------------------------------------------------------- /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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.6.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | tasks.register("clean", Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip 7 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/app.flx 22 | Flutter/app.zip 23 | Flutter/flutter_assets/ 24 | Flutter/flutter_export_environment.sh 25 | ServiceDefinitions.json 26 | Runner/GeneratedPluginRegistrant.* 27 | 28 | # Exceptions to above rules. 29 | !default.mode1v3 30 | !default.mode2v3 31 | !default.pbxuser 32 | !default.perspectivev3 33 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | 8.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 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /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 UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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`, 6 | 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 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | example 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/entities/book.dart: -------------------------------------------------------------------------------- 1 | class Book { 2 | Book({required this.title, required this.pages}); 3 | 4 | final String title; 5 | final List pages; 6 | 7 | @override 8 | String toString() => title; 9 | } 10 | 11 | class Page { 12 | Page({required this.content, required this.number}); 13 | 14 | final String content; 15 | final int number; 16 | } 17 | -------------------------------------------------------------------------------- /example/lib/entities/json_schema.dart: -------------------------------------------------------------------------------- 1 | const Map jsonSchema = { 2 | '\$schema': 'https://json-schema.org/draft/2020-12/schema', 3 | '\$id': '', 4 | 'title': 'Vieux fromages', 5 | 'description': 'Description', 6 | 'type': 'object', 7 | 'properties': { 8 | 'Age (année)': { 9 | 'type': 'integer', 10 | 'min': 1900, 11 | 'max': 2021, 12 | 'default': 2001, 13 | 'examples': [2001] 14 | }, 15 | 'Type': { 16 | 'type': 'string', 17 | 'default': 'Molle', 18 | 'enum': ['Molle', 'Cremeux', 'Dure', 'Rapé'] 19 | }, 20 | 'Type de lait': { 21 | 'type': 'string', 22 | 'default': 'Bufflone', 23 | 'examples': ['Bufflone', 'Vache'] 24 | }, 25 | 'Provenance': {'type': 'string', 'examples': []}, 26 | 'Affinage': {'type': 'string', 'examples': []}, 27 | 'Bio': {'type': 'boolean', 'enum': []}, 28 | 'Conservation': { 29 | 'type': 'string', 30 | 'default': '1 semaine frigo', 31 | 'examples': ['1 semaine frigo'] 32 | }, 33 | 'name': {'type': 'string'} 34 | }, 35 | 'required': ['Ca'] 36 | }; 37 | -------------------------------------------------------------------------------- /example/lib/forms/login_form.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 2 | 3 | class LoginForm extends TemplateForm { 4 | @override 5 | final List fields = [ 6 | AFTextField( 7 | id: 'identifier', 8 | name: 'Identifier', 9 | validators: [ 10 | MinimumStringLengthValidator( 11 | 5, 12 | (e) => 'Min 5 characters, currently ${e?.length ?? 0} ', 13 | ) 14 | ], 15 | type: AFTextFieldType.username, 16 | ), 17 | AFTextField( 18 | id: 'password', 19 | name: 'Password', 20 | validators: [ 21 | MinimumStringLengthValidator( 22 | 6, 23 | (e) => 'Min 6 characters, currently ${e?.length ?? 0} ', 24 | ) 25 | ], 26 | type: AFTextFieldType.password, 27 | ), 28 | AFBooleanField( 29 | id: 'accept-condition', 30 | name: 'Accept terms', 31 | validators: [ShouldBeTrueValidator('Please accept terms')], 32 | value: false, 33 | ), 34 | ]; 35 | } 36 | -------------------------------------------------------------------------------- /example/lib/forms/order_form.dart: -------------------------------------------------------------------------------- 1 | import 'package:auto_form_example/api/fake_api.dart'; 2 | import 'package:auto_form_example/entities/book.dart'; 3 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 4 | 5 | class OrderForm extends TemplateForm { 6 | @override 7 | late final List> fields = [ 8 | AFNumberField( 9 | id: 'order-number', 10 | name: 'Order\'s number', 11 | validators: [NotNullValidator('Please enter a valid integer')], 12 | ), 13 | AFBooleanField( 14 | id: 'payed', 15 | name: 'Is payed', 16 | validators: [], 17 | value: false, 18 | ), 19 | AFSelectField( 20 | id: 'select', 21 | name: 'Select', 22 | validators: [], 23 | values: [1, 2], 24 | textBuilder: (e) => e.toString(), 25 | value: 1, 26 | ), 27 | AFSearchMultipleModelsField( 28 | id: 'books', 29 | name: 'Books', 30 | validators: [NotEmptyListValidator('Please select at least one book')], 31 | search: searchBook, 32 | onChanged: (e) { 33 | set('number_books', e?.length ?? 0); 34 | }), 35 | AFNumberField( 36 | id: 'number_books', 37 | name: 'Number of books', 38 | validators: [], 39 | ) 40 | ]; 41 | } 42 | -------------------------------------------------------------------------------- /example/lib/forms/registration_form.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 2 | 3 | class RegistrationForm extends TemplateForm { 4 | final Field passwordField = AFTextField( 5 | id: 'password', 6 | name: 'Password', 7 | validators: [ 8 | MinimumStringLengthValidator( 9 | 6, 10 | (e) => 'Min 6 cara. Currently: ${e?.length ?? 0}', 11 | ) 12 | ], 13 | type: AFTextFieldType.newPassword, 14 | ); 15 | 16 | @override 17 | late List fields = [ 18 | AFTextField( 19 | id: 'email', 20 | name: 'E-mail address', 21 | validators: [ 22 | NotNullValidator('This field cannot be empty'), 23 | EmailValidator( 24 | 'Invalid email', 25 | ), 26 | ], 27 | type: AFTextFieldType.email, 28 | ), 29 | passwordField, 30 | AFTextField( 31 | id: 'verify', 32 | name: 'Confirm password', 33 | validators: [ 34 | SameAsFieldValidator( 35 | passwordField, 36 | 'Passwords not matching', 37 | ), 38 | ], 39 | type: AFTextFieldType.newPassword, 40 | ), 41 | ]; 42 | } 43 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:auto_form_example/forms/order_form.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 4 | 5 | import 'entities/json_schema.dart'; 6 | import 'forms/login_form.dart'; 7 | import 'forms/registration_form.dart'; 8 | 9 | void main() { 10 | runApp(MyApp()); 11 | } 12 | 13 | class MyApp extends StatelessWidget { 14 | @override 15 | Widget build(BuildContext context) { 16 | return AFTheme( 17 | data: const AFThemeData(), 18 | child: MaterialApp( 19 | title: 'Auto Form Demo', 20 | debugShowCheckedModeBanner: false, 21 | theme: ThemeData( 22 | primarySwatch: Colors.blue, 23 | visualDensity: VisualDensity.adaptivePlatformDensity, 24 | ), 25 | home: const MyHomePage(), 26 | ), 27 | ); 28 | } 29 | } 30 | 31 | class MyHomePage extends StatefulWidget { 32 | const MyHomePage({Key? key}) : super(key: key); 33 | 34 | @override 35 | _MyHomePageState createState() => _MyHomePageState(); 36 | } 37 | 38 | class _MyHomePageState extends State { 39 | @override 40 | Widget build(BuildContext context) { 41 | return Scaffold( 42 | body: DefaultTabController( 43 | length: 4, 44 | child: Scaffold( 45 | body: SingleChildScrollView( 46 | child: SizedBox( 47 | height: MediaQuery.of(context).size.height - 50, 48 | child: Column( 49 | children: [ 50 | Expanded( 51 | child: TabBarView( 52 | children: [ 53 | FormShowcaseTile( 54 | title: 'Json Schema Form', 55 | child: AFWidget( 56 | formBuilder: () => 57 | JsonSchemaForm.fromJson(jsonSchema), 58 | submitButton: (Function() submit) { 59 | return Padding( 60 | padding: const EdgeInsets.only(top: 32), 61 | child: ElevatedButton( 62 | child: const Text('Submit'), 63 | onPressed: () => submit(), 64 | ), 65 | ); 66 | }, 67 | onSubmitted: (JsonSchemaForm form) { 68 | print(form.toMap()); 69 | }, 70 | ), 71 | ), 72 | SingleChildScrollView( 73 | child: FormShowcaseTile( 74 | title: 'Login form', 75 | child: AFWidget( 76 | handleErrorOnSubmit: print, 77 | formBuilder: () => LoginForm(), 78 | submitButton: (Function() submit) { 79 | return Padding( 80 | padding: const EdgeInsets.only(top: 32), 81 | child: ElevatedButton( 82 | child: const Text('Submit'), 83 | onPressed: () => submit(), 84 | ), 85 | ); 86 | }, 87 | onSubmitted: (LoginForm form) async { 88 | await Future.delayed( 89 | const Duration(seconds: 2)); 90 | print(form.toMap()); 91 | }, 92 | ), 93 | ), 94 | ), 95 | FormShowcaseTile( 96 | title: 'Registration form', 97 | child: AFWidget( 98 | formBuilder: () => RegistrationForm(), 99 | submitButton: (Function() submit) { 100 | return Padding( 101 | padding: const EdgeInsets.only(top: 32), 102 | child: ElevatedButton( 103 | child: const Text('Submit'), 104 | onPressed: () { 105 | submit(); 106 | }, 107 | ), 108 | ); 109 | }, 110 | onSubmitted: (RegistrationForm form) { 111 | print(form.toMap()); 112 | }, 113 | ), 114 | ), 115 | SingleChildScrollView( 116 | child: FormShowcaseTile( 117 | title: 'Order form', 118 | child: AFWidget( 119 | formBuilder: () => OrderForm(), 120 | submitButton: (Function() submit) { 121 | return Padding( 122 | padding: const EdgeInsets.only(top: 32), 123 | child: ElevatedButton( 124 | child: const Text('Submit'), 125 | onPressed: () => submit(), 126 | ), 127 | ); 128 | }, 129 | onSubmitted: (OrderForm form) { 130 | print(form.toMap()); 131 | }, 132 | ), 133 | ), 134 | ), 135 | ], 136 | ), 137 | ), 138 | const Padding( 139 | padding: EdgeInsets.all(16), 140 | child: TabPageSelector(), 141 | ) 142 | ], 143 | ), 144 | ), 145 | ), 146 | ), 147 | ), 148 | ); 149 | } 150 | } 151 | 152 | class FormShowcaseTile extends StatelessWidget { 153 | const FormShowcaseTile({Key? key, required this.child, required this.title}) 154 | : super(key: key); 155 | 156 | final String title; 157 | 158 | final Widget child; 159 | 160 | @override 161 | Widget build(BuildContext context) { 162 | return SingleChildScrollView( 163 | child: Center( 164 | child: Container( 165 | margin: const EdgeInsets.symmetric(vertical: 64, horizontal: 24), 166 | padding: const EdgeInsets.all(24), 167 | decoration: BoxDecoration( 168 | borderRadius: BorderRadius.circular(16), 169 | boxShadow: const [ 170 | BoxShadow( 171 | blurRadius: 16, 172 | color: Colors.black12, 173 | offset: Offset(0, 10), 174 | ), 175 | ], 176 | color: Colors.white), 177 | child: Column( 178 | mainAxisSize: MainAxisSize.min, 179 | children: [ 180 | Padding( 181 | padding: const EdgeInsets.only(bottom: 16), 182 | child: Text( 183 | title, 184 | textAlign: TextAlign.center, 185 | style: const TextStyle( 186 | fontSize: 18, 187 | fontWeight: FontWeight.bold, 188 | color: Colors.blueAccent, 189 | ), 190 | ), 191 | ), 192 | child, 193 | ], 194 | ), 195 | ), 196 | ), 197 | ); 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner 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 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.example.example") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | 90 | # Generated plugin build rules, which manage building the plugins and adding 91 | # them to the application. 92 | include(flutter/generated_plugins.cmake) 93 | 94 | 95 | # === Installation === 96 | # By default, "installing" just makes a relocatable bundle in the build 97 | # directory. 98 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 99 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 100 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 101 | endif() 102 | 103 | # Start with a clean build bundle directory every time. 104 | install(CODE " 105 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 106 | " COMPONENT Runtime) 107 | 108 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 109 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 110 | 111 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 112 | COMPONENT Runtime) 113 | 114 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 115 | COMPONENT Runtime) 116 | 117 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 118 | COMPONENT Runtime) 119 | 120 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 121 | install(FILES "${bundled_library}" 122 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 123 | COMPONENT Runtime) 124 | endforeach(bundled_library) 125 | 126 | # Copy the native assets provided by the build.dart from all packages. 127 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") 128 | install(DIRECTORY "${NATIVE_ASSETS_DIR}" 129 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 130 | COMPONENT Runtime) 131 | 132 | # Fully re-copy the assets directory on each build to avoid having stale files 133 | # from a previous install. 134 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 135 | install(CODE " 136 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 137 | " COMPONENT Runtime) 138 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 139 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 140 | 141 | # Install the AOT library on non-Debug builds only. 142 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 143 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 144 | COMPONENT Runtime) 145 | endif() 146 | -------------------------------------------------------------------------------- /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.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GApplication::startup. 85 | static void my_application_startup(GApplication* application) { 86 | //MyApplication* self = MY_APPLICATION(object); 87 | 88 | // Perform any actions required at application startup. 89 | 90 | G_APPLICATION_CLASS(my_application_parent_class)->startup(application); 91 | } 92 | 93 | // Implements GApplication::shutdown. 94 | static void my_application_shutdown(GApplication* application) { 95 | //MyApplication* self = MY_APPLICATION(object); 96 | 97 | // Perform any actions required at application shutdown. 98 | 99 | G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application); 100 | } 101 | 102 | // Implements GObject::dispose. 103 | static void my_application_dispose(GObject* object) { 104 | MyApplication* self = MY_APPLICATION(object); 105 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 106 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 107 | } 108 | 109 | static void my_application_class_init(MyApplicationClass* klass) { 110 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 111 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 112 | G_APPLICATION_CLASS(klass)->startup = my_application_startup; 113 | G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown; 114 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 115 | } 116 | 117 | static void my_application_init(MyApplication* self) {} 118 | 119 | MyApplication* my_application_new() { 120 | return MY_APPLICATION(g_object_new(my_application_get_type(), 121 | "application-id", APPLICATION_ID, 122 | "flags", G_APPLICATION_NON_UNIQUE, 123 | nullptr)); 124 | } 125 | -------------------------------------------------------------------------------- /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 | @NSApplicationMain 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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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 FlutterMacOS 2 | import Cocoa 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: auto_form_example 2 | description: An example project demonstrating how to use the auto form package 3 | 4 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 5 | 6 | version: 1.0.0+1 7 | 8 | environment: 9 | sdk: ">=2.12.0 <3.0.0" 10 | 11 | dependencies: 12 | flutter: 13 | sdk: flutter 14 | 15 | flutter_auto_form: 16 | path: ../ 17 | 18 | dev_dependencies: 19 | flutter_test: 20 | sdk: flutter 21 | 22 | flutter: 23 | uses-material-design: true 24 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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 | example 30 | 31 | 32 | 33 | 36 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /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/GaspardMerten/flutter_auto_form/e5b98734e737733a9150671b7dc4aa55cfd3e904/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 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /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 | 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/flutter_auto_form.dart: -------------------------------------------------------------------------------- 1 | library auto_form; 2 | 3 | export 'src/configuration/defaults.dart'; 4 | export 'src/configuration/typedef.dart'; 5 | export 'src/json_schema/form.dart'; 6 | export 'src/models/field/field.dart'; 7 | export 'src/models/field/field_context.dart'; 8 | export 'src/models/form.dart'; 9 | export 'src/models/validators/defaults.dart'; 10 | export 'src/models/validators/validator.dart'; 11 | export 'src/widgets/fields/boolean_field.dart'; 12 | export 'src/widgets/fields/date_field.dart'; 13 | export 'src/widgets/fields/interface.dart'; 14 | export 'src/widgets/fields/multiple_sub_form_field.dart'; 15 | export 'src/widgets/fields/search_field.dart'; 16 | export 'src/widgets/fields/sub_form_field.dart'; 17 | export 'src/widgets/fields/text_field.dart'; 18 | export 'src/widgets/form.dart'; 19 | export 'src/widgets/form_state.dart'; 20 | export 'src/widgets/theme.dart'; 21 | -------------------------------------------------------------------------------- /lib/src/configuration/defaults.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/widgets/utils/loading_widget.dart'; 5 | 6 | /// The default loading dialog builder used by the [AFTheme] widget. 7 | /// See [FutureLoadingWidget] if you want to create your own loading dialog 8 | /// compatible with the requirement of the [AFTheme]. 9 | Future kShowFutureLoadingDialog({ 10 | required BuildContext context, 11 | required FutureOr future, 12 | }) async { 13 | final T response = await showDialog( 14 | context: context, 15 | barrierDismissible: true, 16 | builder: (BuildContext context) => DefaultLoadingWidget( 17 | popOnComplete: true, 18 | future: future, 19 | ), 20 | ); 21 | 22 | return response; 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/configuration/typedef.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 5 | 6 | /// The interface for the [Field.widgetBuilder] method which builds 7 | /// a widget from information available in the [FieldContext] instance it receives. 8 | /// 9 | /// Any widget that is supposed to represent a [Field] should interface with 10 | /// this typedef. 11 | typedef FieldWidgetConstructor = Widget Function({ 12 | Key? key, 13 | required FieldContext fieldContext, 14 | }); 15 | 16 | /// An interface for the future loader. See [kShowFutureLoadingWidget] for 17 | /// an example of a working implementation. 18 | typedef FutureWrapper = FutureOr Function({ 19 | required BuildContext context, 20 | required FutureOr future, 21 | }); 22 | -------------------------------------------------------------------------------- /lib/src/json_schema/form.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_auto_form/src/json_schema/json_schema.dart'; 3 | import 'package:flutter_auto_form/src/models/field/field.dart'; 4 | import 'package:flutter_auto_form/src/models/form.dart'; 5 | import 'package:flutter_auto_form/src/models/validators/validator.dart'; 6 | 7 | class JsonSchemaForm extends TemplateForm { 8 | JsonSchemaForm(this.fields); 9 | 10 | factory JsonSchemaForm.fromJson(Map json) { 11 | final JsonSchema schema = JsonSchema.fromJson(json); 12 | 13 | final List> fields = []; 14 | 15 | for (final JsonSchemaProperty element in schema.properties) { 16 | if (element.enumValues.isNotEmpty) { 17 | fields.add(AFSelectField( 18 | id: element.id, 19 | name: element.name, 20 | validators: 21 | buildValidators(element, schema.isRequired(element)), 22 | values: element.enumValues, 23 | textBuilder: (e) => e.toString(), 24 | value: element.defaultValue ?? element.enumValues.first, 25 | )); 26 | } else { 27 | switch (element.type) { 28 | case JsonSchemaType.string: 29 | fields.add(AFTextField( 30 | id: element.id, 31 | name: element.name, 32 | validators: 33 | buildValidators(element, schema.isRequired(element)), 34 | value: element.defaultValue, 35 | type: AFTextFieldType.text, 36 | )); 37 | break; 38 | case JsonSchemaType.number: 39 | final validators = buildValidators( 40 | element, 41 | schema.isRequired(element), 42 | ); 43 | 44 | final minimum = element.getOption('min'); 45 | if (minimum != null) { 46 | validators.add(MinValueValidator( 47 | 'The value should be greater or equal to $minimum', 48 | minimum, 49 | )); 50 | } 51 | 52 | final maximum = element.getOption('max'); 53 | 54 | if (maximum != null) { 55 | validators.add(MaxValueValidator( 56 | 'The value should be smaller or equal to $maximum', 57 | minimum, 58 | )); 59 | } 60 | 61 | fields.add(AFNumberField( 62 | id: element.id, 63 | name: element.name, 64 | value: element.defaultValue as num?, 65 | validators: validators, 66 | )); 67 | break; 68 | case JsonSchemaType.integer: 69 | final validators = buildValidators( 70 | element, 71 | schema.isRequired(element), 72 | ); 73 | 74 | final minimum = element.getOption('min'); 75 | if (minimum != null) { 76 | validators.add(MinValueValidator( 77 | 'The value should be greater or equal to $minimum', 78 | minimum, 79 | )); 80 | } 81 | 82 | final maximum = element.getOption('max'); 83 | 84 | if (maximum != null) { 85 | validators.add(MaxValueValidator( 86 | 'The value should be smaller or equal to $maximum', 87 | maximum, 88 | )); 89 | } 90 | 91 | fields.add( 92 | AFNumberField( 93 | id: element.id, 94 | name: element.name, 95 | value: element.defaultValue as int?, 96 | validators: [ 97 | ...validators, 98 | IsIntegerValidator('Please enter a valid integer') 99 | ], 100 | ), 101 | ); 102 | break; 103 | case JsonSchemaType.boolean: 104 | fields.add(AFBooleanField( 105 | id: element.id, 106 | name: element.name, 107 | value: element.defaultValue as bool? ?? false, 108 | validators: 109 | buildValidators(element, schema.isRequired(element)), 110 | )); 111 | break; 112 | default: 113 | debugPrint( 114 | '[Flutter Auto Form]: ${element.type} is not yet implemented.'); 115 | } 116 | } 117 | } 118 | 119 | return JsonSchemaForm(fields); 120 | } 121 | 122 | @override 123 | final List> fields; 124 | } 125 | 126 | List> buildValidators( 127 | JsonSchemaProperty element, bool required) { 128 | final List> validators = []; 129 | 130 | if (required) { 131 | validators.add(const NotNullValidator('This field cannot be null')); 132 | } 133 | 134 | return validators; 135 | } 136 | -------------------------------------------------------------------------------- /lib/src/json_schema/json_schema.dart: -------------------------------------------------------------------------------- 1 | abstract class JsonSchemaObject { 2 | List get properties; 3 | } 4 | 5 | const Map _typeToPropertyConstructor = { 6 | JsonSchemaType.object: JsonSchemaProperty.fromJson, 7 | JsonSchemaType.integer: JsonSchemaProperty.fromJson, 8 | JsonSchemaType.number: JsonSchemaProperty.fromJson, 9 | JsonSchemaType.array: JsonSchemaProperty.fromJson, 10 | JsonSchemaType.boolean: JsonSchemaProperty.fromJson, 11 | JsonSchemaType.string: JsonSchemaProperty.fromJson, 12 | JsonSchemaType.undefined: JsonSchemaProperty.fromJson, 13 | }; 14 | 15 | class JsonSchema extends JsonSchemaObject { 16 | JsonSchema({ 17 | required this.schema, 18 | required this.id, 19 | required this.title, 20 | required this.description, 21 | required this.properties, 22 | required this.required, 23 | }); 24 | 25 | factory JsonSchema.fromJson(Map json) { 26 | final List properties = []; 27 | 28 | json['properties']?.forEach((id, json) { 29 | properties.add( 30 | _typeToPropertyConstructor[_parseType(json['type'])]!(id, json), 31 | ); 32 | }); 33 | 34 | return JsonSchema( 35 | schema: json['\$schema'], 36 | id: json['\$id'], 37 | title: json['title'], 38 | description: json['description'], 39 | properties: properties, 40 | required: json['required'].map((e) => e.toString()).toList(), 41 | ); 42 | } 43 | 44 | final String schema; 45 | final String id; 46 | final String title; 47 | final String description; 48 | 49 | @override 50 | final List properties; 51 | 52 | final List required; 53 | 54 | bool isRequired(JsonSchemaProperty element) { 55 | return required.contains(element.id); 56 | } 57 | } 58 | 59 | final RegExp exp = RegExp(r'(?<=[a-z])[A-Z]'); 60 | 61 | class JsonSchemaProperty extends JsonSchemaObject { 62 | JsonSchemaProperty({ 63 | required this.id, 64 | required this.description, 65 | required this.type, 66 | this.defaultValue, 67 | this.options = const [], 68 | this.properties = const [], 69 | this.enumValues = const [], 70 | this.examples = const [], 71 | }); 72 | 73 | factory JsonSchemaProperty.fromJson(String id, Map json) { 74 | final String type = json['type']; 75 | final String? description = json['description']; 76 | 77 | final List options = []; 78 | 79 | final List properties = []; 80 | 81 | final List enumValues = []; 82 | 83 | if ((json['enum'] ?? []).isNotEmpty) { 84 | json['enum'].forEach(enumValues.add); 85 | } 86 | 87 | final List examples = []; 88 | 89 | if ((json['examples'] ?? []).isNotEmpty) { 90 | json['examples'].forEach(examples.add); 91 | } 92 | 93 | json['properties']?.forEach((id, json) { 94 | if (id != 'type' && id != 'description') { 95 | properties.add(JsonSchemaProperty.fromJson(id, json)); 96 | } 97 | }); 98 | 99 | json.forEach((key, value) { 100 | options.add(PropertyOption(key, value)); 101 | }); 102 | 103 | return JsonSchemaProperty( 104 | id: id, 105 | description: description, 106 | type: _parseType(type), 107 | options: options, 108 | defaultValue: json['default'], 109 | properties: properties, 110 | enumValues: enumValues, 111 | examples: examples, 112 | ); 113 | } 114 | 115 | final String id; 116 | final String? description; 117 | final JsonSchemaType type; 118 | final T? defaultValue; 119 | final List examples; 120 | final List enumValues; 121 | final List options; 122 | @override 123 | final List properties; 124 | 125 | String get name { 126 | return id.replaceAllMapped(exp, (Match m) => ' ${m.group(0) ?? ''}'); 127 | } 128 | 129 | dynamic getOption(String name) { 130 | final results = options.where( 131 | (element) => element.name == name, 132 | ); 133 | 134 | if (results.isNotEmpty) { 135 | return results.first.value; 136 | } 137 | } 138 | } 139 | 140 | class PropertyOption { 141 | PropertyOption(this.name, this.value); 142 | 143 | final String name; 144 | final dynamic value; 145 | } 146 | 147 | JsonSchemaType _parseType(String type) { 148 | switch (type) { 149 | case 'string': 150 | return JsonSchemaType.string; 151 | case 'number': 152 | return JsonSchemaType.number; 153 | case 'integer': 154 | return JsonSchemaType.integer; 155 | case 'object': 156 | return JsonSchemaType.object; 157 | case 'array': 158 | return JsonSchemaType.array; 159 | case 'boolean': 160 | return JsonSchemaType.boolean; 161 | default: 162 | return JsonSchemaType.undefined; 163 | } 164 | } 165 | 166 | enum JsonSchemaType { 167 | string, 168 | integer, 169 | number, 170 | object, 171 | array, 172 | boolean, 173 | undefined 174 | } 175 | -------------------------------------------------------------------------------- /lib/src/models/error.dart: -------------------------------------------------------------------------------- 1 | class SubmitException implements Exception { 2 | SubmitException(this.errorMessage); 3 | 4 | final String errorMessage; 5 | } 6 | -------------------------------------------------------------------------------- /lib/src/models/field/field.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/configuration/typedef.dart'; 5 | import 'package:flutter_auto_form/src/models/validators/validator.dart'; 6 | 7 | export 'defaults.dart'; 8 | 9 | typedef FieldValueParser = T Function(String value); 10 | 11 | /// This class is the base class for any type of custom fields you would 12 | /// want to create. See the [AFTextField] widget to learn more on how 13 | /// to extend it. 14 | abstract class Field { 15 | Field({ 16 | required this.id, 17 | required this.name, 18 | required this.validators, 19 | this.onChanged, 20 | }); 21 | 22 | final StreamController _streamController = 23 | StreamController.broadcast(); 24 | 25 | /// The stream that will be used to notify the form that the field's value 26 | /// has changed. 27 | Stream get updateStream => _streamController.stream; 28 | 29 | final ValueChanged? onChanged; 30 | 31 | /// A unique identifier for the field which will be used to retrieve its data. 32 | final String id; 33 | 34 | /// The name that will be displayed to the user. 35 | final String name; 36 | 37 | /// A list of validators that will be used to verify the user's input. 38 | final List validators; 39 | 40 | /// The current value of the field. 41 | T? _value; 42 | 43 | /// The current value of the field. 44 | T? get value => _value; 45 | 46 | /// The current value of the field. 47 | set value(covariant Object? value) { 48 | _value = parser(value); 49 | onChanged?.call(_value); 50 | } 51 | 52 | /// Sets the value of the field and notifies the form's widgets that the value has 53 | /// changed. 54 | void updateValue(covariant Object? value) { 55 | _value = parser(value); 56 | _streamController.add(_value); 57 | } 58 | 59 | /// This method returns null if the field is valid. Otherwise it will 60 | /// return the error's string specified in the validator (see [Validator]). 61 | String? validator([Object? object]) { 62 | for (final Validator validator in validators) { 63 | final String? error = validator.validate(value); 64 | 65 | if (error != null) return error; 66 | } 67 | 68 | return null; 69 | } 70 | 71 | /// Parses a value into an instance of T. 72 | T? parser(covariant Object? unparsedValue); 73 | 74 | FieldWidgetConstructor get widgetBuilder; 75 | } 76 | -------------------------------------------------------------------------------- /lib/src/models/field/field_context.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter_auto_form/src/models/field/field.dart'; 4 | 5 | class FieldContext { 6 | FieldContext({ 7 | required this.field, 8 | required this.forceErrorDisplay, 9 | required this.completeAction, 10 | this.previous, 11 | }); 12 | 13 | final Field field; 14 | 15 | final Function()? completeAction; 16 | 17 | final FieldContext? previous; 18 | 19 | late final FieldContext? next; 20 | 21 | bool forceErrorDisplay; 22 | 23 | final StreamController _focusStreamController = StreamController(); 24 | 25 | Stream get focusStream => _focusStreamController.stream; 26 | 27 | bool get isLast => next == null; 28 | 29 | String? get errorText => 30 | forceErrorDisplay ? field.validator(field.value) : null; 31 | 32 | void sendRequestFocusEvent() { 33 | _focusStreamController.add(null); 34 | } 35 | 36 | void onChanged(value) { 37 | field.value = value; 38 | } 39 | 40 | void updateWith({bool? forceErrorDisplay}) { 41 | this.forceErrorDisplay = forceErrorDisplay ?? this.forceErrorDisplay; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/src/models/field/utils.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_auto_form/src/models/field/defaults.dart'; 3 | 4 | /// Returns the [AutofillHints] matching the [AFTextField.type]. 5 | List getAutoFillHintsFromFieldType(AFTextField field) { 6 | String? autoFillHint; 7 | 8 | switch (field.type) { 9 | case AFTextFieldType.password: 10 | autoFillHint = AutofillHints.password; 11 | break; 12 | case AFTextFieldType.email: 13 | autoFillHint = AutofillHints.email; 14 | break; 15 | case AFTextFieldType.username: 16 | autoFillHint = AutofillHints.username; 17 | break; 18 | case AFTextFieldType.newPassword: 19 | autoFillHint = AutofillHints.newPassword; 20 | break; 21 | case AFTextFieldType.newUsername: 22 | autoFillHint = AutofillHints.newUsername; 23 | break; 24 | default: 25 | break; 26 | } 27 | 28 | return [if (autoFillHint != null) autoFillHint]; 29 | } 30 | 31 | /// Returns the [TextInputType] matching the [AFTextField.type]. 32 | TextInputType? getTextInputType(AFTextField field) { 33 | TextInputType? inputType; 34 | 35 | switch (field.type) { 36 | case AFTextFieldType.email: 37 | inputType = TextInputType.emailAddress; 38 | break; 39 | case AFTextFieldType.username: 40 | inputType = TextInputType.name; 41 | break; 42 | case AFTextFieldType.newPassword: 43 | inputType = TextInputType.visiblePassword; 44 | break; 45 | case AFTextFieldType.password: 46 | inputType = TextInputType.visiblePassword; 47 | break; 48 | case AFTextFieldType.newUsername: 49 | inputType = TextInputType.name; 50 | break; 51 | case AFTextFieldType.number: 52 | inputType = TextInputType.number; 53 | break; 54 | default: 55 | break; 56 | } 57 | 58 | return inputType; 59 | } 60 | -------------------------------------------------------------------------------- /lib/src/models/form.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_auto_form/src/models/field/field.dart'; 2 | 3 | /// An abstract class that makes it easy to create form with a strong validation 4 | /// system. 5 | /// 6 | /// Use the toMap() method to retrieve all the fields values. 7 | /// 8 | /// See [Field] and [Validator] for more information. 9 | abstract class TemplateForm { 10 | List get fields; 11 | 12 | bool isComplete() { 13 | // It is important to not directly return false in the for boucle because 14 | // in the case a subform is present in the fields, it needs this call 15 | // to display error. 16 | bool isComplete = true; 17 | 18 | for (final Field field in fields) { 19 | if (field.validator(field.value) != null) { 20 | isComplete = false; 21 | } 22 | } 23 | 24 | return isComplete; 25 | } 26 | 27 | String? getFirstError() { 28 | for (final Field field in fields) { 29 | final String? error = field.validator(field.value); 30 | if (error != null) { 31 | return error; 32 | } 33 | } 34 | 35 | return null; 36 | } 37 | 38 | T? get(String id) { 39 | return fields.singleWhere((e) => e.id == id).value as T?; 40 | } 41 | 42 | dynamic set(String id, dynamic value) { 43 | return fields.singleWhere((e) => e.id == id).updateValue(value); 44 | } 45 | 46 | Map toMap() { 47 | return {for (var e in fields) e.id: e.value}; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/src/models/validators/defaults.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 2 | import 'package:flutter_auto_form/src/models/validators/regex.dart'; 3 | 4 | class FuncValidator extends ValidatorWithStaticError { 5 | FuncValidator({required String error, required this.isValid}) : super(error); 6 | 7 | final bool Function(T? value) isValid; 8 | 9 | @override 10 | bool innerValidate(T? value) { 11 | return isValid(value); 12 | } 13 | } 14 | 15 | /// Checks whether a given url string is valid. Null is deemed as an acceptable 16 | /// url. 17 | class URLValidator extends ValidatorWithStaticError { 18 | const URLValidator(String error) : super(error); 19 | 20 | @override 21 | bool innerValidate(String? value) { 22 | return value == null || RegExp(urlRegex).hasMatch(value); 23 | } 24 | } 25 | 26 | /// An enum used by the [HexColorValidator] to specify which format of hex color 27 | /// is accepted. 28 | /// 29 | /// Both: #ff2f2f and ff2f2f are accepted 30 | /// withHashtag: only #ff2f2f is accepted 31 | /// withoutHashtag: only ff2f2f is accepted 32 | enum HexColorValidatorMode { both, withHashtag, withoutHashtag } 33 | 34 | /// Checks whether a given hex color string is valid. Null is deemed as an acceptable 35 | /// url. 36 | 37 | class HexColorValidator extends ValidatorWithStaticError { 38 | const HexColorValidator( 39 | String error, { 40 | this.mode = HexColorValidatorMode.withHashtag, 41 | }) : super(error); 42 | 43 | final HexColorValidatorMode mode; 44 | 45 | @override 46 | bool innerValidate(String? value) { 47 | final String regex; 48 | 49 | switch (mode) { 50 | case HexColorValidatorMode.both: 51 | regex = hexRegexWithBoth; 52 | break; 53 | case HexColorValidatorMode.withHashtag: 54 | regex = hexRegexWithHashtag; 55 | break; 56 | case HexColorValidatorMode.withoutHashtag: 57 | regex = hexRegexWithoutHashtag; 58 | break; 59 | } 60 | 61 | return value == null || RegExp(regex).hasMatch(value); 62 | } 63 | } 64 | 65 | /// Checks whether a given value isn't null. 66 | class NotNullValidator extends ValidatorWithStaticError { 67 | const NotNullValidator(String error) : super(error); 68 | 69 | @override 70 | bool innerValidate(T? value) => value != null; 71 | } 72 | 73 | /// Checks whether a given value is an integer. 74 | class IsIntegerValidator extends ValidatorWithStaticError { 75 | IsIntegerValidator(String error) : super(error); 76 | 77 | @override 78 | bool innerValidate(T? value) => value?.toInt() == value; 79 | } 80 | 81 | /// Checks whether a given num is greater (or equal) than a minimum value. 82 | class MinValueValidator extends ValidatorWithStaticError { 83 | MinValueValidator(String error, this.minimum) : super(error); 84 | 85 | final num minimum; 86 | 87 | @override 88 | bool innerValidate(T? value) => value == null || value >= minimum; 89 | } 90 | 91 | /// Checks whether a given num is smaller (or equal) than a maximum value. 92 | class MaxValueValidator extends ValidatorWithStaticError { 93 | MaxValueValidator(String error, this.maximum) : super(error); 94 | 95 | final num maximum; 96 | 97 | @override 98 | bool innerValidate(T? value) => value == null || value <= maximum; 99 | } 100 | 101 | /// Checks whether a given string isn't empty. 102 | class NotEmptyStringValidator extends ValidatorWithStaticError { 103 | NotEmptyStringValidator(String error) : super(error); 104 | 105 | @override 106 | bool innerValidate(String? value) => value != null && value.isNotEmpty; 107 | } 108 | 109 | /// Checks whether a given value isn't empty. 110 | class NotEmptyListValidator extends ValidatorWithStaticError> { 111 | NotEmptyListValidator(String error) : super(error); 112 | 113 | @override 114 | bool innerValidate(List? value) => value != null && value.isNotEmpty; 115 | } 116 | 117 | /// Checks whether a given string possess a minimum length. 118 | class MinimumStringLengthValidator extends Validator { 119 | const MinimumStringLengthValidator(this.minStringLength, this.error); 120 | 121 | final String Function(String? value) error; 122 | 123 | final int minStringLength; 124 | 125 | @override 126 | String? validate(String? value) { 127 | if (value == null || value.length < minStringLength) return error(value); 128 | 129 | return null; 130 | } 131 | } 132 | 133 | /// Checks whether the value of a given field equals the value of another field. 134 | class SameAsFieldValidator extends ValidatorWithStaticError { 135 | const SameAsFieldValidator(this.field, String error) : super(error); 136 | 137 | final Field field; 138 | 139 | @override 140 | bool innerValidate(T? value) { 141 | return value == field.value; 142 | } 143 | } 144 | 145 | /// Checks whether the value of a givGreaterThanFieldValidator of another field. 146 | class GreaterThanFieldValidator 147 | extends ValidatorWithStaticError { 148 | GreaterThanFieldValidator(this.getValue, String error) : super(error); 149 | 150 | final T? Function() getValue; 151 | 152 | @override 153 | bool innerValidate(T? value) { 154 | final otherValue = getValue(); 155 | if (value != null && otherValue != null) { 156 | return value >= otherValue; 157 | } 158 | return false; 159 | } 160 | } 161 | 162 | /// Checks whether a given string only comports alphanumerical characters. 163 | class AlphanumericValidator extends ValidatorWithStaticError { 164 | const AlphanumericValidator(String error) : super(error); 165 | 166 | @override 167 | bool innerValidate(String? value) => 168 | value == null || RegExp(alphaNumericRegex).hasMatch(value); 169 | } 170 | 171 | /// Checks whether an email string is valid. 172 | class EmailValidator extends ValidatorWithStaticError { 173 | const EmailValidator(String error) : super(error); 174 | 175 | @override 176 | bool innerValidate(String? value) { 177 | return value == null || RegExp(emailRegex).hasMatch(value.trim()); 178 | } 179 | } 180 | 181 | /// Checks whether a boolean value is set to true. 182 | class ShouldBeTrueValidator extends ValidatorWithStaticError { 183 | const ShouldBeTrueValidator(String error) : super(error); 184 | 185 | @override 186 | bool innerValidate(bool? value) { 187 | return value ?? false; 188 | } 189 | } 190 | 191 | class FormValidator extends Validator { 192 | const FormValidator(); 193 | 194 | @override 195 | String? validate(TemplateForm value) { 196 | return value.isComplete() ? null : 'ERROR'; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /lib/src/models/validators/regex.dart: -------------------------------------------------------------------------------- 1 | const String urlRegex = r'^(?:(?:https?):\/\/)[\w/\-?=%.]+\.[\w/\-?=%.]+$'; 2 | 3 | const String hexRegexWithBoth = r'^[#]?[a-fA-F0-9]{6}$'; 4 | const String hexRegexWithHashtag = r'^#[a-fA-F0-9]{6}$'; 5 | const String hexRegexWithoutHashtag = r'^[a-fA-F0-9]{6}$'; 6 | 7 | const String alphaNumericRegex = r'^[a-zA-Z0-9]+$'; 8 | 9 | const String numericRegex = r'^[0-9]+$'; 10 | const String emailRegex = 11 | r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$'; 12 | -------------------------------------------------------------------------------- /lib/src/models/validators/validator.dart: -------------------------------------------------------------------------------- 1 | export 'defaults.dart'; 2 | 3 | /// The [Validator] class is used by the [Field] class to validate its input. 4 | abstract class Validator { 5 | const Validator(); 6 | 7 | /// This method should return null if the field is valid, a string corresponding 8 | /// to the error otherwise. 9 | String? validate(T value); 10 | } 11 | 12 | /// As its name suggests, this class makes it easier to create a validator 13 | /// which returns a static error message (that does not change based on the data). 14 | abstract class ValidatorWithStaticError 15 | extends Validator { 16 | const ValidatorWithStaticError(this.error); 17 | 18 | final String error; 19 | 20 | @override 21 | String? validate(T? value) { 22 | if (innerValidate(value)) { 23 | return null; 24 | } else { 25 | return error; 26 | } 27 | } 28 | 29 | /// Returns true or false depending on the validation process. This method 30 | /// is then used by the [ValidatorWithStaticError.validate] method to return 31 | /// a static error if the result is false. 32 | bool innerValidate(T? value); 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/boolean_field.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 3 | 4 | class BooleanFieldWidget extends FieldStatefulWidget { 5 | const BooleanFieldWidget({ 6 | Key? key, 7 | required this.fieldContext, 8 | }) : super(key: key); 9 | 10 | @override 11 | final FieldContext fieldContext; 12 | 13 | @override 14 | State createState() => _BooleanFieldWidgetState(); 15 | } 16 | 17 | /// Displays a switch list tile in the form of a field. 18 | class _BooleanFieldWidgetState extends State { 19 | late final AFBooleanField field = widget.fieldContext.field as AFBooleanField; 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | return Padding( 24 | padding: const EdgeInsets.only(top: 16), 25 | child: InputDecorator( 26 | decoration: InputDecoration( 27 | errorText: widget.fieldContext.forceErrorDisplay 28 | ? field.validator(field.value) 29 | : null, 30 | border: InputBorder.none, 31 | ).applyDefaults( 32 | Theme.of(context).inputDecorationTheme, 33 | ), 34 | child: SwitchListTile( 35 | value: field.value ?? false, 36 | contentPadding: EdgeInsets.zero, 37 | onChanged: (newValue) => setState(() { 38 | widget.fieldContext.onChanged(newValue); 39 | }), 40 | title: Text( 41 | field.name, 42 | style: Theme.of(context).inputDecorationTheme.hintStyle, 43 | ), 44 | ), 45 | ), 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/date_field.dart: -------------------------------------------------------------------------------- 1 | import 'package:date_field/date_field.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_auto_form/src/models/field/defaults.dart'; 4 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 5 | import 'package:flutter_auto_form/src/widgets/fields/interface.dart'; 6 | 7 | class DateFieldWidget extends FieldStatefulWidget { 8 | const DateFieldWidget({ 9 | Key? key, 10 | required this.fieldContext, 11 | required this.mode, 12 | }) : super(key: key); 13 | 14 | @override 15 | final FieldContext fieldContext; 16 | 17 | final DateTimeFieldPickerMode mode; 18 | 19 | @override 20 | State> createState() => _DateFieldWidgetState(); 21 | } 22 | 23 | class _DateFieldWidgetState 24 | extends FieldState> { 25 | late final AFDateField field = widget.fieldContext.field as AFDateField; 26 | 27 | @override 28 | Widget build(BuildContext context) { 29 | return Padding( 30 | padding: const EdgeInsets.only(top: 16), 31 | child: DateTimeFormField( 32 | mode: widget.mode, 33 | decoration: InputDecoration( 34 | labelText: field.name, 35 | suffixIcon: const Icon(Icons.calendar_month)), 36 | onChanged: (date) => setState(() { 37 | widget.fieldContext.onChanged(date); 38 | }), 39 | autovalidateMode: widget.fieldContext.forceErrorDisplay 40 | ? AutovalidateMode.always 41 | : AutovalidateMode.onUserInteraction, 42 | validator: field.validator, 43 | initialPickerDateTime: field.value, 44 | initialValue: field.value, 45 | ), 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/fields.dart: -------------------------------------------------------------------------------- 1 | export 'boolean_field.dart'; 2 | export 'select_field.dart'; 3 | export 'text_field.dart'; 4 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/interface.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 3 | 4 | abstract class FieldStatefulWidget extends StatefulWidget { 5 | const FieldStatefulWidget({Key? key}) : super(key: key); 6 | 7 | FieldContext get fieldContext; 8 | } 9 | 10 | abstract class FieldState extends State { 11 | @override 12 | void initState() { 13 | super.initState(); 14 | 15 | widget.fieldContext.field.updateStream.listen(onChanged); 16 | } 17 | 18 | void onChanged(dynamic value) { 19 | setState(() { 20 | widget.fieldContext.onChanged(value); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/multiple_sub_form_field.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/models/field/defaults.dart'; 5 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 6 | import 'package:flutter_auto_form/src/models/form.dart'; 7 | import 'package:flutter_auto_form/src/widgets/fields/interface.dart'; 8 | import 'package:flutter_auto_form/src/widgets/form.dart'; 9 | 10 | class AFMultipleSubFormFieldWidget 11 | extends FieldStatefulWidget { 12 | const AFMultipleSubFormFieldWidget({ 13 | Key? key, 14 | required this.fieldContext, 15 | }) : super(key: key); 16 | 17 | @override 18 | final FieldContext fieldContext; 19 | 20 | @override 21 | State> createState() => 22 | AFMultipleSubFormFieldWidgetState(); 23 | } 24 | 25 | class AFMultipleSubFormFieldWidgetState 26 | extends FieldState> { 27 | late final AFMultipleSubFormField field = 28 | widget.fieldContext.field as AFMultipleSubFormField; 29 | 30 | final Map> formKeys = {}; 31 | 32 | late final StreamSubscription subscription; 33 | 34 | GlobalKey _getKey(TemplateForm form) { 35 | if (!formKeys.containsKey(form.hashCode)) { 36 | formKeys[form.hashCode] = GlobalKey(); 37 | } 38 | 39 | return formKeys[form.hashCode]!; 40 | } 41 | 42 | @override 43 | void initState() { 44 | super.initState(); 45 | 46 | subscription = field.forceErrorStream.listen((_) { 47 | for (final formKey in formKeys.values) { 48 | formKey.currentState?.updateForceError(true); 49 | } 50 | }); 51 | } 52 | 53 | @override 54 | void dispose() { 55 | super.dispose(); 56 | subscription.cancel(); 57 | } 58 | 59 | @override 60 | Widget build(BuildContext context) { 61 | return Container( 62 | padding: const EdgeInsets.all(16), 63 | margin: const EdgeInsets.only(top: 16), 64 | decoration: BoxDecoration( 65 | borderRadius: BorderRadius.circular(16), 66 | border: Border.all(color: Colors.black12)), 67 | child: Column( 68 | crossAxisAlignment: CrossAxisAlignment.start, 69 | children: [ 70 | Text( 71 | field.name, 72 | ), 73 | for (final form in field.forms) 74 | AFWidget( 75 | key: _getKey(form), 76 | formBuilder: () => form, 77 | onSubmitted: (_) => widget.fieldContext.completeAction, 78 | ), 79 | ], 80 | ), 81 | ); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/search_field.dart: -------------------------------------------------------------------------------- 1 | import 'package:dropdown_search/dropdown_search.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_auto_form/src/models/field/defaults.dart'; 4 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 5 | import 'package:flutter_auto_form/src/widgets/fields/interface.dart'; 6 | 7 | const _kClearButtonsProps = ClearButtonProps(isVisible: false, iconSize: 0); 8 | const _kPopupsMultiSelectionProp = PopupPropsMultiSelection.menu( 9 | showSearchBox: true, 10 | isFilterOnline: true, 11 | ); 12 | const _kDropdownButtonProps = DropdownButtonProps( 13 | isVisible: false, 14 | iconSize: 0, 15 | ); 16 | 17 | class SearchModelFieldWidget extends FieldStatefulWidget { 18 | const SearchModelFieldWidget({ 19 | Key? key, 20 | required this.fieldContext, 21 | }) : super(key: key); 22 | 23 | @override 24 | final FieldContext fieldContext; 25 | 26 | @override 27 | State> createState() => 28 | _SearchModelFieldWidgetState(); 29 | } 30 | 31 | class _SearchModelFieldWidgetState 32 | extends FieldState> { 33 | late final AFSearchModelField field = 34 | widget.fieldContext.field as AFSearchModelField; 35 | 36 | @override 37 | Widget build(BuildContext context) { 38 | final decorationTheme = Theme.of(context).inputDecorationTheme; 39 | 40 | return Padding( 41 | padding: const EdgeInsets.only(top: 16), 42 | child: DropdownSearch( 43 | selectedItem: field.value, 44 | onChanged: onChanged, 45 | asyncItems: field.search, 46 | validator: field.validator, 47 | autoValidateMode: widget.fieldContext.forceErrorDisplay 48 | ? AutovalidateMode.always 49 | : AutovalidateMode.onUserInteraction, 50 | clearButtonProps: _kClearButtonsProps, 51 | dropdownButtonProps: _kDropdownButtonProps, 52 | dropdownBuilder: field.value == null 53 | ? null 54 | : (_, __) { 55 | return SearchModelFieldSelectedItem( 56 | name: field.value.toString()); 57 | }, 58 | popupProps: const PopupProps.menu( 59 | showSearchBox: true, 60 | isFilterOnline: true, 61 | ), 62 | dropdownDecoratorProps: DropDownDecoratorProps( 63 | dropdownSearchDecoration: InputDecoration( 64 | errorText: widget.fieldContext.errorText, 65 | label: Text(widget.fieldContext.field.name), 66 | ).applyDefaults(decorationTheme), 67 | ), 68 | ), 69 | ); 70 | } 71 | } 72 | 73 | class SearchMultipleModelsField extends FieldStatefulWidget { 74 | const SearchMultipleModelsField({ 75 | Key? key, 76 | required this.fieldContext, 77 | }) : super(key: key); 78 | 79 | @override 80 | final FieldContext fieldContext; 81 | 82 | @override 83 | State> createState() => 84 | _SearchMultipleModelsFieldState(); 85 | } 86 | 87 | class _SearchMultipleModelsFieldState 88 | extends FieldState> { 89 | late final AFSearchMultipleModelsField field = 90 | widget.fieldContext.field as AFSearchMultipleModelsField; 91 | 92 | @override 93 | Widget build(BuildContext context) { 94 | final decorationTheme = Theme.of(context).inputDecorationTheme; 95 | 96 | return Padding( 97 | padding: const EdgeInsets.only(top: 16), 98 | child: DropdownSearch.multiSelection( 99 | selectedItems: field.value ?? [], 100 | onChanged: onChanged, 101 | dropdownBuilder: 102 | (field.value?.isEmpty ?? true) ? null : _dropdownBuilder, 103 | asyncItems: field.search, 104 | clearButtonProps: _kClearButtonsProps, 105 | dropdownButtonProps: _kDropdownButtonProps, 106 | popupProps: _kPopupsMultiSelectionProp, 107 | dropdownDecoratorProps: DropDownDecoratorProps( 108 | dropdownSearchDecoration: InputDecoration( 109 | errorText: widget.fieldContext.errorText, 110 | label: Text(widget.fieldContext.field.name), 111 | ).applyDefaults(decorationTheme), 112 | ), 113 | ), 114 | ); 115 | } 116 | 117 | Widget _dropdownBuilder(context, items) => Column( 118 | crossAxisAlignment: CrossAxisAlignment.stretch, 119 | children: [ 120 | for (final item in items) 121 | SearchModelFieldSelectedItem( 122 | name: item.toString(), 123 | ) 124 | ], 125 | ); 126 | } 127 | 128 | class SearchModelFieldSelectedItem extends StatelessWidget { 129 | const SearchModelFieldSelectedItem({Key? key, required this.name}) 130 | : super(key: key); 131 | 132 | final String name; 133 | 134 | @override 135 | Widget build(BuildContext context) { 136 | return Container( 137 | margin: const EdgeInsets.only(top: 4), 138 | padding: const EdgeInsets.all(8), 139 | decoration: BoxDecoration( 140 | borderRadius: BorderRadius.circular(8), 141 | color: Theme.of(context).colorScheme.surface), 142 | child: Text( 143 | name, 144 | style: const TextStyle(fontSize: 12), 145 | ), 146 | ); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/select_field.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 3 | 4 | class SelectFieldWidget extends FieldStatefulWidget { 5 | const SelectFieldWidget({ 6 | Key? key, 7 | required this.fieldContext, 8 | }) : super(key: key); 9 | 10 | @override 11 | State> createState() => _SelectFieldWidgetState(); 12 | 13 | @override 14 | final FieldContext fieldContext; 15 | } 16 | 17 | class _SelectFieldWidgetState 18 | extends State> { 19 | late final AFSelectField field = 20 | widget.fieldContext.field as AFSelectField; 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return Padding( 25 | padding: const EdgeInsets.only(top: 16), 26 | child: DropdownButtonFormField( 27 | validator: field.validator, 28 | autovalidateMode: widget.fieldContext.forceErrorDisplay 29 | ? AutovalidateMode.always 30 | : AutovalidateMode.onUserInteraction, 31 | value: field.value, 32 | onChanged: (e) { 33 | setState(() { 34 | widget.fieldContext.onChanged(e); 35 | }); 36 | }, 37 | items: [ 38 | for (final value in field.values) 39 | DropdownMenuItem( 40 | value: value, 41 | child: Text(field.textBuilder(value)), 42 | ) 43 | ], 44 | ), 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/sub_form_field.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/models/field/defaults.dart'; 5 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 6 | import 'package:flutter_auto_form/src/models/form.dart'; 7 | import 'package:flutter_auto_form/src/widgets/fields/interface.dart'; 8 | import 'package:flutter_auto_form/src/widgets/form.dart'; 9 | 10 | class AFSubFormFieldWidget extends FieldStatefulWidget { 11 | const AFSubFormFieldWidget({ 12 | Key? key, 13 | required this.fieldContext, 14 | }) : super(key: key); 15 | 16 | @override 17 | final FieldContext fieldContext; 18 | 19 | @override 20 | State> createState() => 21 | AFSubFormFieldWidgetState(); 22 | } 23 | 24 | class AFSubFormFieldWidgetState 25 | extends FieldState> { 26 | late final AFSubFormField field = 27 | widget.fieldContext.field as AFSubFormField; 28 | 29 | final formKey = GlobalKey(); 30 | 31 | late final StreamSubscription subscription; 32 | 33 | @override 34 | void initState() { 35 | super.initState(); 36 | 37 | subscription = field.forceErrorStream.listen((event) { 38 | formKey.currentState?.updateForceError(true); 39 | }); 40 | } 41 | 42 | @override 43 | void dispose() { 44 | super.dispose(); 45 | subscription.cancel(); 46 | } 47 | 48 | @override 49 | Widget build(BuildContext context) { 50 | return Container( 51 | decoration: BoxDecoration( 52 | border: Border.all(color: Colors.black12), 53 | borderRadius: BorderRadius.circular(16)), 54 | margin: const EdgeInsets.only(top: 16), 55 | padding: const EdgeInsets.all(16), 56 | child: Column( 57 | crossAxisAlignment: CrossAxisAlignment.start, 58 | children: [ 59 | Text( 60 | field.name, 61 | ), 62 | AFWidget( 63 | key: formKey, 64 | formBuilder: () => field.form, 65 | onSubmitted: (_) => widget.fieldContext.completeAction, 66 | ), 67 | ], 68 | ), 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/src/widgets/fields/text_field.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/models/field/field.dart'; 5 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 6 | import 'package:flutter_auto_form/src/models/field/utils.dart'; 7 | import 'package:flutter_auto_form/src/widgets/fields/interface.dart'; 8 | import 'package:smarter_text_field/smarter_text_field.dart'; 9 | 10 | abstract class AFTextFieldWidgetStateFocusHelper 11 | extends State { 12 | final FocusNode focusNode = FocusNode(); 13 | 14 | late final StreamSubscription _subscription; 15 | 16 | @override 17 | void initState() { 18 | super.initState(); 19 | 20 | _subscription = widget.fieldContext.focusStream.listen((event) { 21 | FocusScope.of(context).requestFocus(focusNode); 22 | }); 23 | } 24 | 25 | @override 26 | void dispose() { 27 | super.dispose(); 28 | 29 | _subscription.cancel(); 30 | } 31 | } 32 | 33 | class AFTextFieldWidget extends FieldStatefulWidget { 34 | const AFTextFieldWidget({ 35 | Key? key, 36 | required this.fieldContext, 37 | }) : super(key: key); 38 | 39 | @override 40 | final FieldContext fieldContext; 41 | 42 | @override 43 | State createState() => _AFTextFieldWidgetState(); 44 | } 45 | 46 | class _AFTextFieldWidgetState 47 | extends AFTextFieldWidgetStateFocusHelper { 48 | late final AFTextField field = widget.fieldContext.field as AFTextField; 49 | 50 | late final TextEditingController controller = TextEditingController( 51 | text: field.value?.toString(), 52 | ); 53 | 54 | @override 55 | void initState() { 56 | super.initState(); 57 | 58 | field.updateStream.listen((event) { 59 | setState(() { 60 | controller.text = event == null ? '' : event.toString(); 61 | }); 62 | }); 63 | 64 | controller 65 | .addListener(() => widget.fieldContext.onChanged(controller.text)); 66 | } 67 | 68 | @override 69 | Widget build(BuildContext context) { 70 | final InputDecoration decoration = InputDecoration( 71 | labelText: field.name, 72 | ).applyDefaults(Theme.of(context).inputDecorationTheme); 73 | 74 | final bool obscureText = field.type == AFTextFieldType.password || 75 | field.type == AFTextFieldType.newPassword; 76 | 77 | final TextInputAction keyboardAction; 78 | 79 | if (widget.fieldContext.isLast) { 80 | keyboardAction = TextInputAction.done; 81 | } else { 82 | keyboardAction = TextInputAction.next; 83 | } 84 | 85 | return Padding( 86 | padding: const EdgeInsets.only(top: 16), 87 | child: SmartTextFormField( 88 | decoration: decoration, 89 | maxLines: field.maxLines, 90 | validator: field.validator, 91 | controller: controller, 92 | autoFillHints: getAutoFillHintsFromFieldType(field), 93 | focusNode: focusNode, 94 | obscureText: obscureText, 95 | keyboardType: getTextInputType(field), 96 | action: keyboardAction, 97 | forceError: widget.fieldContext.forceErrorDisplay, 98 | completeAction: widget.fieldContext.next?.sendRequestFocusEvent ?? 99 | widget.fieldContext.completeAction, 100 | displayObscureTextToggle: obscureText, 101 | ), 102 | ); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /lib/src/widgets/form.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/models/form.dart'; 5 | import 'package:flutter_auto_form/src/widgets/form_state.dart'; 6 | 7 | class AFWidget extends AFFormStatefulWidget { 8 | const AFWidget({ 9 | super.key, 10 | required super.formBuilder, 11 | required super.onSubmitted, 12 | super.submitButton, 13 | super.handleErrorOnSubmit, 14 | super.enableFinalAction = true, 15 | super.enableSubmitFormWrapper, 16 | }); 17 | 18 | @override 19 | AFWidgetState createState() => AFWidgetState(); 20 | } 21 | 22 | class AFWidgetState 23 | extends AFFormState, T> { 24 | @override 25 | Widget build(BuildContext context) { 26 | Widget child = form(); 27 | 28 | if (widget.submitButton != null) { 29 | child = Column( 30 | children: [ 31 | child, 32 | Padding( 33 | padding: const EdgeInsets.only(top: 16), 34 | child: widget.submitButton!( 35 | () => submitForm(), 36 | ), 37 | ) 38 | ], 39 | ); 40 | } 41 | 42 | return child; 43 | } 44 | 45 | @override 46 | FutureOr submit(T form) => widget.onSubmitted(form); 47 | 48 | void updateForceError(bool newValue) { 49 | setState(() { 50 | forceDisplayFieldsError = newValue; 51 | }); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/src/widgets/form_state.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_auto_form/src/models/error.dart'; 5 | import 'package:flutter_auto_form/src/models/field/field.dart'; 6 | import 'package:flutter_auto_form/src/models/field/field_context.dart'; 7 | import 'package:flutter_auto_form/src/models/form.dart'; 8 | import 'package:flutter_auto_form/src/widgets/theme.dart'; 9 | 10 | abstract class AFFormStatefulWidget extends StatefulWidget { 11 | const AFFormStatefulWidget( 12 | {super.key, 13 | required this.formBuilder, 14 | required this.onSubmitted, 15 | required this.enableFinalAction, 16 | this.enableSubmitFormWrapper, 17 | this.handleErrorOnSubmit, 18 | this.submitButton}); 19 | 20 | final T Function() formBuilder; 21 | 22 | final Function(T form) onSubmitted; 23 | 24 | final bool enableFinalAction; 25 | 26 | final bool? enableSubmitFormWrapper; 27 | 28 | final ValueChanged? handleErrorOnSubmit; 29 | 30 | final Widget Function(Function() submit)? submitButton; 31 | } 32 | 33 | /// The [AFFormState] allows to override and customize even more the behavior 34 | /// of the form widget's logic. 35 | /// 36 | /// Before considering extending this class, make sure that the [AFWidget] class 37 | /// does not satisfy your requirements! 38 | abstract class AFFormState, 39 | G extends TemplateForm> extends State { 40 | /// The [TemplateForm] that will be used as the blueprint of this class. 41 | late final G model; 42 | 43 | /// Whether to submit the form when the user clicks on the last field's [TextInputAction]. 44 | late final bool enableFinalAction; 45 | 46 | /// Whether to use wrap the submit function inside the [AFThemeData.submitFormWrapper] 47 | /// function. This can be useful to display a loading dialog while submitting 48 | /// the data. 49 | late final bool? enableSubmitFormWrapper; 50 | 51 | /// A callback that will be triggered whenever the [submitForm] method is called 52 | /// while the form is invalid. It exposes the first error returned by one of the 53 | /// form's field ([Field] 54 | late final ValueChanged? handleErrorOnSubmit; 55 | 56 | /// Whether to display each field's respective error (if there is one) even if 57 | /// the user did not interact with any of these fields. 58 | bool forceDisplayFieldsError = false; 59 | 60 | /// Since this getter makes use of the [context] value, it should not be 61 | /// called inside the [initState]. 62 | AFThemeData get theme => AFTheme.of(context); 63 | 64 | final Map _fieldContexts = {}; 65 | 66 | @override 67 | void initState() { 68 | super.initState(); 69 | 70 | model = widget.formBuilder(); 71 | 72 | enableFinalAction = widget.enableFinalAction; 73 | 74 | enableSubmitFormWrapper = widget.enableSubmitFormWrapper; 75 | 76 | handleErrorOnSubmit = widget.handleErrorOnSubmit; 77 | 78 | FieldContext? previousFieldContext; 79 | 80 | for (int index = 0; index < model.fields.length; index++) { 81 | final bool isLast = index == model.fields.length - 1; 82 | 83 | final field = model.fields[index]; 84 | 85 | final fieldContext = FieldContext( 86 | field: field, 87 | forceErrorDisplay: forceDisplayFieldsError, 88 | completeAction: isLast && enableFinalAction ? submitForm : null, 89 | previous: previousFieldContext, 90 | ); 91 | 92 | previousFieldContext?.next = fieldContext; 93 | 94 | if (isLast) { 95 | fieldContext.next = null; 96 | } 97 | 98 | _fieldContexts[field.id] = fieldContext; 99 | 100 | previousFieldContext = fieldContext; 101 | } 102 | } 103 | 104 | /// Builds each [Field] contained inside the [TemplateForm]. 105 | /// 106 | /// It then wraps all the fields inside an [AutofillGroup] for better autocompleting. 107 | Widget form() { 108 | final List fieldWidgets = [ 109 | for (Field field in model.fields) 110 | field.widgetBuilder( 111 | fieldContext: _fieldContexts[field.id]! 112 | ..updateWith( 113 | forceErrorDisplay: forceDisplayFieldsError, 114 | ), 115 | ) 116 | ]; 117 | 118 | return AutofillGroup( 119 | child: Column( 120 | children: fieldWidgets, 121 | ), 122 | ); 123 | } 124 | 125 | FutureOr submit(G form); 126 | 127 | Future submitForm() async { 128 | setState(() { 129 | forceDisplayFieldsError = true; 130 | }); 131 | 132 | if (model.isComplete()) { 133 | final bool enabledSubmitFormWrapper = enableSubmitFormWrapper ?? 134 | AFTheme.of(context).enableSubmitFormWrapper; 135 | 136 | try { 137 | if (enabledSubmitFormWrapper && enableFinalAction) { 138 | await theme.submitFormWrapper( 139 | context: context, 140 | future: submit(model), 141 | ); 142 | } else { 143 | await submit(model); 144 | } 145 | } on SubmitException catch (exception) { 146 | handleErrorOnSubmit?.call(exception.errorMessage); 147 | } 148 | } else { 149 | handleErrorOnSubmit?.call(model.getFirstError()!); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /lib/src/widgets/theme.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 3 | 4 | const _dTheme = AFThemeData(); 5 | 6 | class AFTheme extends InheritedWidget { 7 | const AFTheme({ 8 | Key? key, 9 | required Widget child, 10 | this.data = _dTheme, 11 | }) : super(key: key, child: child); 12 | 13 | final AFThemeData data; 14 | 15 | static AFThemeData of(BuildContext context) { 16 | final result = context.dependOnInheritedWidgetOfExactType()?.data; 17 | 18 | return result ?? _dTheme; 19 | } 20 | 21 | @override 22 | bool updateShouldNotify(AFTheme oldWidget) { 23 | return oldWidget.data != data; 24 | } 25 | } 26 | 27 | class AFThemeData { 28 | const AFThemeData({ 29 | this.submitFormWrapper = kShowFutureLoadingDialog, 30 | this.enableSubmitFormWrapper = true, 31 | }); 32 | 33 | /// A function that will be called by the [AFFormState] state whenever 34 | /// the form submitted by the user. It has the responsibility to await 35 | /// the future received as an argument which is returned by the 36 | /// [AFFormState.onSubmitted] 37 | final FutureWrapper submitFormWrapper; 38 | 39 | final bool enableSubmitFormWrapper; 40 | } 41 | -------------------------------------------------------------------------------- /lib/src/widgets/utils/loading_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | 5 | /// The widget that is displayed by the [kShowFutureLoadingDialog]. 6 | class DefaultLoadingWidget extends StatefulWidget { 7 | const DefaultLoadingWidget({ 8 | Key? key, 9 | required this.future, 10 | required this.popOnComplete, 11 | }) : super(key: key); 12 | 13 | final FutureOr future; 14 | final bool popOnComplete; 15 | 16 | @override 17 | State> createState() => 18 | _DefaultLoadingWidgetState(); 19 | } 20 | 21 | class _DefaultLoadingWidgetState extends State> { 22 | @override 23 | void initState() { 24 | super.initState(); 25 | 26 | if (widget.future is Future) { 27 | (widget.future as Future).then(_onComplete); 28 | } else { 29 | _onComplete(widget.future as T); 30 | } 31 | } 32 | 33 | void _onComplete(T value) { 34 | if (widget.popOnComplete) { 35 | Navigator.of(context).pop(value); 36 | } 37 | } 38 | 39 | @override 40 | Widget build(BuildContext context) { 41 | return Align( 42 | alignment: FractionalOffset.center, 43 | child: Column( 44 | mainAxisAlignment: MainAxisAlignment.center, 45 | mainAxisSize: MainAxisSize.min, 46 | children: [ 47 | Container( 48 | margin: const EdgeInsets.all(50), 49 | decoration: BoxDecoration( 50 | borderRadius: BorderRadius.circular(12.5), 51 | color: Colors.white, 52 | ), 53 | child: const Material( 54 | color: Colors.transparent, 55 | child: Padding( 56 | padding: EdgeInsets.all(16.0), 57 | child: CircularProgressIndicator(), 58 | ), 59 | ), 60 | ), 61 | ], 62 | ), 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_auto_form 2 | description: A package simplifying the process of creating user friendly forms in Flutter 3 | version: 2.0.0 4 | homepage: https://github.com/GaspardMerten/flutter_auto_form 5 | 6 | environment: 7 | sdk: '>=3.3.3 <4.0.0' 8 | 9 | dependencies: 10 | file_picker: ^8.0.2 11 | smarter_text_field: ^0.0.7 12 | date_field: ^5.0.1 13 | dropdown_search: ^5.0.6 14 | 15 | flutter: 16 | sdk: flutter 17 | 18 | dev_dependencies: 19 | flutter_test: 20 | sdk: flutter 21 | 22 | flutter_lints: ^2.0.1 23 | 24 | 25 | 26 | analyzer: 27 | plugins: 28 | - dart_code_metrics 29 | exclude: 30 | - lib/**.g.dart 31 | - lib/**.inject.dart 32 | - lib/**.inject.summary 33 | - test/**.g.dart 34 | - test/**.inject.dart 35 | -------------------------------------------------------------------------------- /test/models/validators/default_validators_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_auto_form/flutter_auto_form.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | void main() { 5 | test('Not null validator validates properly', () { 6 | const String propreValue = 'value'; 7 | 8 | expect(const NotNullValidator('error').validate(propreValue), equals(null)); 9 | 10 | const String? improperValue = null; 11 | 12 | expect( 13 | const NotNullValidator('error').validate(improperValue), 14 | equals('error'), 15 | ); 16 | }); 17 | 18 | test('Minimum string length validates properly', () { 19 | const String properLengthOne = 'gaspard'; 20 | const String properLengthTwo = 'gaspa'; 21 | 22 | expect( 23 | MinimumStringLengthValidator(5, (_) => 'error').validate(properLengthOne), 24 | equals(null), 25 | ); 26 | expect( 27 | MinimumStringLengthValidator(5, (_) => 'error').validate(properLengthTwo), 28 | equals(null), 29 | ); 30 | 31 | const String notProperLength = 'gasp'; 32 | 33 | expect( 34 | MinimumStringLengthValidator( 35 | 5, 36 | (String? value) => '$value', 37 | ).validate(notProperLength), 38 | equals(notProperLength), 39 | ); 40 | }); 41 | test('Same as field validator validates properly', () { 42 | const String dValue = 'value'; 43 | 44 | final AFTextField textField = AFTextField( 45 | id: 'id', 46 | name: 'name', 47 | validators: [], 48 | type: AFTextFieldType.text, 49 | value: dValue, 50 | ); 51 | 52 | expect( 53 | SameAsFieldValidator(textField, 'error').validate(dValue), 54 | equals(null), 55 | ); 56 | 57 | const String notSameValue = 'notTheSame'; 58 | 59 | expect( 60 | SameAsFieldValidator(textField, 'error').validate(notSameValue), 61 | equals('error'), 62 | ); 63 | }); 64 | test('AlphanumericV validator validates properly', () { 65 | const String properAlphanumeric = 'gaspard'; 66 | const String properAlphanumericWithNumber = 'gaspard1'; 67 | const String properAlphanumericWithCapitalizedLetters = 'Gaspard'; 68 | 69 | expect( 70 | const AlphanumericValidator('error').validate(properAlphanumeric), 71 | equals(null), 72 | ); 73 | expect( 74 | const AlphanumericValidator('error') 75 | .validate(properAlphanumericWithNumber), 76 | equals(null), 77 | ); 78 | expect( 79 | const AlphanumericValidator('error') 80 | .validate(properAlphanumericWithCapitalizedLetters), 81 | equals(null), 82 | ); 83 | 84 | const String improperAlphanumericOne = 'gaspard@merten'; 85 | const String improperAlphanumericTwo = 'gaspard merten'; 86 | const String improperAlphanumericThree = 'gaspard.merten'; 87 | 88 | expect( 89 | const AlphanumericValidator('error').validate(improperAlphanumericOne), 90 | equals('error'), 91 | ); 92 | expect( 93 | const AlphanumericValidator('error').validate(improperAlphanumericTwo), 94 | equals('error'), 95 | ); 96 | expect( 97 | const AlphanumericValidator('error').validate(improperAlphanumericThree), 98 | equals('error'), 99 | ); 100 | }); 101 | test('Should be true validator validates properly', () { 102 | const bool value = true; 103 | 104 | expect(const ShouldBeTrueValidator('error').validate(value), equals(null)); 105 | 106 | const bool falseValue = false; 107 | 108 | expect( 109 | const ShouldBeTrueValidator('error').validate(falseValue), 110 | equals('error'), 111 | ); 112 | }); 113 | test('Email validator validates properly', () { 114 | const String properEmail = 'gaspard@merten.be'; 115 | const String properEmailWithCapitalizedLetters = 'GasparD@Merten.BE'; 116 | 117 | expect(const EmailValidator('error').validate(properEmail), equals(null)); 118 | expect( 119 | const EmailValidator('error').validate(properEmailWithCapitalizedLetters), 120 | equals(null), 121 | ); 122 | 123 | const String improperEmailOne = 'gaspard@merten'; 124 | const String improperEmailTwo = 'gaspard.merten.be'; 125 | 126 | expect( 127 | const EmailValidator('error').validate(improperEmailOne), 128 | equals('error'), 129 | ); 130 | expect( 131 | const EmailValidator('error').validate(improperEmailTwo), 132 | equals('error'), 133 | ); 134 | }); 135 | 136 | test('URL Validator validates properly', () { 137 | const String properURL = 'https://www.merten.be'; 138 | 139 | expect(const URLValidator('error').validate(properURL), equals(null)); 140 | 141 | const String improperURLOne = 'gaspard@merten.be'; 142 | const String improperURLTwo = 'gaspard.merten.be'; 143 | 144 | expect( 145 | const URLValidator('error').validate(improperURLOne), 146 | equals('error'), 147 | ); 148 | expect( 149 | const URLValidator('error').validate(improperURLTwo), 150 | equals('error'), 151 | ); 152 | }); 153 | 154 | test('Hex Color Validator validates properly - Default mode, with #', () { 155 | const String properHexColorOne = '#f9232f'; 156 | const String properHexColorTwo = '#F9232F'; 157 | 158 | expect( 159 | const HexColorValidator('error').validate(properHexColorOne), 160 | equals(null), 161 | ); 162 | expect( 163 | const HexColorValidator('error').validate(properHexColorTwo), 164 | equals(null), 165 | ); 166 | 167 | const String improperHexColorOne = '#f9232x'; 168 | const String improperHexColorTwo = 'f9232aa'; 169 | const String improperHexColorThree = 'f9232a'; 170 | 171 | expect( 172 | const HexColorValidator('error').validate(improperHexColorOne), 173 | equals('error'), 174 | ); 175 | expect( 176 | const HexColorValidator('error').validate(improperHexColorTwo), 177 | equals('error'), 178 | ); 179 | expect( 180 | const HexColorValidator('error').validate(improperHexColorThree), 181 | equals('error'), 182 | ); 183 | }); 184 | test('Hex Color Validator validates properly - Without #', () { 185 | const String properHexColorOne = 'f9232f'; 186 | const String properHexColorTwo = 'F9232F'; 187 | 188 | expect( 189 | const HexColorValidator( 190 | 'error', 191 | mode: HexColorValidatorMode.withoutHashtag, 192 | ).validate(properHexColorOne), 193 | equals(null), 194 | ); 195 | expect( 196 | const HexColorValidator( 197 | 'error', 198 | mode: HexColorValidatorMode.withoutHashtag, 199 | ).validate(properHexColorTwo), 200 | equals(null), 201 | ); 202 | 203 | const String improperHexColorOne = '#f9232a'; 204 | const String improperHexColorTwo = 'f9232aa'; 205 | const String improperHexColorThree = 'f9232x'; 206 | 207 | expect( 208 | const HexColorValidator( 209 | 'error', 210 | mode: HexColorValidatorMode.withoutHashtag, 211 | ).validate(improperHexColorOne), 212 | equals('error'), 213 | ); 214 | expect( 215 | const HexColorValidator( 216 | 'error', 217 | mode: HexColorValidatorMode.withoutHashtag, 218 | ).validate(improperHexColorTwo), 219 | equals('error'), 220 | ); 221 | expect( 222 | const HexColorValidator( 223 | 'error', 224 | mode: HexColorValidatorMode.withoutHashtag, 225 | ).validate(improperHexColorThree), 226 | equals('error'), 227 | ); 228 | }); 229 | test('Hex Color Validator validates properly - Both mode (with & without #)', 230 | () { 231 | const String properHexColorOne = 'f9232f'; 232 | const String properHexColorTwo = 'F9232F'; 233 | const String properHexColorThree = '#f9232f'; 234 | const String properHexColorFour = '#F9232F'; 235 | 236 | expect( 237 | const HexColorValidator( 238 | 'error', 239 | mode: HexColorValidatorMode.both, 240 | ).validate(properHexColorOne), 241 | equals(null), 242 | ); 243 | expect( 244 | const HexColorValidator( 245 | 'error', 246 | mode: HexColorValidatorMode.both, 247 | ).validate(properHexColorTwo), 248 | equals(null), 249 | ); 250 | 251 | expect( 252 | const HexColorValidator( 253 | 'error', 254 | mode: HexColorValidatorMode.both, 255 | ).validate(properHexColorThree), 256 | equals(null), 257 | ); 258 | expect( 259 | const HexColorValidator( 260 | 'error', 261 | mode: HexColorValidatorMode.both, 262 | ).validate(properHexColorFour), 263 | equals(null), 264 | ); 265 | 266 | const String improperHexColorOne = '#f9232x'; 267 | const String improperHexColorTwo = 'f9232aa'; 268 | const String improperHexColorThree = 'f9232x'; 269 | 270 | expect( 271 | const HexColorValidator( 272 | 'error', 273 | mode: HexColorValidatorMode.both, 274 | ).validate(improperHexColorOne), 275 | equals('error'), 276 | ); 277 | expect( 278 | const HexColorValidator( 279 | 'error', 280 | mode: HexColorValidatorMode.both, 281 | ).validate(improperHexColorTwo), 282 | equals('error'), 283 | ); 284 | expect( 285 | const HexColorValidator( 286 | 'error', 287 | mode: HexColorValidatorMode.both, 288 | ).validate(improperHexColorThree), 289 | equals('error'), 290 | ); 291 | }); 292 | } 293 | --------------------------------------------------------------------------------