xform 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

XForm #

Flutter forms with superpowers. #

Simplifies form creation and management. Simply create form fields and the xform will take care of the rest. Moving to the next field on enter, keyboard type based on field type, validation, multipage forms, etc.

Supported Fields #

  • XTextField - Your usual text field
  • XDateField - Text field with a date picker
  • XSelectField - Dropdown selection box
  • XCheckbox - Checkbox returning true or false values
  • XCheckboxGroup - Grouped checkboxes returning an array of the selected values
  • XRadioGroup - Grouped radio buttons

Quick Start #

  • Add the XForm widget to a stateful widget
  • Add XFields as children, each page wrapped in a ListView.
  • Add a submit function to handle the data on submission.

Example #

import 'package:flutter/material.dart';
import 'package:xform/xform.dart';

void main() => runApp(MaterialApp(
      home: Scaffold(
          appBar: AppBar(title: const Text('XForm')), body: FormWidget()),
    ));

class FormWidget extends StatefulWidget {
  @override
  _FormWidgetState createState() => _FormWidgetState();
}

class _FormWidgetState extends State<FormWidget> {
  _submit(formData) {
    print(formData);
  }
  
  @override
  Widget build(BuildContext context) {  
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: XForm(submit: _submit, children: <Widget>[
        ListView(children: <Widget>[
          XTextField(
            name: "name",
            label: "Name",
            required: true,
          ),
          XTextField(
            name: "email",
            label: "Email Address",
            type: FieldType.email,
          ),
        ]),
      ]),
    );
  }
}

[0.2.0] - 9 Apr 2019

  • Date field returns date type
  • Numeric field returns numeric value
  • Added support for switch
  • Validation on page switch

[0.1.2] - 29 Jan 2019

  • Fixed Form display on long forms to not overlap buttons
  • Added support for checkbox, checkboxgroup and radiogroup
  • Changed default values from string to dynamic

[0.1.1] - 17 Jan 2019

  • Fixed bug in date field default values

[0.1.0] - 16 Jan 2019

  • Added styling options to fields
  • Added required option to select field
  • Updated date field to also take keyboard input
  • Updated readme

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:xform/xform.dart';
import 'dart:async';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  GlobalKey scaffoldKey = GlobalKey();
  @override
  Widget build(BuildContext context) {
    Future _submit(Map<String, dynamic> formData) async {
      List<Widget> children = [];
      formData.forEach((key, value) {
        children.add(Text("$key: ${value.toString()} ${value.runtimeType}"));
      });
      showDialog(
        context: scaffoldKey.currentState.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("Form Data"),
            content: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: children),
            actions: <Widget>[
              FlatButton(
                child: Text("Close"),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        },
      );
    }

    return MaterialApp(
      home: Scaffold(
        key: scaffoldKey,
        appBar: AppBar(
          title: const Text('XForm'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: XForm(submit: _submit, children: <Widget>[
            ListView(children: <Widget>[
              XTextField(
                name: "name",
                label: "Name",
                required: true,
              ),
              XTextField(
                name: "number",
                label: "Number",
                type: FieldType.numeric,
              ),
              XTextField(
                name: "email",
                label: "Email Address",
                type: FieldType.email,
              ),
              XTextField(
                name: "password",
                label: "Password",
                type: FieldType.password,
              ),
            ]),
            ListView(children: <Widget>[
              XCheckbox(
                name: "agree",
                label: "I agree",
                defaultValue: true,
              ),
              XSwitch(
                name: "switch",
                label: "Flip Me",
                defaultValue: true,
              ),
              XRadioGroup(
                name: 'radios',
                selected: "male",
                options: [
                  Option(name: "Male", value: "male"),
                  Option(name: "Female", value: "female"),
                ],
              ),
              XCheckboxGroup(
                name: 'favourite',
                label: 'Favourite Food',
                selected: ["cake"],
                options: [
                  Option(name: "Cake", value: "cake"),
                  Option(name: "Candy", value: "candy"),
                ],
              ),
            ]),
            ListView(children: <Widget>[
              XDateField(
                name: "date",
                label: "Date of Birth",
                defaultValue: DateTime.now(),
              ),
              XSelectField(
                name: "options",
                label: "Options",
                required: true,
                options: [Option(name: "Name", value: "value")],
              )
            ]),
          ]),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  xform: ^0.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:xform/xform.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/xformcontainer.dart. (-1 points)

Analysis of lib/src/xformcontainer.dart reported 2 hints:

line 16 col 17: 'ancestorStateOfType' is deprecated and shouldn't be used. Use findAncestorStateOfType instead. This feature was deprecated after v1.12.1..

line 16 col 43: 'TypeMatcher' is deprecated and shouldn't be used. TypeMatcher has been deprecated because it is no longer used in framework(only in deprecated methods). This feature was deprecated after v1.12.1..

Fix lib/src/xform.dart. (-0.50 points)

Analysis of lib/src/xform.dart reported 1 hint:

line 22 col 39: 'inheritFromWidgetOfExactType' is deprecated and shouldn't be used. Use dependOnInheritedWidgetOfExactType instead. This feature was deprecated after v1.12.1..

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (intl).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
intl ^0.15.7 0.15.8 0.16.1
validate ^1.7.0 1.7.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test