CardData.fromJson constructor
Parses a CardData object from a JSON map.
Example:
Map<String, dynamic> jsonData = {
"id": "card_1",
"brand": "Visa",
"last_4": "1234",
"exp_year": "2026",
"exp_month": "12",
"name": "John Doe",
"address_zip": "12345"
};
CardData cardData = CardData.fromJson(jsonData);
Implementation
factory CardData.fromJson(Map<String, dynamic> json) {
return CardData(
id: json['id'],
brand: json['brand'],
last4: json['last_4'],
expYear: json['exp_year'].toString(),
expMonth: json['exp_month'].toString(),
name: json['name'],
addressZip: json['address_zip'], // Can be null
);
}