0

This is the code i have written but facing some error like "cant use String in getOptions()"

 totalClasses = await FirebaseFirestore.instance .collection('tutors') .doc(uid) .get("TotalClassesTook") .then((value) { return value.data(); }); 

How to retrieve the TotalClassesTook field value from this doc Error image

2
  • Where in your code are you using getOptions ? Commented May 22, 2021 at 16:01
  • @NisanthReddy ,Now I have attached the error image please check it once. Commented May 22, 2021 at 17:32

2 Answers 2

2

While using the FirebaseFirestore.instance to get your data, the .get() is for specifying the GetOptions with feature like cache.

But that is not what you require.

Use it like this,

totalClasses = await FirebaseFirestore.instance .collection('tutors') .doc(uid) .get() .then((value) { return value.data()['TotalClassesTook']; // Access your after your get the data }); 
Sign up to request clarification or add additional context in comments.

Comments

2

For me the Nishanth's answer was not working, so this one worked for me.

FirebaseFirestore.instance .collection('tutors') .doc(uid) .get() .then((value) { print(value.get('TotalClassesTook')); }); 

Or this:

FirebaseFirestore.instance .collection('tutors') .doc(uid) .get() .then((value) { Map data = value.data() as Map; print(data['TotalClassesTook']); }); 

Both of them worked for me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.