How to display data from API to flutter Multi Select Form Field

I am using this Package for the Multi-Select form Field in Flutter. In this Package already defined data source like

datasource: [
{
“display”: “Running”,
“value”: “Running”,
},
{
“display”: “Climbing”,
“value”: “Climbing”,
},
{
“display”: “Walking”,
“value”: “Walking”,
},
],

My Problem is How add Data Source from API into Flutter
My API response
{
“Data”: [
{
“name”: “Person 1”
},
{
“name”: “Person 2”
},
{
“name”: “Person 3”
},
{
“name”: “Person 4”
}
]
}

As you can see the required format for data source, so you will have to parse your API and convert it into the required format. You should do this ideally in the backend itself. But if you want the value to be same as name then you can handle it on the Front End.

So let’s say your response is in the variable List<Map<String, String>> data; Then you can parse the list and convert your array.

data.map(item => {display: item.name, value: item.name})

This is pseudo-code, you can look up the exact syntax of map in dart. Hope this is helpful :slight_smile: