Skip to content

Dynamic forms in flutter #987

Closed Answered by ShadyZekry
Satendra9984 asked this question in Q&A
Discussion options

You must be logged in to vote

One possible sollution is to assign a "string-key" for every field that your app supports, then map every field in that json into it's corrisponding widget with its parameters.

If your json looks like this:

[
	{
		"type": "text_field",
		"label": "text field1",
		"value": "your value here",
		"hintText": "custom hint",
		"errorText": "custom error"
	},
	{
		"type": "text_area",
		"label": "text field2",
		"hintText": "custom hint",
		"errorText": "custom error"
	},
	{
		"type": "check_box",
		"label": "text field2",
		"value": ""
	}
]

Then your code should look like this:

  // Maps every object in the json to an instance of a widget
  static final Map<String, Widget Function(Map<String, d…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by deandreamatias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants