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 在Flatter中有没有一种方法可以在列表中生成小部件而不使用Listview、Gridview?_Flutter_Flutter Listview - Fatal编程技术网

Flutter 在Flatter中有没有一种方法可以在列表中生成小部件而不使用Listview、Gridview?

Flutter 在Flatter中有没有一种方法可以在列表中生成小部件而不使用Listview、Gridview?,flutter,flutter-listview,Flutter,Flutter Listview,我想做的是将列表中的小部件放到堆栈中。列表中的每个小部件都将返回一个具有不同对齐方式的容器 Container( alignment: Alignment(xValue,yValue)) 我的堆栈如下所示: stack( children: <Widget>[ SizedBox( width :MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, child: Container

我想做的是将列表中的小部件放到堆栈中。列表中的每个小部件都将返回一个具有不同对齐方式的容器

Container( alignment: Alignment(xValue,yValue))
我的堆栈如下所示:

stack(
children: <Widget>[
SizedBox(
width :MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Container(
color:Colors.greenAccent,
child: ListView.builder(
           physics: const NeverScrollableScrollPhysics(),
           itemCount: widgetList.length,
           itemBuilder(BuildContext contet, int index){
                return widgetList[index]; })
))])
堆栈(
儿童:[
大小盒子(
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
子:容器(
颜色:Colors.greenAccent,
子项:ListView.builder(
物理学:const NeverScrollableScrollPhysics(),
itemCount:widgetList.length,
itemBuilder(BuildContext内容,int索引){
返回widgetList[索引];})
))])
在这里,即使我的容器出现在堆栈中,它们的位置也不是我想要的位置。它们的对齐在listtile内完成。我想要的是在SizedBox中对齐widgetlist中的那些容器

stack(
   children: <Widget>[
        SizedBox(
            width :MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Container( color: Colors.greenAccent)),
        widgetList[0],
        widgetList[1], ])
堆栈(
儿童:[
大小盒子(
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
子:容器(颜色:Colors.greenAccent)),
widgetList[0],
widgetList[1],])

这样,即使可以使列表中的小部件位于需要的位置,它也不是动态的。我需要帮助来动态执行此操作。

使用扩展运算符

Stack(
   children: <Widget>[
        SizedBox(
            width :MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Container( color: Colors.greenAccent)),
        ...widgetList,    // Note the three dots before the widgetList
])
堆栈(
儿童:[
大小盒子(
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
子:容器(颜色:Colors.greenAccent)),
…widgetList,//注意widgetList前面的三个点
])