Closed mohdtaha60 closed 3 years ago
Hey @mohdtaha60. You will have to manually cast the data from the documentSnapshot (which is of Map type). Check this below example to get an idea.
itemBuilder: (index, context, documentSnapshot) {
final data = documentSnapshot.data();
final product = Product(
id: data['id'],
name: data['name'],
quantity: data['quantity'],
);
return ListTile(
leading: CircleAvatar(child: Icon(Icons.person)),
title: Text(product.name),
subtitle: Text(product.quantity),
);
},
Feel free to reopen the issue if you face any related issue. Thanks for using the package 🎉
Hey @mohdtaha60. You will have to manually cast the data from the documentSnapshot (which is of Map type). Check this below example to get an idea.
itemBuilder: (index, context, documentSnapshot) { final data = documentSnapshot.data(); final product = Product( id: data['id'], name: data['name'], quantity: data['quantity'], ); return ListTile( leading: CircleAvatar(child: Icon(Icons.person)), title: Text(product.name), subtitle: Text(product.quantity), ); },
Thanks alottt dude, it helped me alot.
Thank you for this amazing library. Just wanna know what is the proper method to cast documentSnapshot to my Model i.e Product. tried this inside item itemBuilder, but doesn't work.
Product products =documentSnapshot.data() as Product;
Error is _InternalLinkedHashMap<String, dynamic>' is not a subtype of type documentSnapshot.data. Update: Ok, seems am doing it wrong. Can anyone help me mapping the snapshot data to an object