Flutter:循环下拉列表未显示所选值

问题描述 投票:1回答:1

我正在for循环中重复一个内部具有下拉菜单的小部件。但是,当我单击时未显示所选值时。有人以前曾经按下过下拉按钮吗?这是我到目前为止的代码。它放置在for循环中。

child: new DropdownButton(

                value: _relationSelects[i],
                hint: Text("Select Category"),
                items: _relationschoice.map((String value) {
                return new DropdownMenuItem<String>(
                value: value,
                  child: new Text(value.toString()),
                );
                }).toList(),
                onChanged: (String value) {
                  setState(() {
                    _relationSelects[i] = value;      // Problem here too, the element doesn’t show in the dropdown as selected
                    print("Selected: ${_relationSelects[i]} (${i})");
                  });
                },


              ),

它可以打印所选值。但它并没有改变状态。

如果我使用String代替List-String作为值,则它可以为所有循环的下拉列表显示相同的选定值,这是不正确的。

我之前已经检查过此答案,但仍无法正常工作Can't show the dropdown selected value in Flutter

有人可以请教吗?谢谢。

android mobile flutter dropdown hybrid-mobile-app
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.