Let’s say i have this List of maps :
List values = [
{
'icon': FontAwesomeIcons.book,
'title': 'A',
'books': [
{'author': 'Max', 'age': 30},
{'author': 'Dani', 'age': 45}
]
},
{
'icon': FontAwesomeIcons.book,
'title': 'B',
'books': [],
}
];
How to check if this book exists to where the title ‘A’ {'author': 'Steve', 'age': 28},
and if it doesn’t exists how to add it.
Edit:
The result i want to reach is :
List values = [
{
'icon': FontAwesomeIcons.book,
'title': 'A',
'books': [
{'author': 'Max', 'age': 30},
{'author': 'Dani', 'age': 45},
{'author': 'Steve', 'age': 28}
]
},
{
'icon': FontAwesomeIcons.book,
'title': 'B',
'books': [],
}
];
3
Answers
You can use
.firstWhere
to find item, likeI strongly recommend using Data Models. it will make your work easier.
When using this model, you can easily convert and edit your data: