首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DropdownButton失败

DropdownButton失败
EN

Stack Overflow用户
提问于 2022-01-22 23:10:48
回答 1查看 25关注 0票数 0

我有以下DropdownButton小部件:

代码语言:javascript
复制
Center(
              child: DropdownButton<dynamic>(
                value: selectedTipoInterno,
                items: dataTiposInt.map(
                  (list) {
                    return DropdownMenuItem(
                      child: Text(list['tipo_int']),
                      value: list['id'],
                    );
                  },
                ).toList(),
                onChanged: (value) {
                  setState(() {});
                },
              ),
            )

这里有dataTiposInt的值:

代码语言:javascript
复制
[{"id":"1","tipo_int":"Administrador"},{"id":"2","tipo_int":"Editor"},{"id":"3","tipo_int":"Supervisor"},{"id":"4","tipo_int":"Analista"},{"id":"5","tipo_int":"Colaborador"}]

我得到以下错误输出:

代码语言:javascript
复制
There should be exactly one item with [DropdownButton]'s value: Administrador. 
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 894 pos 15: 'items == null || items.isEmpty || value == null ||
              items.where((DropdownMenuItem<T> item) {
                return item.value == value;
              }).length == 1'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-22 23:20:03

我希望我能做一点评论,但还没有足够的声誉。

在您的代码中,datatiposInt的值是这样写的吗?或者它是生成的?如果是后者,那么查看代码也是有帮助的。

另外,我猜您的selectedTipoInterno不是字符串类型的,所以我想知道这是否会抛出下拉列表。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70817897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档