This might be more of a Dart question than Flutter, but it originates from a requirement I have in a Flutter project.
I am to receive a definition of a field in a form, and in Flutter, I am to display a dynamic widget that is created according to the field definition.
Say for example I receive a json file describing a DateTime field, and it describes this field specifically to show only the date.
I believe the solution should be a generated file, that holds a map between a field definition and an instance of widget, like so:
{
"DateTimeDateOnly": "MyWidget(prop1: hardcoded value, prop2: dataObject.fieldValue)"
}
I was wondering:
- Is this possible?
- How can I create the widget dynamically, in a way that for every field I’ll need to display in the same manner, I’ll get the same widget?
- Once the definition itself is updated(I get a new json), how do I update the mapping from the field definition to its widget representation?