Mohamed Ghoneim
Mohamed Ghoneim

Reputation: 39

how to fetch data (numbers) in double format from Firestore and multiply them in flutter

So I'm trying to fetch numbers from a specific document and place them in double format and multiply or add the values to each other but first, I need to retrieve them from firestore. my data on firestore For example:

double com ;
double km;
double minute;
double base ;

double total price = com + km + minute + base ;

Upvotes: 0

Views: 974

Answers (2)

Shalabyer
Shalabyer

Reputation: 635

Will, the code will depend on what are the data types of these values on the cloud.. assuming they are already saved as double

 final _fireStore = FirebaseFirestore.instance;
 double base ;
 double com;
 double km ;
 double minute ;

 await _fireStore
          .collection('prices')
          .doc(userID)
          .get()
          .then((DocumentSnapshot snapShot) {
        if (snapShot.exists) {
            base = snapShot.data()['base'];
            com= snapShot.data()['com'];
            km= snapShot.data()['km'];
            minute= snapShot.data()['minute'];
            print('Done Fitching Data From FireStore');
            print(base);
        }
      });

if they are stored as Strings then you will define them as strings at the first 5 lines then you will use

double.parse(com);

Upvotes: 1

Nehry Dedoro
Nehry Dedoro

Reputation: 41

you can use .toDouble(); or double.parse();

Upvotes: 1

Related Questions