【问题标题】:how can I save data to cloud firebase as number from textformfield in flutter如何在颤动中将数据作为文本表单字段中的数字保存到云 Firebase
【发布时间】:2018-08-08 13:00:32
【问题描述】:

我的表单包含一些 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);
    }
  }

其中价格是一个数字(num price;) 请在这方面帮助我

【问题讨论】:

    标签: firebase google-cloud-platform flutter


    【解决方案1】:
    String numString = '3';
    int numInt = int.parse(numString);
    

    所以你会做这样的事情:

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

    【讨论】:

      猜你喜欢
      • 2020-11-16
      • 2021-09-26
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多