I’m trying to print a specific users info from firebase, but whenever I try to call the specific value, such as name, it always comes up as the error, Too many positional arguments: 0 expected, but 1 found.
getUserState() async{
String temp;
final FirebaseAuth auth = FirebaseAuth.instance;
final String id = FirebaseFirestore.instance.collection('users').id;
FirebaseFirestore.instance.collection('users').doc(id).get().then((value){
temp = value.data('name') as String;
});
4
Answers
data
is a method that takes no parameter and returns aMap
Try this:
To print an specific user information from Firebase calling by a value such as name, you can use the Firebase Database Query API. You can use the orderByChild() method to query the database and retrieve data based on a specific value. For example, if you want to print an user information from Firebase calling by name, you can use the following code:
You can use
.get
to read mapIf you need a function that returns a String that contains the name you can refactor your code like the following:
user: is a Map<String, dynamic> representation of your document in collection. You can use it to covert in your model with fromJson for example.
If any users found with provided id it returns null