After extracting the method of my textformfield widget, I want to add controller to it using the TextEditingController,the issue is how to placed it in each fields but i have extracted it all to a method, but if I type anything it shows for all the input fields:
This is the signup part where I am trying to use the controller, but i kept it below
Container buildSignupSection() {
return Container(
margin: EdgeInsets.only(top: 30),
child: Form(
key: _signUpFormKey,
child: Column(
children: [
buildTextField(
"xpresschop",
"Name",
true,
false,
false,
),
buildTextField(
"[email protected]",
"email",
false,
false,
true,
),
buildTextField(
"......",
"password",
false,
true,
false,
),
buildTextField(
"......",
"Confirm password",
false,
true,
false,
),
],
),
),
);
}
How will i add it here
Widget buildTextField(String hintText, String labelText, bool isName,
bool isPassword, bool isEmail) {
return Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Column(
children: [
TextFormField(
controller: ,
autocorrect: isAutoCorrect,
obscureText: isPassword,
CodePudding user response:
Add different controller to each textfield, u can pass controller as parameter to buildTextField method
var nameController = TextEditingController();
...
buildTextField( "xpresschop", "Name", true, false, false, nameController)
...
then your widget would be:
Widget buildTextField(String hintText, String labelText, bool isName,
bool isPassword, bool isEmail, TextEditingController myController) {
return
......
TextFormField(
controller:myController ,
....