Flutter:按键查找文本小部件

问题描述

我正在生成包含下拉按钮、文本字段和文本小部件的行。

for(int i = 0; i < listZutaten.length; i++)
                  new Visibility(
                      visible: true,child: new Row(
                      children: [
                        new Container(
                          width: (MediaQuery.of(context).size.width / 2) - 10,height: 65.0,child: new DropdownButton<String>(
                              isExpanded: true,value: stringDropDownButtonList[i],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(() {
                                  stringDropDownButtonList[i] = wert;
                                  print(stringDropDownButtonList[i]);
                                  index = listZutaten.indexOf(stringDropDownButtonList[i].toString());
                                  print("index: $index");
                                });
                              },items: listZutaten.map((String value) {
                                return DropdownMenuItem<String>(
                                  value: value,child: new Text(value),);
                              }).toList(),new Container(
                          width: 100.0,child: new Padding(
                            padding: const EdgeInsets.only(left: 15.0),child: new TextField(
                                controller: eiweiss,keyboardType: TextInputType.number,textAlign: TextAlign.center,decoration: Inputdecoration(
                                  enabledBorder: UnderlineInputBorder(),hintText: 'Menge',new Container(  
                          width: 75.0,child: new Text(
                            listEinheiten[index].toString(),key: new Key(i.toString()),]
                    ),)

只要我在下拉列表中选择了一个值,我就希望同一行中的文本小部件更新。

现在,每个文本小部件都会更新。

通过研究,我发现有一种像 find.byKey 这样的方法,但这似乎只适用于测试环境,一旦应用程序进入应用程序商店,这种情况就不再适用了。

那么,您知道如何更新同一行中的文本小部件而不是分配的每个文本小部件吗?

期待您的回复

悟空

解决方法

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

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

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