Flutter 如何重置我的应用程序并重置此应用程序的当前状态
请问,如何重置我的Flutter 如何重置我的应用程序并重置此应用程序的当前状态,flutter,dart,Flutter,Dart,请问,如何重置我的currentstate导航器,以便当用户在文本字段中键入时,错误消息将消失,而不是保留,直到他们点击提交按钮。我知道这是使用了unChanged函数,但我真的搞不懂 请帮忙。我也在下面附上了我的代码 多谢各位 类ForgotPwd扩展StatefulWidget{ @凌驾 _ForgotPwdState createState()=>_ForgotPwdState(); } 类_ForgotPwdState扩展状态{ 最终文本编辑控制器_popEditingControll
currentstate
导航器,以便当用户在文本字段中键入时,错误消息将消失,而不是保留,直到他们点击提交按钮。我知道这是使用了unChanged
函数,但我真的搞不懂
请帮忙。我也在下面附上了我的代码
多谢各位
类ForgotPwd扩展StatefulWidget{
@凌驾
_ForgotPwdState createState()=>_ForgotPwdState();
}
类_ForgotPwdState扩展状态{
最终文本编辑控制器_popEditingController=文本编辑控制器();
final _formKey=GlobalKey();
@凌驾
小部件构建(构建上下文){
返回对话框(
子:堆栈(
儿童:[
容器(
身高:270.0,
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:borderRadius.all(
圆形半径(10.0),
),
),
孩子:填充(
填充:仅限边缘设置(顶部:40.0),
孩子:表格(
键:_formKey,
子项:列(子项:[
正文(
“忘记密码了吗?”,
样式:TextStyle(
fontFamily:“无需工作”,
字体大小:18.0,
颜色:颜色(0XFF25282B),
fontWeight:fontWeight.w600),
),
填充物(
衬垫:
仅限边缘设置(左:20.0,右:20.0,顶:30.0),
子项:TextFormField(
验证器:(值){
if(value.isEmpty==true){
返回“请输入电子邮件地址”;
}否则{
返回null;
}
},
控制器:_popEditingController,
键盘类型:TextInputType.emailAddress,
装饰:输入装饰(
前缀:图标(FontAwesomeIcons.envelope),
标签样式:文本样式(字体大小:15.0),
hintText:'输入您的电子邮件地址',
hintStyle:TextStyle(fontSize:15.0),
边框:下划线输入边框(
borderSide:borderSide(颜色:Colors.black)),
),
),
填充物(
填充:所有边缘设置(30.0),
孩子:升起按钮(
形状:圆形矩形边框(
边界半径:新的边界半径。圆形(10.0)),
颜色:颜色(0XFFC20370),
已按下:(){
设置状态(){
if(_formKey.currentState.validate()){
导航器(上下文)
.pop(_popEditingController.text.toString());
}
});
},
子项:文本('SUBMIT',
样式:TextStyle(
颜色:颜色,白色,
fontFamily:“无需工作”,
字体大小:18.0,
fontWeight:fontWeight.w600),
))
]),
),
),
),
],
),
);
}
}
您可以在文本字段的onChanged
方法中调用\u formKey.currentState.validate()
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)),
))
]),
),
),
),
],
),
);
}
}