![](/img/trans.png)
[英]MVC hiding/showing a partial view with a form on another form, save issue
[英]flutter form save issue
下面的代码工作正常,我单击平面按钮,然后弹出警报对话框。 问题:1)但是,如果我添加form.save,它将显示错误
flutter:处理手势时引发了以下NoSuchMethodError:flutter:在null上调用了setter'clientName ='。 颤动:接收方:空颤动:尝试调用:clientName =“ 423”
2)如何获得文本输入值,例如:clientName..etc 我总是空的。 请帮助。
class _formState extends State<form> {
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
Booking booking;
@override
Widget build(BuildContext context) {
final getCourse = widget.course;
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
//title: Text('${widget.course.title}\n地址: ${widget.course.address}\nTEL: ${widget.course.tel}'),
title: Text('即日訂位'),
),
body: Container(
child: Form(
key: formKey,
child: ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.person_outline),
title: TextFormField(
initialValue: "",
onSaved: (val) => booking.clientName = val,
validator: (val) => val == "" ? val : null,
decoration: new InputDecoration(
labelText: "Name",
),
),
),
//Send or Post button
FlatButton(
textColor: Colors.blueAccent,
child: Text("OK"),
color: Colors.transparent,
onPressed: () {
_showFormDialog();
SystemChannels.textInput.invokeMethod('TextInput.hide');
},
)
],
),
),
),
);
}
void _showFormDialog() {
final FormState form = formKey.currentState;
if (form.validate()) {
//form.save();
var alert = new AlertDialog(
content: new Row(
children: <Widget>[
Text("hihi")
],
),
actions: <Widget>[
new FlatButton(
onPressed: () {
form.reset();
Navigator.pop(context);
},
child: Text("ok")),
new FlatButton(onPressed: () => Navigator.pop(context),
child: Text("cancel"))
],
);
showDialog(context: context,
builder: (_) {
return alert;
});
}
else {
var alert = new AlertDialog(
content:
new Row(
children: <Widget>[
Text("error!")
],
),
actions: <Widget>[
new FlatButton(onPressed: () => Navigator.pop(context),
child: Text("OK"))
],
);
showDialog(context: context,
builder: (_) {
return alert;
});
}
}
}
您必须先初始化您的Booking
对象,尝试以下操作:
Booking booking = new Booking();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.