预期为类型'List <DropdownMenuItem <Color >>'的值,但得到类型为'MappedListIterable <Color,DropdownMenuItem <Color >>'的值

时间:2020-01-17 17:12:17

标签: flutter dart

我正在尝试从dropdownmenu更改themeColor,但收到此错误:“预期类型为'List>'的值,但类型为之一 'MappedListIterable>'

Color  selected ;

MaterialApp(
      theme: ThemeData(primarySwatch: selected),
      home: Scaffold();

 List myColor = [
    Colors.amber,
    Colors.blue,
    Colors.green,
    Colors.black,
  ];

 DropdownButton(
              icon: Icon(Icons.arrow_downward),
              value: selected,
              onChanged: (value){
                setState(() {
                  selected = value;
                });
              },
              items: myColor.map((value)=>DropdownMenuItem(
                value: value,
                child: Text(value.toString()),
              ))
            ),

0 个答案:

没有答案