checkbox_formfield

pub package

A few kinds of checkbox that can be used as FormField

Getting Started

This library currently has two Widgets.

  • CheckboxListTileFormField: Use CheckboxListTile in Form
  • CheckboxIconFormField: Use two Icons as if they consist a checkbox and also in Form

Demo

Demo

Usage sample

class TaskEditPage extends StatelessWidget {
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'Sample',
        ),
      ),
      body: Padding(
        padding: EdgeInsets.all(16),
        child: Column(
          children: <Widget>[
            Form(
              key: _formKey,
              child: Column(
                children: <Widget>[
                  CheckboxListTileFormField(
                    title: Text('Check!'),
                    onSaved: (bool value) {},
                    validator: (bool value) {
                      if (value) {
                        return null;
                      } else {
                        return 'False!';
                      }
                    },
                  ),
                  CheckboxIconFormField(
                    iconSize: 32,
                    onSaved: (bool value) {},
                  ),
                  RaisedButton(
                    onPressed: () {
                      if (_formKey.currentState.validate()) {
                        _formKey.currentState.save();
                      }
                    },
                    child: Text('Submit'),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Specifications

CheckboxListTileFormField

ParameterDescription
keyFormField.key
titleCheckboxListTile.title
contextProvide a default color to errorColor
onSavedFormField.onSaved
validatorFormField.validator
initialValueFormField.initialValue
autovalidateFormField.autovalidate
enabledWhether the checkbox is enabled
denseCheckboxListTile.dense
errorColorColor of error message
Default: Theme.errorColor (context is given), Colors.red (otherwise)
activeColorCheckboxListTile.activeColor
checkColorCheckboxListTile.checkColor
controlAffinityCheckboxListTile.controlAffinity
secondaryCheckboxListTile.secondary

CheckboxIconFormField

ParameterDescription
keyFormField.key
contextProvide a default color to errorColor
onSavedFormField.onSaved
initialValueFormField.initialValue
autovalidateFormField.autovalidate
enabledWhether the checkbox is enabled
trueIconIconData if true
Default: Icons.check
falseIconIconData if false
Default: Icons.check_box_outline_blank
trueIconColorColor if true
Default: Theme.accentIconTheme.color (if context is given), Theme.iconTheme.color (otherwise)
falseIconColorColor if false
Default: Theme.iconTheme.color
disabledColorColor if disabled
Default: Theme.disabledColor
paddingpadding
Default: 24.0
iconSizeIcon.size

Libraries

checkbox_formfield
checkbox_icon_formfield
checkbox_list_tile_formfield