Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter for循环中的颤振返回小部件_Flutter - Fatal编程技术网

Flutter for循环中的颤振返回小部件

Flutter for循环中的颤振返回小部件,flutter,Flutter,我下面的代码正在运行,但它不是根据列表的长度返回多个小部件,而是在第一轮停止,经过大量的研究和谷歌搜索,我知道它停止了,因为我返回了一个小部件。因此,基本上for循环在到达“return”时停止。 如果我没有在小部件之前添加“return”,它返回的是nothing,或者它给出了一个错误,表示“小部件需要返回类型,但没有返回”。所以没有“我想”我知道这个问题,但我找不到解决办法 @override Widget build(BuildContext context) { for (v

我下面的代码正在运行,但它不是根据列表的长度返回多个小部件,而是在第一轮停止,经过大量的研究和谷歌搜索,我知道它停止了,因为我返回了一个小部件。因此,基本上for循环在到达“return”时停止。 如果我没有在小部件之前添加“return”,它返回的是nothing,或者它给出了一个错误,表示“小部件需要返回类型,但没有返回”。所以没有“我想”我知道这个问题,但我找不到解决办法

@override
  Widget build(BuildContext context) {
    for (var allAttributes in widget.allAttributes) {
      //print(allAttributes.name);
      bool attributeCheck;
      if(widget.attributes.length > 0){
        for(var attributes in widget.attributes){
          if(allAttributes.id == attributes.attributeId){
            return Row(
              children: <Widget>[
                new Container(
                    alignment: Alignment(-1.0, -1.0),
                    child: Padding(
                      padding: const EdgeInsets.only(bottom: 10.0, right: 10.0),
                      child: Text(
                        allAttributes.name + ':',
                        style: TextStyle(
                            color: Colors.black,
                            fontSize: 20,
                            fontWeight: FontWeight.w600),
                      ),
                    )),
                DropdownButton<Attributes>(
                  hint: Text("Select item"),
                  value: selectedUser,
                  onChanged: (Attributes Value) {
                    setState(() {
                      selectedUser = Value;
                    });
                  },
                  items: widget.attributes.map((Attributes attributes) {
                    return DropdownMenuItem<Attributes>(
                      value: attributes,
                      child: Row(
                        children: <Widget>[
                          SizedBox(
                            width: 10,
                          ),
                          Text(
                            attributes.value,
                            style: TextStyle(color: Colors.black),
                          ),
                        ],
                      ),
                    );
                  }).toList(),
                ),
              ],
            );
          }
        }
      }
    }

    return Text('Nothing');
  }
@覆盖
小部件构建(构建上下文){
for(widget.allAttributes中的var allAttributes){
//打印(所有属性.名称);
布尔属性检查;
如果(widget.attributes.length>0){
for(widget.attributes中的var属性){
if(allAttributes.id==attributes.attributeId){
返回行(
儿童:[
新容器(
对齐:对齐(-1.0,-1.0),
孩子:填充(
填充:仅限常量边集(底部:10.0,右侧:10.0),
子:文本(
allAttributes.name+':',
样式:TextStyle(
颜色:颜色,黑色,
尺寸:20,
fontWeight:fontWeight.w600),
),
)),
下拉按钮(
提示:文本(“选择项”),
值:selectedUser,
onChanged:(属性值){
设置状态(){
selectedUser=值;
});
},
条目:widget.attributes.map((属性){
返回下拉菜单项(
值:属性,
孩子:排(
儿童:[
大小盒子(
宽度:10,
),
正文(
属性。值,
样式:TextStyle(颜色:Colors.black),
),
],
),
);
}).toList(),
),
],
);
}
}
}
}
返回文本('Nothing');
}
我确实尝试过地图,但它也不起作用,下面是地图的代码:

@override
  Widget build(BuildContext context) {
    widget.allAttributes.map((AllAttributes allAttributes) {
      //print(allAttributes.name);
        widget.attributes.map((Attributes attributes){
          return Row(
            children: <Widget>[
              new Container(
                  alignment: Alignment(-1.0, -1.0),
                  child: Padding(
                    padding: const EdgeInsets.only(bottom: 10.0, right: 10.0),
                    child: Text(
                      allAttributes.name + ':',
                      style: TextStyle(
                          color: Colors.black,
                          fontSize: 20,
                          fontWeight: FontWeight.w600),
                    ),
                  )),
              DropdownButton<Attributes>(
                hint: Text("Select item"),
                value: selectedUser,
                onChanged: (Attributes Value) {
                  setState(() {
                    selectedUser = Value;
                  });
                },
                items: widget.attributes.map((Attributes attributes) {
                  return DropdownMenuItem<Attributes>(
                    value: attributes,
                    child: Row(
                      children: <Widget>[
                        SizedBox(
                          width: 10,
                        ),
                        Text(
                          attributes.value,
                          style: TextStyle(color: Colors.black),
                        ),
                      ],
                    ),
                  );
                }).toList(),
              ),
            ],
          );
        }).toList();
    }).toList();

    return Text('Nothing');
  }
@覆盖
小部件构建(构建上下文){
widget.allAttributes.map((allAttributes allAttributes){
//打印(所有属性.名称);
widget.attributes.map((属性){
返回行(
儿童:[
新容器(
对齐:对齐(-1.0,-1.0),
孩子:填充(
填充:仅限常量边集(底部:10.0,右侧:10.0),
子:文本(
allAttributes.name+':',
样式:TextStyle(
颜色:颜色,黑色,
尺寸:20,
fontWeight:fontWeight.w600),
),
)),
下拉按钮(
提示:文本(“选择项”),
值:selectedUser,
onChanged:(属性值){
设置状态(){
selectedUser=值;
});
},
条目:widget.attributes.map((属性){
返回下拉菜单项(
值:属性,
孩子:排(
儿童:[
大小盒子(
宽度:10,
),
正文(
属性。值,
样式:TextStyle(颜色:Colors.black),
),
],
),
);
}).toList(),
),
],
);
}).toList();
}).toList();
返回文本('Nothing');
}

我认为列表的映射方法可能是这种情况的最佳解决方案

不经过编辑就很难修改这么大的代码,所以我向您展示了如何处理您的情况

 List<int> _data = [1, 2, 3, 4, 5, 6];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
          child: Column(
        children: _data.map((e) {
          return Text(e.toString());
        }).toList(),
      )),
    );
  } 
List_data=[1,2,3,4,5,6];
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:容器(
子:列(
子项:_data.map((e){
返回文本(例如toString());
}).toList(),
)),
);
} 
我仍然尽我最大的努力修改代码。我希望下面的代码工作没有任何错误

此外,通过使用list包装list(for循环使用for循环)两次创建列表,所以将其删除

  //print(allAttributes.name);
  return Column(
        children:
    widget.attributes.length>0? widget.attributes.map((Attributes attributes){
      return Row(
        children: <Widget>[
          new Container(
              alignment: Alignment(-1.0, -1.0),
              child: Padding(
                padding: const EdgeInsets.only(bottom: 10.0, right: 10.0),
                child: Text(
                  allAttributes.name + ':',
                  style: TextStyle(
                      color: Colors.black,
                      fontSize: 20,
                      fontWeight: FontWeight.w600),
                ),
              )),
          DropdownButton<Attributes>(
            hint: Text("Select item"),
            value: selectedUser,
            onChanged: (Attributes Value) {
              setState(() {
                selectedUser = Value;
              });
            },
            items: widget.attributes.map((Attributes attributes) {
              return DropdownMenuItem<Attributes>(
                value: attributes,
                child: Row(
                  children: <Widget>[
                    SizedBox(
                      width: 10,
                    ),
                    Text(
                      attributes.value,
                      style: TextStyle(color: Colors.black),
                    ),
                  ],
                ),
              );
            }).toList(),
          ),
        ],
      );
    }).toList(): [Text('Nothing')]);
//打印(allAttributes.name);
返回列(
儿童:
widget.attributes.length>0?widget.attributes.map((属性){
返回行(
儿童:[
新容器(
对齐:对齐(-1.0,-1.0),
孩子:填充(
填充:仅限常量边集(底部:10.0,右侧:10.0),
子:文本(
allAttributes.name+':',
样式:TextStyle(
颜色:颜色,黑色,
尺寸:20,
fontWeight:fontWeight.w600),
),
)),
下拉按钮(
提示:文本(“选择项”),
值:selectedUser,
onChanged:(属性值){
设置状态(){
selectedUser=值;
});
},
条目:widget.attributes.map((属性){
返回下拉菜单项(
值:属性,