forme 2.0.0-alpha4+1 forme: ^2.0.0-alpha4+1 copied to clipboard
a powerful flutter form widget , renamed from form_builder
Forme #
a powerful flutter form widget
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 #
get FormeManagement
FormeKey is a FormeManagement,but if you want to get underlying FormeManagement,you can use methods below
FormeManagement formeManagement = formKey.currentFormeManagement;// return a nonnull FormeManagement
FormeManagement? formeManagement = formKey.quietlyManagement;// return a FormeManagement , return null if not find
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 |
FormeRate | dobule | true |
FormeSingleCheckbox | bool | false |
FormeSingleSwitch | bool | false |
FormeCupertinoPicker | int | false |
FormeDropdownButton | T | true |
FormeListTile | List< T> | false |
currently supported other fields #
field | description |
---|---|
FormeButton | button |
FormeVisible | make field visible|invisible |
FormeColumn | a column support insert|swap|remove widgets |
FormeRow | a row support insert|swap|remove widgets |
currently supported widgets #
field | description |
---|---|
FormeClearButton | a icon button used to clear field's value |
FormePasswordVisibleButton | a icon button used to toggle textfield's obscureText |
FormeTextFieldWidget | a textfield . when click prefix or suffix buttons, will not trigger textfield's onTap |
FormeDropdownButtonClearButton | a icon button used to clear FormeDropdownButton's value |
FormeCupertinoPickerLockButton | a icon button used to enable or disable FormeCupertinoPicker's scroll |
example for helping build a custom field #
build a common field #
https://github.com/wwwqyhme/forme/blob/main/lib/src/field/forme_button.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_rate.dart