flutter-form-builder-ecosystem / flutter_form_builder

Simple form maker for Flutter Framework
https://pub.dev/packages/flutter_form_builder
MIT License
1.46k stars 529 forks source link

Type safe forms values #825

Open sultanmyrza opened 3 years ago

sultanmyrza commented 3 years ago

currently FormBuilder.initialValue(formSchema) formSchema is Map<String, dynamic> any plans for making "form schema" type safe?

  /// An optional Map of field initialValues. Keys correspond to the field's
  /// name and value to the initialValue of the field.
  ///
  /// The initialValues set here will be ignored if the field has a local
  /// initialValue set.
  final Map<String, dynamic> initialValue; // current solution

  final T initialValue; // Maybe someday in the future?
deandreamatias commented 2 years ago

I don't sure if this is possible, because form use a map to fieldNames (String key) and your values (dynamic value). If do you have a solution, please feel free to make comments or a pull request

listepo commented 11 months ago

I have an idea to use code generation for this, but so far I haven't gotten around to experimenting

Desdaemon commented 9 months ago

I was just browsing so apologies if it's off-topic (thank you for developing this package!), but how about implementing the underlying Builder and State with two additional generics <K, V> for key and value, and existing widgets can be a specialization of <String, dynamic>? It's not full type safety but I think it gets close enough to be practical, e.g. K can be an enum and V a sealed enum class for ease of use.