我想将passcontroller数据从密码小工具传输到passwordrep小工具,以便在passwordrep小工具中进行比较,但它不传输我输入的文本。我不知道是变量还是小工具类型的问题。请帮助。
密码小工具:
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,
),
));
}
密码报告小工具:
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,
),
));
}
我试过将小部件转换为有状态的小部件,但也不起作用。
1条答案
按热度按时间ua4mk5z41#
为密码和repeatPassword制作2个文本控制器
将每个
TextEditingController
传递到所需的TextFormField
使用
text
属性_passwordController.text
,该属性包含用户输入的文本完整示例