我如何将数据从flift中的textformfield中保存为Cloud Firebase的数字

时间:2018-08-08 13:00:33

标签: firebase google-cloud-platform flutter

我的表单包含一些textformfield,其中一个字段是要保存为数字而不是字符串的价格。.下面是我的Textformfield代码

 new TextFormField(
                      keyboardType: TextInputType.number,
                      style: new TextStyle(fontFamily: "ChelaOne-Regular",
                          color: Colors.white,
                          fontSize: 20.0),
                      decoration: new InputDecoration(
                          labelText: "Price",
                          labelStyle: new TextStyle(
                              fontFamily: "ChelaOne-Regular",
                              color: Colors.white),
                          hintText: "Please enter Price ",
                          hintStyle: new TextStyle(
                              fontFamily: "ChelaOne-Regular",
                              color: Colors.white,
                              fontSize: 15.0)),
                      validator: (val) =>
                      val.isEmpty
                          ? 'Please enter Discribtion'
                          : null,
                        onSaved: (val) => price = val,
                    ),

我保存数据的代码是

Firestore.instance.collection('item').document().setData({
        "Discribtion": discribtion,
        "Title": title,
        "price":price,

      });
      Done();
      Navigator.pop(context);
    }
  }

其中price是一个数字(数字价格;) 请帮助我

1 个答案:

答案 0 :(得分:0)

String numString = '3';
int numInt = int.parse(numString);

所以您将执行以下操作:

Firestore.instance.collection('item').document().setData({
        "Discribtion": discribtion,
        "Title": title,
        "price":int.parse(price),

      });