Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

Input fields for Flutter standalone or within a form

Flutter Input Widgets – Standalone or within a Form → flutter_input

This package provides input widgets (fields) to manipulate data. The data to manipulate is either a single variable or an entry in a map. The map can even be nested. Parameter path defines the key to access the entry in the map. To access an entry in a nested map, the keys must be separated by a single slash (/) character.

All input widgets share a common set of parameters and methods. A list of validators can be attached to each input widget.

Each input widget can be used standalone. If it finds a InputForm ancestor then it will automatically register itself to the form. The form provides methods to enable()reset()save() or validate() all fields at once.

Input Widgets

The following input widgets are available. See section Development below for building your own input widget.

Common Parameters

All input widgets share a common set of parameters. All parameters are named and optional.

Validators

The following validators can be given to parameter validators of an input widget. Each validator accepts the optional parameter message to set an individual error message if the validation fails.

Usage

Each input widget will automatically register itself if it finds an InputForm ancestor. Otherwise it will just run standalone. It will use initialValue for its value to display. If initialValue is null then it will use the value from map[path] if both are set. If map is not set, then the field will use map from an InputForm ancestor (if there is any).

Saving a modified value will happen

The changed value will be written to the map at path if both were supplied. Also method onSave() will be invoked with the changed value.

Demo

For a complete example see example/main.dart.

InputDatePicker

The highly customizable InputDatePicker allows you to choose a date from a calendar page which also shows the week of the year. It provides spinners, swipes and a dropdown to select the month. The year can even be entered as text. All parts can be customized by DatePickerStyles.

Development

To create a new input field for data type T follow these steps:

  1. Copy one of the included class files.
  2. Rename the class widget and its state to your new one.
  3. Replace T with the value type of your new input field.
  4. Adapt parameters and leave the call to super() with all the common parameters.
  5. Adapt method build( BuildContext context) in the state class. It must end with return super.buildInputField( context, ... where ... is the code to display your new field widget.

Utilities

This package also contains some utilities.

To Do

Download Flutter Input Widgets source code on GitHub

https://github.com/djarjo/flutter_input

Exit mobile version