Home > Blockchain >  how to extract value from one list and store into another list in flutter
how to extract value from one list and store into another list in flutter

Time:07-31

I ran into an issue with flutter. I want to fetch all url value from a List and store into another list..

const List series = [
{
"title": "The Moth",
"publisher": "THE MOTH",
"cover":"imgurl",

"seriesurllists": [
{
"title": "book 1",
"url":"https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3"
},
{
"title": "book 2",
"url":"https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3",
},
{
"title": "book 3",
"url":"https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3",
  },
]

}, ];

into

 List<String> allAudio = [
'https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3,
'https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3',
'https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3'

];

CodePudding user response:

  List<String?> allAudio = (series[0]["seriesurllists"] as List<Map<String, String>>).map((e) => e["url"]).toList();

CodePudding user response:

You can try this if you have more than one series.

for(var element in series){
 List<String> allAudio = (element["seriesurllists"] as List<Map<String, String>>).map((e) => e["url"]).toList();
}
  • Related