i have this function
UserData _userDataFromSnapshot(DocumentSnapshot snapshot) {
return UserData(
uid: uid,
userName: snapshot.data()['userName'],
userEmail: snapshot.data['userEmail'],
phoneNumber: snapshot.data['phoneNb']
);
}
but im getting error on the paranthesis
The operator '[]' isn't defined for the type 'Object'.
updateee for the question
also i have the function and instance of collection
final CollectionReference users = FirebaseFirestore.instance.collection('users');
// get user doc stream
Stream<UserData> get userData {
return users.doc(uid).snapshots()
.map(_userDataFromSnapshot);
}
when i read data:
Widget profile(context, user){
return StreamBuilder<UserData>(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
if(snapshot.hasData){
UserData userData = snapshot.data;
print(userData.userName);
} else print('no data');
}
);
}
what can i do?
im using versions:
Flutter 2.0.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision c5a4b4029c (1 year, 1 month ago) • 2021-03-04 09:47:48 -0800 Engine • revision 40441def69 Tools • Dart 2.12.0