Answers for "'List<dynamic>' to 'List<DropdownMenuItem<String>>?'. flutter"

0

'List<dynamic>' to 'List<DropdownMenuItem<String>>?'. flutter

// List with fields to be displayed in dropdown
final List itemsList
DropdownButton<String>(
        value: selectedItem,
        icon: const Icon(Icons.arrow_downward),
        iconSize: 24,
        elevation: 16,
        style: const TextStyle(color: Colors.deepPurple),
        underline: Container(
          height: 2,
          color: Colors.deepPurpleAccent,
        ),
        onChanged: (String? newValue) {
          // call event with select value
        },
        items: convertList())
        
// Converting List to List<DropdownMenuItem<String>>
List<DropdownMenuItem<String>> convertList() {
    List<DropdownMenuItem<String>> list = [];
    for (var item in itemsList) {
      list.add(DropdownMenuItem(
        child: Text(item),
        value: item,
      ));
    }

    return list;
  }
Posted by: Guest on September-05-2021

Code answers related to "'List<dynamic>' to 'List<DropdownMenuItem<String>>?'. flutter"

Browse Popular Code Answers by Language