FormBuilder Extra Fields

FormBuilder Extra Fields provides common ready-made form input fields for flutter_form_builder package. The package gives you a convenient way of adding common ready-made input fields instead of creating your own FormBuilderField from scratch.


Pub Version GitHub Workflow Status Codecov CodeFactor Grade GitHub OSS Lifecycle

Buy me a coffee


Example

import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_fields/form_builder_extra_fields.dart';

...

final _formKey = GlobalKey<FormBuilderState>();
final continents = ['Africa', 'Asia', 'Australia', 'Europe', 'North America', 'South America'];
...


@override
Widget build(BuildContext context) {
  return FormBuilder(
    key: _formKey,
    autovalidate: true,
    child: Column(
      children: <Widget>[
        FormBuilderSearchableDropdown(
          name: 'searchable_dropdown',
          items: continents,
          decoration:
              const InputDecoration(labelText: 'Searchable Dropdown'),
        ),
        const SizedBox(height: 15),
        FormBuilderColorPickerField(
          name: 'color_picker',
          initialValue: Colors.yellow,
          // readOnly: true,
          colorPickerType: ColorPickerType.MaterialPicker,
          decoration: const InputDecoration(labelText: 'Color Picker'),
        ),
        FormBuilderCupertinoDateTimePicker(
          name: 'date_time',
          initialValue: DateTime.now(),
          inputType: CupertinoDateTimePickerInputType.both,
          decoration: const InputDecoration(
            labelText: 'Cupertino DateTime Picker',
          ),
          locale: Locale.fromSubtags(languageCode: 'en_GB'),
        ),
        FormBuilderCupertinoDateTimePicker(
          name: 'date',
          initialValue: DateTime.now(),
          inputType: CupertinoDateTimePickerInputType.date,
          decoration: const InputDecoration(
            labelText: 'Cupertino DateTime Picker - Date Only',
          ),
          locale: Locale.fromSubtags(languageCode: 'en_GB'),
        ),
        FormBuilderCupertinoDateTimePicker(
          name: 'time',
          initialValue: DateTime.now(),
          inputType: CupertinoDateTimePickerInputType.time,
          decoration: const InputDecoration(
            labelText: 'Cupertino DateTime Picker - Time Only',
          ),
          locale: Locale.fromSubtags(languageCode: 'en_GB'),
        ),
        FormBuilderTypeAhead<String>(
          decoration: const InputDecoration(
              labelText: 'TypeAhead (Autocomplete TextField)',
              hintText: 'Start typing continent name'),
          name: 'continent',
          itemBuilder: (context, continent) {
            return ListTile(title: Text(continent));
          },
          suggestionsCallback: (query) {
            if (query.isNotEmpty) {
              var lowercaseQuery = query.toLowerCase();
              return continents.where((continent) {
                return continent.toLowerCase().contains(lowercaseQuery);
              }).toList(growable: false)
                ..sort((a, b) => a
                    .toLowerCase()
                    .indexOf(lowercaseQuery)
                    .compareTo(
                        b.toLowerCase().indexOf(lowercaseQuery)));
            } else {
              return continents;
            }
          },
        ),
        FormBuilderTouchSpin(
          decoration: const InputDecoration(labelText: 'TouchSpin'),
          name: 'touch_spin',
          initialValue: 10,
          step: 1,
          iconSize: 48.0,
          addIcon: const Icon(Icons.arrow_right),
          subtractIcon: const Icon(Icons.arrow_left),
          
        ),
        FormBuilderRating(
          decoration: const InputDecoration(labelText: 'Rating'),
          name: 'rate',
          iconSize: 32.0,
          initialValue: 1.0,
          max: 5.0,
        ),
        FormBuilderSignaturePad(
          decoration: const InputDecoration(
            labelText: 'Signature Pad',
          ),
          name: 'signature',
          border: Border.all(color: Colors.green),
        ),
        const SizedBox(height: 10),
        Row(
          children: <Widget>[
            Expanded(
              child: MaterialButton(
                color: Theme.of(context).colorScheme.secondary,
                child: Text(
                  "Submit",
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  _formKey.currentState.save();
                  if (_formKey.currentState.validate()) {
                    print(_formKey.currentState.value);
                  } else {
                    print("validation failed");
                  }
                },
              ),
            ),
            SizedBox(width: 20),
            Expanded(
              child: MaterialButton(
                color: Theme.of(context).colorScheme.secondary,
                child: Text(
                  "Reset",
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  _formKey.currentState.reset();
                },
              ),
            ),
          ],
        ),
      ],
    ),
  );
}

Input widgets

The currently supported fields include:

  • FormBuilderChipsInput - Takes a list of Chips as input and suggests more options on typing
  • FormBuilderColorPicker - For Color input selection
  • FormBuilderCupertinoDateTimePicker - For Date, Time and DateTime input using a Cupertino-style picker
  • FormBuilderRating - For selection of a numerical value as a rating
  • FormBuilderSearchableDropdown - Field for selecting value(s) from a searchable list
  • FormBuilderSignaturePad - Field with drawing pad on which user can doodle
  • FormBuilderTouchSpin - Selection of a number by tapping on a plus or minus icon
  • FormBuilderTypeAhead - Auto-completes user input from a list of items

In order to create an input field in the form, along with the label, and any applicable validation, there are several attributes that are supported by all types of inputs namely:

AttributeTypeDefaultRequiredDescription
nameStringYesThis will form the key in the form value Map
initialValueTnullNoThe initial value of the input field
enabledbooltrueNoDetermines whether the field widget will accept user input.
decorationInputDecorationInputDecoration()NoDefines the border, labels, icons, and styles used to decorate the field.
validatorFormFieldValidator<T>nullNoA FormFieldValidator that will check the validity of value in the FormField
onChangedValueChanged<T>nullNoThis event function will fire immediately the the field value changes
valueTransformerValueTransformer<T>nullNoFunction that transforms field value before saving to form value. e.g. transform TextField value for numeric field from String to num
The rest of the attributes will be determined by the type of Widget being used.

Support

Issues and PRs

Any kind of support in the form of reporting bugs, answering questions or PRs is always appreciated.

Coffee :-)

If this package was helpful to you in delivering your project or you just wanna to support this package, a cup of coffee would be highly appreciated ;-)

Buy me a coffee

Libraries

form_builder_extra_fields