简体   繁体   English

如何用 Flutter 中 api 的数据填充 FindDropdown?

[英]How to fill a FindDropdown with data from api in Flutter?

im newbie with flutter and i'm trying to fill this FindDropdown that i found with the data i get from api.我是 flutter 的新手,我正在尝试用从 api 获得的数据来填充我发现的 FindDropdown。

FindDropdown(
                        searchBoxDecoration: InputDecoration(
                            hintText: "Buscar",
                            border: OutlineInputBorder(
                              borderSide:
                                  new BorderSide(color: Constants.blackAudi),
                            )),
                        label: "Seleccione el Taller:",
                        labelVisible: true,
                        items: [_.talleres[0].nombre],
                        onChanged: (item) {
                          print(item);
                          countriesKey.currentState
                              ?.setSelectedItem(<String>[]);
                        },
                        showSearchBox: true,
                        showClearButton: true,
                        
                        titleStyle: TextStyle(color: Constants.blackAudi),
                      ),

As you can see in the items: part im using the call to my method, however i am only calling the first item and i need to get all of them.正如您在项目中看到的那样:我使用了对我的方法的调用,但是我只调用了第一个项目,我需要获取所有这些项目。

EDIT: tried using _.talleres.map((e) => e.nombre).toList()编辑:尝试使用 _.talleres.map((e) => e.nombre).toList()

but didnt worked either:(但也没有工作:(

i got this:我懂了:

在此处输入图像描述

I appreciate any help you can give:)感谢您提供的任何帮助:)

Edit-1:编辑-1:

FindDropdown takes a builder if your list is not predefined you can use that builder to build up your list. FindDropdown 需要一个构建器,如果您的列表未预定义,您可以使用该构建器来构建您的列表。 you can find an example here你可以在这里找到一个例子

You can try the map function to get all the values and then convert it into a list, as shown below.您可以尝试使用map function 获取所有值,然后将其转换为列表,如下所示。

items: _.talleres.map( (e) => e.nombre ).toList()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM