Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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

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
Dart 颤振状态小部件返回列表_Dart_Flutter - Fatal编程技术网

Dart 颤振状态小部件返回列表

Dart 颤振状态小部件返回列表,dart,flutter,Dart,Flutter,我正在将以前在函数中的内容移动到无状态小部件中。我想知道我是否可以返回一个带有小部件类型的列表,如果可以,我该怎么做 我尝试了一些随机的东西,只会进一步破坏我的应用程序 class returnList1 extends StatelessWidget { @override Widget build(BuildContext context) { return <Widget>[ InfoCard(), InfoCard(), I

我正在将以前在函数中的内容移动到无状态小部件中。我想知道我是否可以返回一个带有小部件类型的列表,如果可以,我该怎么做

我尝试了一些随机的东西,只会进一步破坏我的应用程序

class returnList1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return <Widget>[
      InfoCard(),
      InfoCard(),
      InfoCard(),
      Stack(
        children: <Widget>[
          IconButton(
            icon: Icon(Icons.more_horiz),
            iconSize:
                35.0, // TODO: scale icons based on mediaquery height and width
            color: Colors.black,
            onPressed: () {
              print("More Pressed!");
            },
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(
                MediaQuery.of(context).size.width * 0.034,
                MediaQuery.of(context).size.height * 0.02839,
                0.0,
                0.0),
            child: Material(
              color: Colors.transparent,
              elevation: 7.5,
              borderRadius: BorderRadius.circular(200.0),
              child: Container(
                height: MediaQuery.of(context).size.height * 0.009675,
                width: MediaQuery.of(context).size.width * 0.0559,
                color: Colors.transparent,
              ),
            ),
          ),
        ],
      )
    ];
  }
}
class returnList1扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回[
信息卡(),
信息卡(),
信息卡(),
堆叠(
儿童:[
图标按钮(
图标:图标(更多图标),
我意识到:
35.0,//TODO:基于mediaquery高度和宽度缩放图标
颜色:颜色,黑色,
已按下:(){
打印(“更压!”);
},
),
填充物(
填充:EdgeInsets.fromLTRB(
MediaQuery.of(context).size.width*0.034,
MediaQuery.of(context).size.height*0.02839,
0.0,
0.0),
儿童:材料(
颜色:颜色。透明,
标高:7.5,
边界半径:边界半径。圆形(200.0),
子:容器(
高度:MediaQuery.of(context).size.height*0.009675,
宽度:MediaQuery.of(context).size.width*0.0559,
颜色:颜色。透明,
),
),
),
],
)
];
}
}

当我运行代码时,我得到“getter'length'被调用为null。在我的IDE中,我得到“返回类型'List'不是方法'build'定义的'Widget'”。

你不能使用
build
方法返回列表。
build
方法只能返回
Widget
。 如果您想要返回一个列表,那么您可以创建一个函数并返回一个列表,该列表可以在任何多子容器的children属性中使用

这是密码

    _returnList (BuildContext context) {
    return [
      InfoCard(),
      InfoCard(),
      InfoCard(),
      Stack(
        children: <Widget>[
          IconButton(
            icon: Icon(Icons.more_horiz),
            iconSize:
            35.0, // TODO: scale icons based on mediaquery height and width
            color: Colors.black,
            onPressed: () {
              print("More Pressed!");
            },
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(
                MediaQuery.of(context).size.width * 0.034,
                MediaQuery.of(context).size.height * 0.02839,
                0.0,
                0.0),
            child: Material(
              color: Colors.transparent,
              elevation: 7.5,
              borderRadius: BorderRadius.circular(200.0),
              child: Container(
                height: MediaQuery.of(context).size.height * 0.009675,
                width: MediaQuery.of(context).size.width * 0.0559,
                color: Colors.transparent,
              ),
            ),
          ),
        ],
      )
    ];
  }
\u返回列表(构建上下文){
返回[
信息卡(),
信息卡(),
信息卡(),
堆叠(
儿童:[
图标按钮(
图标:图标(更多图标),
我意识到:
35.0,//TODO:基于mediaquery高度和宽度缩放图标
颜色:颜色,黑色,
已按下:(){
打印(“更压!”);
},
),
填充物(
填充:EdgeInsets.fromLTRB(
MediaQuery.of(context).size.width*0.034,
MediaQuery.of(context).size.height*0.02839,
0.0,
0.0),
儿童:材料(
颜色:颜色。透明,
标高:7.5,
边界半径:边界半径。圆形(200.0),
子:容器(
高度:MediaQuery.of(context).size.height*0.009675,
宽度:MediaQuery.of(context).size.width*0.0559,
颜色:颜色。透明,
),
),
),
],
)
];
}

这不起作用。在返回内容之前,您需要将内容包装在一个小部件中,该小部件包含一个小部件列表(如