I want to transfer passcontroller data from password widget to passwordrep widget to compare them in the passwordrep Widget but it doesn't transfer the text that I input.I don't know if it's the problem because of the variables or the Widget type. Pls help.
password Widget:
TextFormField passwordrep(TextEditingController passrepcontroller, bool isObscure) {
TextEditingController passcontroller = new TextEditingController();
password(passcontroller, true);
return TextFormField(
controller: passrepcontroller,
obscureText: isObscure,
onSaved: (value) {
passrepcontroller.text = value!;
},
validator: (value) {
RegExp regex = RegExp(r'^.{8,}$');
if (value!.isEmpty) {
return "Please repeat the password";
}
if (!regex.hasMatch(value) || value != passcontroller.text) {
return 'Passwords don\'t match';
}
return null;
},
decoration: const InputDecoration(
fillColor: Colors.white70,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(15.0),
),
borderSide: BorderSide(color: Colors.black),
),
contentPadding: EdgeInsets.symmetric(vertical: 15.0),
hintText: "Repeat Password",
prefixIcon: Icon(
Icons.lock_outline,
color: Colors.black,
),
));
}
passwordrep Widget:
TextFormField passwordrep(TextEditingController passrepcontroller, bool isObscure) {
TextEditingController passcontroller = new TextEditingController();
password(passcontroller, true);
return TextFormField(
controller: passrepcontroller,
obscureText: isObscure,
onSaved: (value) {
passrepcontroller.text = value!;
},
validator: (value) {
RegExp regex = RegExp(r'^.{8,}$');
if (value!.isEmpty) {
return "Please repeat the password";
}
if (!regex.hasMatch(value) || value != passcontroller.text) {
return 'Passwords don\'t match';
}
return null;
},
decoration: const InputDecoration(
fillColor: Colors.white70,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(15.0),
),
borderSide: BorderSide(color: Colors.black),
),
contentPadding: EdgeInsets.symmetric(vertical: 15.0),
hintText: "Repeat Password",
prefixIcon: Icon(
Icons.lock_outline,
color: Colors.black,
),
));
}
I've tried converting the widgets to statefull widgets but it also doesn't work.