forme 2.0.0-beta+3 forme: ^2.0.0-beta+3 copied to clipboard
a powerful flutter form widget , for me,for you , renamed from form_builder
Forme #
a powerful flutter form widget , for me,for you
screenshot #
Simple Usage #
FormeKey formKey = FormeKey(); // FormeKey is a GlobalKey and also is a FormeManagement
Forme(key:formKey,
readOnly:true|false,
onChanged:FormeValueChanged,
child:Widget child,
);
Form Field #
Form Field types #
FormeField
- StatefulField
- ValueField
- NonnullValueField
- CommonField
methods #
FormeManagement #
FormeManagement formeManagement = formKey;
check whether form has a name field
bool hasField = formeManagement.hasField(String name);
whether form is readOnly
bool readOnly = formeManagement.readOnly;
set form readOnly|editable
formeManagement.readOnly = true|false;
get form data
Map<String, dynamic> data = formeManagement.data;
get form field validate errors
List<FormeFieldManagementWithError> errors = formeManagement.errors;
quietly vaidate form
List<FormeFieldManagementWithError> errors = formeManagement.quietlyValidate();
set form data
formeManagement.data = data;// will trigger field's onChanged listener
formeManagement.setData(data,trigger:bool) // if trigger is false ,won't trigger field's onChanged listener
reset form
formeManagement.reset();
validate form
will display error text
bool isValid = formeManagement.validate();
whether form is valid
won't display error text
bool isValid = formeManagement.isValid;
save form
formeManagement.save();
FormeFieldManagement #
create FormeFieldManagement by name
FormeFieldManagement formeFieldManagement = formeManagement.field(String name);
get field's name
String? name = formeFieldManagement.name;
whether field is readOnly
bool readOnly = formeFieldManagement.readOnly;
set readOnly|editable on field
formeFieldManagement.readOnly = true|false;
whether field is focusable
bool focusable = formeFieldManagement.focusable;
whether field is focused
bool hasFocus = formeFieldManagement.hasFocus;
focus|unfocus a form field
formeFieldManagement.focus = true|false;
set focus listener on field
formeFieldManagement.focusListener = (key,hasFocus){};
whether field is a value field
bool isValueField = formeFieldManagement.isValueField;
set state model
formeFieldManagement.model = FormeModel();
update state model #
formeFieldManagement.update<T>(FormeModelUpdater<T> updater);
get state model
FormeModel model = formeFieldManagement.model;
ensure form field visible
formeFieldManagement.ensureVisible();
FormeValueFieldManagement #
FormeValueFieldManagement extend FormeFieldManagement
get FormeValueFieldManagement
if field is not a value field , an error will be throw
FormeValueFieldManagement formeFieldManagement = formeManagement.valueField(String name);
get field's value
dynamic value = valueFieldManagement.value;
set field value
valueFieldManagement.value = value; // set field value , will trigger onChanged listener
textSelectionManagement.setValue(value,trigger:bool); // if trigger is false ,won't trigger onChanged listener
whether field is valid
won't display error text
bool isValid = valueFieldManagement.isValid;
validate field
will display error text
bool isValid = valueFieldManagement.validate();
get error text
String? errorText = valueFieldManagement.errorText;
quietlyValidate field
won't display error text
String? errorText = valueFieldManagement.quietlyValidate();
currently supported value fields #
field | return value | nullable |
---|---|---|
FormeTextField | string | false |
FormeDateTimeTextField | DateTime | true |
FormeNumberTextField | num | true |
FormeTimeTextField | TimeOfDay | true |
FormeDateRangeTextField | DateTimeRange | true |
FormeSlider | double | false |
FormeRangeSlider | RangeValues | false |
FormeFilterChip | List< T> | false |
FormeChoiceChip | T | true |
FormeSingleCheckbox | bool | false |
FormeSingleSwitch | bool | false |
FormeDropdownButton | T | true |
FormeListTile | List< T> | false |
currently supported other fields #
field | description |
---|---|
FormeVisible | make field visible|invisible |
FormeColumn | a column support insert|swap|remove widgets |
FormeRow | a row support insert|swap|remove widgets |
example for helping build a custom field #
build a common field #
https://github.com/wwwqyhme/forme/blob/main/lib/src/field/forme_flex.dart
build a nonnull value field #
https://github.com/wwwqyhme/forme/blob/main/lib/src/field/forme_single_switch.dart
build a value field #
https://github.com/wwwqyhme/forme/blob/main/lib/src/field/forme_choice_chip.dart