I have 20 input fields in my app. What is the best way to define TextFormField widgets? For example:
Column(
children: [
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
_buildCariUnvanTextField(unvanController),
],
),
Should I have 20 separate methods? Is it correct way to define? Or what should i do? Can anyone explain?
CodePudding user response:
Avoid using helper methods altogether and instead define and use own defined classes/widgets.
For reference:
And another SO question where it has been answered:
What is the difference between functions and classes to create reusable widgets?
CodePudding user response:
You shouldn't have 20 different methods. You should use ListView.builder
code like this:
ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return _buildCariUnvanTextField(unvanController);
},
),
If the widgets are different, I think the only way is to have 20 different methods.