autoform 0.0.5
autoform: ^0.0.5 copied to clipboard

A simple package to help you build forms. A form builder with code controlled validation.

autoform #

A simple package to help you build forms.

Getting Started #

Straight forward form builder.

Simple implementation #



class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {

  var form = AutoForm(
    values: {'name': 'Edwards'},
    properties: [
      AutoProperty(
        field: 'name',
        title: 'Name',
        validator: AutoValidators.isEmail,
        type: AutoPropertyType.text,
      ),
      AutoProperty(
          field: 'personality',
          title: 'Personality Type',
          validator: AutoValidators.isEmail,
          type: AutoPropertyType.multiselect,
          options: ['Simple', 'Complex', 'Other']),
    ],
  ).create();

  @override
  void initState() {
    super.initState();
    var s = AutoFormSettings();
    s.fieldMargin = EdgeInsets.symmetric(vertical: 20);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Column(
          children: [
            form.widget,
            ElevatedButton(
              onPressed: () {
                var isValid = form.form.validate();
                if (isValid) {
                  pprint("Form validated");
                } else {
                  pprint("Errors");
                }
              },
              child: Text("Validate"),
            ),
          ],
        ),
      ),
    );
  }
}


Create a form from map #


  var personForm = AutoForm.fromMap({
      'properties': [
        {
          'title': 'Full Name',
          'field': 'fullName',
          'validator': 'isRequired',
          'type': 'text',
        },
        {
          'title': 'Age',
          'field': 'age',
          'type': 'number',
        },
        {
          'title': 'Gender',
          'field': 'gender',
          'type': 'select',
          "options": ["Male", "Female", "rather not say"]
        },
      ]
    }).create();

1
likes
100
pub points
46%
popularity

A simple package to help you build forms. A form builder with code controlled validation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on autoform