I am following a video on youtube of Flutter UI, In which the tutor is mapping JSON-like data to a more specific custom-made object class but doing the same is throwing errors to me. Might be because of the new Dart version?. Can someone clear the mapping concept to me as I have no idea and also how to fix this error?
Errors:
class CardModel {
String user;
String cardNumber;
String cardExpired;
String cardType;
int cardBackground;
String cardElementTop;
String cardElementBottom;
CardModel(this.user, this.cardNumber, this.cardExpired, this.cardType,
this.cardBackground, this.cardElementTop, this.cardElementBottom);
}
List<CardModel> cards = cardData
.map(
(item) => CardModel(
item['user'],
item['cardNumber'],
item['cardExpired'],
item['cardType'],
item['cardBackground'].,
item['cardElementTop'],
item['cardElementBottom'],
),
)
.toList();
var cardData = [
{
"user": "Amanda Alex",
"cardNumber": "**** **** **** 1425",
"cardExpired": "03-01-2023",
"cardType": "assets/images/mastercard_logo.png",
"cardBackground": 0xFF1E1E99,
"cardElementTop": "assets/svg/ellipse_top_pink.svg",
"cardElementBottom": "assets/svg/ellipse_bottom_pink.svg"
},
{
"user": "Amanda Alex",
"cardNumber": "**** **** **** 8287",
"cardExpired": "03-01-2025",
"cardType": "assets/images/mastercard_logo.png",
"cardBackground": 0xFFFF70A3,
"cardElementTop": "assets/svg/ellipse_top_blue.svg",
"cardElementBottom": "assets/svg/ellipse_bottom_blue.svg"
}
];
Second File
class OperationModel {
String name;
String selectedIcon;
String unselectedIcon;
OperationModel(this.name, this.selectedIcon, this.unselectedIcon);
}
List<OperationModel> datas = operationsData
.map((item) => OperationModel(
item['name'], item['selectedIcon'], item['unselectedIcon']))
.toList();
List<Map<String, dynamic>> operationsData = [
{
"name": "Money\nTransfer",
"selectedIcon": "assets/svg/money_transfer_white.svg",
"unselectedIcon": "assets/svg/money_transfer_blue.svg"
},
{
"name": "Bank\nWithdraw",
"selectedIcon": "assets/svg/bank_withdraw_white.svg",
"unselectedIcon": "assets/svg/bank_withdraw_blue.svg"
},
{
"name": "Insight\nTracking",
"selectedIcon": "assets/svg/insight_tracking_white.svg",
"unselectedIcon": "assets/svg/insight_tracking_blue.svg"
},
];
Here in this second file when I changed map as <String, String> this error occurs but changing <String, dynamic> works fine. But why mentioning string is not working as these all are Strings in operationModel class

