i want to store the field value course name and use it further,
i tried this but it didnt work giving error as
Unhandled Exception: Bad state: cannot get a field on a
DocumentSnapshotPlatform which does not exist
print(widget.scourse);
DocumentSnapshot dsa = await FirebaseFirestore.instance
.collection("users")
.doc("$widget.scourse")
.get();
print(dsa.get('courseName'));
// final studentsc=course.toString().toLowerCase().split(" ").join() +"student";
}
widget.scourse is the document name
this is the code i had written pl help
2
Answers
Here you missed the curly brackets so .scourses was sent as string instead of its value
If all things are working (with your database, setup, etc.), there seems to be an issue with the doc id in your code.
When you want to access a variable in a string, putting a dollar sign in front of it is okay. But when you want to do any computation or complex variable access (like you are doing), you have to wrap the computation in curly braces.
The following code should explain what I mean:
Now coming over to the code you shared, you mentioned that widget.scourse is the document name (I suppose id here). Accessing it inside the .doc method, you should use the braces like I explained above. Something, like the following:
Or better still, since widget.scourse is a string already, you don’t need to put it inside quotes again (and access it with dollar sign), you simply use it directly.