After migrating to null safety, I'm getting the error: The argument type 'Object?' can't be assigned to the parameter type 'DocumentSnapshot<Object?>'. Thanks for helping out.
FutureBuilder(
future: usersReference
.doc(sublist[i].ownerId)
.get(),
builder: (context, snap) {
if (!snap.hasData) {
return loader();
}
UserModel user =
UserModel.fromDocument(snap.data);//error line
//tried snap.data(), snap.data!
return Container();
);
This the UserModel
class UserModel {
String id;
String username;
String url;
UserModel(
{
required this.id,
required this.username,
required this.url,
});
factory UserModel.fromDocument(DocumentSnapshot doc) {
return UserModel(
id: doc.id,
username: doc.get('username') ?? "",
url: doc.get('url') ?? "",
);
}
}
CodePudding user response:
Try to adding type cast if u have to make sure it type.
CodePudding user response:
Did you try to cast it?
FutureBuilder<DocumentSnapshot>(
future: usersReference
.doc(sublist[i].ownerId)
.get(),
builder: (BuildContext context, DocumentSnapshot snapshot) {
if (!snapshot.hasData) {
return loader();
}
UserModel user = UserModel.fromDocument(snap.data);
return Container();
}
);