lets build form package (draft) (wip)
user will write somethings like this
// should use marcos
@RiverForm()
class NameForm {
@StringItem<String>() // this may be optional and take it from datatype
external String name();
@PhoneTransformer<String>()
@PasswordValidator()
@PhoneValidator()
external String phone();
@PasswordValidator()
external String password();
@EqualField(#password) // password and confirmPassword should be equal
external String confirmPassword();
}
then he should use it like this
class MyWidget extends HookWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
final form = useForm(NameForm());
return Form(
key: form.key,
child: Column(
children: [
TextFormField(
controller: form.name.controller,
validator: form.name.validator,
),
RiverText(form.name),
form.name.build(),
TextButton(
child: const Text("data"),
onPressed: () {
if (!form.validate()) {
return;
}
final result = form.result;
result.name;
result.phone;....
},
)
],
),
);
}
}
usecase:
- two password match
- phone transformer
- dropdown
- checklist
- option list
- multi select (array)
- validation
- ease pass data to other layer
- maybe toJson
- integrate with hook
- ease dispose
- default value
- password obsecure
- complex validator for report multi error in password
- maybe step too
- type safety first
step:
- try to generate a class using macros depends on fields
Libraries
- form_kit
- Support for doing something awesome.