代码之家  ›  专栏  ›  技术社区  ›  GPH

颤振窗体保存问题

  •  0
  • GPH  · 技术社区  · 7 年前

    下面的代码运行良好,我单击平面按钮和警报对话框弹出。

    颤振:在处理 颤振:接收器:空颤振:尝试调用: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;
              });
        }
    
      }
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   diegoveloper    7 年前

    你必须初始化你的 Booking 对象,请尝试以下操作:

     Booking booking = new  Booking();
    
    推荐文章