Flutter:如何将动态列表添加到下拉列表?编辑#2

Flutter : How to add dynamic list to Dropdown ? Edited #2

我有从上一页收到的列表,想把它放在下拉菜单中,该列表包含很多项目:

List myItems = [];
getItem() {
  categories.forEach((item) {
    print(item.name); //----------the print result is correct
    myItems.add(item.name);
  });
  return myItems;
}

我把它放在下拉菜单中:

 DropdownButton(
                        onChanged: (v) {
                          _selected = prod.get_cat(v);
                        },
                        elevation: 16,
                        style: TextStyle(
                            color: Colors.black,
                            fontWeight: FontWeight.bold,
                            fontSize: 22),
                        underline: SizedBox(),
                        value: _selected,
                        items:
                            getItem().map<DropdownMenuItem<String>>((value) {
                          return DropdownMenuItem<String>(
                            value: value[id],
                            child: Center(child: Text(value[name])),
                          );
                        }).toList(),
                      )

提供商的价值变化:

get_cat(id) {
    _selectedValue = id;
    return _selectedValue;
  }

我收到错误:

A non-null String must be provided to a Text widget. 'package:flutter/src/widgets/text.dart': Failed assertion: line 370 pos 10: 'data != null'

我该如何解决这个问题?

标识符应该是字符串。

value: value['id'],
child: Center(child: Text(value['name'])),