Given the following page with 3 tabs that all contain multiple textfields, is using the riverpod library the best/easiest way to both set and collect values from each tab’s textformfield widgets?
The "Save" button should collect all the values. likewise, when creating the form, a data model is passed in containing all the info, and should be distributed among the tabs. I’ve been reading that there seem to be multiple ways to do this, such as providers, textcontrollers, etc, but i just found the riverpod library and it seems the easiest option.
Thanks!
2
Answers
You can simplify handling multiple TextFormFields by using the flutter_form_builder package. It makes form handling easier by providing built-in widgets for validation and input collection, without needing to manually manage each field.
}
}
I’m not a fan of one-fits-all. But, indeed Riverpod can be a good solution for this.
I think
StateNotifier
works pretty fine for your case. I don’t think you’re looking for a code solution by the question, but just to outline the process here are some code snippets that might help.You’ll have to create a state class containing all the different properties you’re going to collect.
Something like:
Get your
StateNotifierProvider
ready:Create your State Notifier:
And there you go, just use it in your actual widgets.
At the end of everything, in your save button widget, just access the state:
You’re good to go! You can do the same in pretty much a million different ways, but the important thing is to consider is the time and resource you might want to spend to a single problem. If you find Riverpod easy and as it can do it efficiently that’s a way-to-go.
Hope this helps!