【问题标题】:i have an error : 'List<DropdownMenuItem<String>>' is not a subtype of type 'List<String>'我有一个错误:“List<DropdownMenuItem<String>>”不是“List<String>”类型的子类型
【发布时间】:2020-12-12 08:05:15
【问题描述】:

我正在做一个颤振项目,我将一个对象数组(List> 数组)从我的块传递给流构建器。如果我打印该对象,它会打印得很好,但是当我尝试将它们映射到DropdownMenuItem 时,它会抛出我提到的错误。因此,如果我在类中创建一个相同格式的虚拟数组并访问它,我不会收到错误消息。我不确定我在这里缺少什么。

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);
                });
              },
            ),
          ),
        )

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 2019-06-26
      • 2022-12-02
      • 2020-12-04
      • 1970-01-01
      • 2021-05-10
      • 2021-07-17
      相关资源
      最近更新 更多