gpt4 book ai didi

flutter - 如何重置我的重置此应用程序的当前状态

转载 作者:行者123 更新时间:2023-12-03 03:03:28 25 4
gpt4 key购买 nike

请,我如何重置我的currentstate Navigator,这样当用户在文本字段中键入内容时,错误消息就会消失而不是消失,直到他们点击“提交”按钮为止。我知道这是unChanged函数的使用,但我真的无法弄清楚。
请帮忙。我还在下面附加了我的代码。
谢谢。
enter image description here

class ForgotPwd extends StatefulWidget {
@override
_ForgotPwdState createState() => _ForgotPwdState();
}

class _ForgotPwdState extends State<ForgotPwd> {
final TextEditingController _popEditingController = TextEditingController();

final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Dialog(
child: Stack(
children: [
Container(
height: 270.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
),
child: Padding(
padding: EdgeInsets.only(top: 40.0),
child: Form(
key: _formKey,
child: Column(children: [
Text(
'Forgot Password?',
style: TextStyle(
fontFamily: 'Work Sans',
fontSize: 18.0,
color: Color(0XFF25282B),
fontWeight: FontWeight.w600),
),
Padding(
padding:
EdgeInsets.only(left: 20.0, right: 20.0, top: 30.0),
child: TextFormField(
validator: (value) {
if (value.isEmpty == true) {
return 'Please enter email address';
} else {
return null;
}
},
controller: _popEditingController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
prefixIcon: Icon(FontAwesomeIcons.envelope),
labelStyle: TextStyle(fontSize: 15.0),
hintText: 'Enter your email address',
hintStyle: TextStyle(fontSize: 15.0),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.black))),
),
),
Padding(
padding: EdgeInsets.all(30.0),
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(10.0)),
color: Color(0XFFC20370),
onPressed: () {
setState(() {
if (_formKey.currentState.validate()) {
Navigator.of(context)
.pop(_popEditingController.text.toString());
}
});
},
child: Text('SUBMIT',
style: TextStyle(
color: Colors.white,
fontFamily: 'Work Sans',
fontSize: 18.0,
fontWeight: FontWeight.w600)),
))
]),
),
),
),
],
),
);
}
}

最佳答案

您可以在文本字段的_formKey.currentState.validate()方法中调用onChanged

关于flutter - 如何重置我的重置此应用程序的当前状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64553761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com