Flutter:动态下拉按钮

问题描述

早上好,

生成 x 个下拉按钮(取决于某个数组的长度)。

如果我想使用提示,它不显示,因为提示仅在属性值的当前值为空时显示

由于我的 rezeptZutatValue(包含要显示的成分的列表)已经拥有所有成分,因此我对如何解决此问题感到困惑。

如果我尝试将空字符串或 null 作为列表中的第一个值传递,我会收到一条错误消息,指出多个下拉按钮字段包含相同的内容(为什么我没有遇到此问题?)。

ListeZutatenEinheit 包含所有应该从一开始就显示的成分,所以我很伤心,如果它甚至可能与天气无关我是否使用列表作为值,因为下拉按钮仍然只显示一个值?

所以,我希望你们能给我的黑暗带来一点光。到目前为止解决了我的其余问题,只是想弄清楚如何动态显示提示(对于我在 for 循环中生成的所有下拉按钮字段)。

new DropdownButton<String>(
                              value: rezeptZutatValue[i].toString(),isExpanded: true,icon: const Icon(Icons.arrow_downward),iconSize: 24,elevation: 16,style: const TextStyle(color: Colors.deepPurple),underline: Container(
                                height: 2,color: Colors.deepPurpleAccent,),onChanged: (String? wert) {
                                setState((){                                      
                                  rezeptZutatValue[i] = wert.toString();

                                  if (rezept["zutat"]![i] != wert.toString()){
                                    rezept["zutat"]![i] = wert.toString();
                                  }

                                  print(rezept["zutat"].toString());
                                });
                              },items: listeZutatenEinheit.map((String value) {                                    
                                return DropdownMenuItem<String>(
                                  value: value,child: new Text(value),);
                              }).toList(),hint: new Text("Zutat auswählen")      
                          )

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)