下面的代码运行良好,我单击平面按钮和警报对话框弹出。
颤振:在处理
颤振:接收器:空颤振:尝试调用:clientName=“423”
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;
});
}
}
}