how can I save data to cloud firebase as number from textformfield in flutter

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how can I save data to cloud firebase as number from textformfield in flutter



I form which contain some textformfield in which one field is price which i want to save as number not string ..below is my code of 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,
),



my code to save data is


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

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



where price is a num(num price;)
please help me in this




1 Answer
1


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



So you would do something like this:


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

);





thanks its working
– Hitanshu Gogoi
Aug 8 at 13:20






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS