dynamic_forms_generator 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

dynamic_forms_generator #

pub package

Dart library for generating model and parser part of the flutter_dynamic_forms.

Main goal #

There is a lots of boilerplate code needed to write a single component for the flutter_dynamic_forms. Especially in the model and parser classes. To simplify this task we can describe components in a simple Yaml format and let this generator create model and parser for us.

Usage #

To use this generator you need to have all the Yaml files for the related components in your project.

After that add this package as a dev dependency together with build_runner:

dev_dependencies:
  build_runner: ^1.0.0
  dynamic_forms_generator: <latest version>

Optionally add a build.yaml to the root of your project to override default imports that should be generated in your files:

targets:
  $default:
    builders:
      dynamic_forms_generator:dynamicFormsBuilder:
        options:
          default_imports:
            - "../components.dart"
            components_to_ignore:
            - "form_element.yaml"
            - "validation.yaml"

default_imports will generate this import line to the both of model and parser files.

components_to_ignore will not generate anything for the listed components. Specifically form_element.yaml and validation.yaml are the default option so you don't need to explicitly list them. Reason why you don't want to generate anything for those classes is that they already have their models and parsers in the dynamic_forms library but other components can extend them and generator needs to have all the Yaml definitions in the project so it can correctly analyse their structure.

Other options are model_imports and parser_imports which generates imports at the beginning of the model or parser file.

Now you simply run

pub run build_runner build

or if you are using Flutter

flutter packages pub run build_runner build

Instead of build you can use watch to track changes. See build_runner package for more information.

Component description structure #

Each component should contain all the necessary info to be able to represent it in xml format.

Example component definitions:

type: checkBox
parentType: formElement
properties:
  label:
    type: string
  value:
    type: bool
    default: false
    isMutable: true
type: container
parentType: formElement
properties:
  children:
    type: formElement[]
contentProperty: children
type: singleSelectGroup<tSingleSelectChoice extends singleSelectChoice>
parentType: formElement
properties:
  value:
    type: string
    isMutable: true
  choices:
    type: tSingleSelectChoice[]
type: dropdownButton
parentType: singleSelectGroup<dropdownOption>
  • Required type contains unique value which identifies the component.
    • Can contain optional generic parameters.
      • Parameters are wrapped between < > and delimited by comma.
      • Each parameter can be followed by the extend keyword and other type which will further constraint the type.
  • Optional parentType contains name of other element and it inherits all its properties and the contentProperty.
    • Can contain optional generic parameters.
      • Parameters are wrapped between < > and delimited by comma.
  • Optional properties section contains map of all the component properties.
    • Each key in this map corresponds to the property name and value contains other property descriptions.
      • Required type represents type of the property.
      • Optional default contains default value of the property when it is not explicitly set.
      • Optional isMutable contains optional info wheter state of the property can be mutated. Default is false.
        • When set to true it is expected to be sent from a client back to a server.
  • Optional contentProperty contains name of the property, which can be written directly as a child of the component element.

Types #

There are multiple types that can be set to the type in the property description:

  • int - 64-bit two's complement integer
  • decimal
  • bool
  • string
  • dateTime - string as standardized format of date-time (ISO 8601)
  • typename that ends with valueElement or ValueElement (e.g. moneyValueElement) - used for structures
  • typename that ends with enumElement or EnumElement (e.g. exampleEnumElement) - used for enumerators
  • enum - used only in enumElement components
  • customformElement - name of the other component
  • customformElement[] - array of the other components

Each type is nullable and when property is not set it defaults to the null (unless default key is defined).

YAML -> XML

In XML the name corresponds to the element name.

parentType is not represented in the xml.

Property can be written directly as an attribute of the element

<element propertyName="property value"/>

and in case of complex values it can also be written as:

<element>
    <element.propertyName>
        property value
    </element.propertyName>
</element>

Each property which is not type formElement can also contain expression as the element value:

<element>
    <element.propertyName>
        <expression>
            1 + 1
        </expression>
    </element.propertyName>
</element>

See https://github.com/OndrejKunc/flutter_dynamic_forms to learn more about expressions.

contentProperty allows to write the selected property directly inside the element. In case of container it looks like this:

<container>
    <child1/>
    <child2/>
</container>

YAML -> JSON

JSON has very similar mapping except that contentProperty is ignored.

0.2.0 #

Added support for value types and enums.

0.1.3 #

Fixed issue with files having the same suffix.

0.1.2 #

Added default value for strings.

0.1.1 #

Fixed small health suggestions.

0.1.0 #

Initial Version of the library.

example/main.dart

void main() {
  print("Hello world");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dynamic_forms_generator: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dynamic_forms_generator/dynamic_forms_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:dynamic_forms_generator/dynamic_forms_generator.dart with components: io, build.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
build ^1.0.0 1.2.0
build_config >=0.2.6 <0.5.0 0.4.1+1
petitparser ^2.1.1 2.4.0
yaml ^2.1.16 2.2.0
Transitive dependencies
analyzer 0.38.5
args 1.5.2
async 2.4.0
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
front_end 0.1.27
glob 1.1.7
html 0.14.0+3
json_annotation 3.0.0
kernel 0.3.27
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
pubspec_parse 0.1.5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
Dev dependencies
test ^1.6.3