首页 > 解决方案 > i have an error : 'List>' is not a subtype of type 'List'

问题描述

I'm working on a flutter project where I pass an array of objects (List> array) to the stream-builder from my bloc. If I print the object, it prints nicely, but when I try to map them out in the DropdownMenuItem, it throws me the mentioned error. Hence, if I create a dummy array in the same format within the class and access it, I do not get the error. I'm not sure what I am missing here.

Expanded(
          child: Padding(
            padding: const EdgeInsets.all(5.0),
            child: DropDownField(
              controller: _idpatientController,
              items: data.map<DropdownMenuItem<String>>((list) {
                return  DropdownMenuItem<String>(
                  child: Text(
                      list['nom_patient'] + " " + list['prenom_patient']),
                  value: list['id_patient'],
                );
              }).toList(),
              value: selectedName,
              onValueChanged: (value) {
                setState(() {
                  selectedName = value;
                  print(value);
                });
              },
            ),
          ),
        )

标签: flutterdart

解决方案


尝试这个 :

    items: <String>['A', 'B', 'C', 'D'].map((String value) {
    return new DropdownMenuItem<String>(
      value: value,
      child: new Text(value),
    );
  }).toList(),

推荐阅读