flutter_input 0.1.0 flutter_input: ^0.1.0 copied to clipboard
Input form with fields for Flutter
Flutter Input Form with Fields → 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. Any developers are highly welcome.
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
InputSwitch
- 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', ...
- 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<InputValidator
Development #
To create a new input field for data type T
.
- Create a new stateful widget for type
T
:class MyNewInputWidget extends InputField<T>
FormState extends State<Form>
abstract Field<T> extends StatefulWidget
Field itself is abstract and must be extended by a concrete implementation.T
is the type of the value.FieldState extends State<Field>
contains the value of typeT
.InputWidget extends Field<T>
where T is the value type of this input widget