My FirebaseFirestore looks like the below image
My code snipped for deserialization is as below:
class StripeProductPlan extends Equatable {
final DocumentReference selfRef;
final Map<String, String> metaData;
final String name;
final String? role;
final String? taxCode;
const StripeProductPlan({
required this.selfRef,
required this.metaData,
required this.name,
this.role,
this.taxCode,
});
factory StripeProductPlan.fromSnapshot(
DocumentSnapshot<Map<String, dynamic>> snapshot) {
final data = snapshot.data()!;
return StripeProductPlan(
metaData: data['metaData'] as Map<String, String>,
selfRef: snapshot.reference,
name: data['name'] as String,
role: data['role'] as String? ?? '',
taxCode: data['taxCode'] as String? ?? '',
);
}
Everything else works, except for the metaData deserialization. How do I fix this?
1
Answers
I see in your screenshot:
That your Map field is called
medatadata
while in your class is calledmetaData
, which is not correct. The field names must match. See the difference, the field in the database starts with a lowercase letterd
while in the class starts with capital letterD.
To solve thisin the simplest way possible, please change the name of the field in the class to match the one in the database: