flutter_input 0.2.0 flutter_input: ^0.2.0 copied to clipboard
Input fields with form for Flutter
Flutter Input Fields standalone or within a Form → flutter_input #
This package provides an InputForm
and a set of input fields.
Each input field can be used standalone or as part of a form.
This package is an early version of the architectural ideas described below. It still has issues especially concerning decoration. Developers are highly welcomed :-)
The main goal of this package is to provide ideas and input for data management with Flutter. My hope is that it becomes maintained by the Flutter team or be integrated with other similar packages.
Please see and vote issue https://github.com/flutter/flutter/issues/46073 on GitHub.
Input fields #
Currently the following input fields are supported:
InputCheckbox
- Checkbox for data typebool
InputDate
- Calendar selection for data typeDateTime
InputDateTime
- Sliders for data typeDateTime
can be customized for date only, time only or bothInputDropDown<T>
- Dropdown button for data typeT
InputFavorite
- A favorite button with selectable icon for data typebool
InputRadio<T>
- Radio button to select one value of typeT
InputRating
- Rating widget with selectable icons and a range selector for data typeint
InputSlider
- Slider for data typedouble
between a minimum and maximum valueInputSpinner
- Spinner with buttons for data typedouble
to decrease or increase a value between a minimum and maximumInputSwitch
- Switch for data typebool
InputText
- Text input for data typeString
Architecture #
This package is based on the following design criteria:
- Provide an easy to understand package for data input which is easy to use, to maintain and to extend
- Have a form to manage one data object (a
Map
) for all fields providing a central method tovalidate()
andsave()
. - Fields access this map by means of a
path
string to get an initial value and to save back the fields value. - Fields can be used stand alone, even within a form.
To achieve this,
path
must benull
andonChanged
must not. - Widget attributes with same functionality should have same names (unlike 'initialValue' and 'value' or 'onChanged' and 'onValueChanged')
- All fields have a common set of attributes
- Have as much layout design to the form as possible (can still be overwritten by each field-widget)
- Each input field should auto-assign itself to the form
(requires attribute
path
). - Each input widget should accept a list of reusable validators like 'NotNull', 'Min', 'Max', 'Future', 'Past', ...
- Input fields do not have standard parameters for data type conversion.
If this is required in some case, just use your converter on parameters
initialValue
andonSave
. - All input fields should have an ".adaptive" constructor allowing them to be used by Android and iOS. (Not implemented yet)
Usage #
For a complete example see example/main.dart
.
All field constructors have the following shared parameters. All parameters are named and optional.
- Key key
bool autovalidate = false
//- InputDecoration decoration - e.g. for a label
- bool enabled - to protect the field against changes. Overrides
setting through the
Form
- T initialValue - to set the fields initial value. Overrides using the value from the forms map.
- ValueSetter
- ValueSetter
- String path - to access the form map
- List
Development #
To create a new input field for data type T
just copy one of the existing
classes and modify it accordingly. Replace T with the type of the value of
your new input field.
- Create a new stateful widget for type
T
withclass MyNewInputWidget extends InputField<T> {
class MyNewInputState extends InputFieldState<T> {
where T is replaced by the type of the value of the field.- Write method
build( BuildContext context)
in the state class. It must end withreturn super.buildInputField( context, ...
where...
is the code to display your input field widget.