有没有一种方法可以在不使用 Listview ,Gridview 的情况下在 List 中生成 Widget?
Is there a way in flutter to generate Widgets in a List without using Listview , Gridview?
我想做的是将列表中的小部件放入堆栈。列表中的每个小部件都将 return 一个具有不同对齐方式的容器。
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]; })
))])
这里即使我的容器出现在堆栈中,它们的位置也不是我想要的位置。它们的对齐是在 listtile 内完成的。我想要的是对齐 SizedBox.I 内 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], ])
这种方式即使可以让列表中的小部件位于需要的位置,它也不是动态的。我需要帮助才能动态执行此操作。
使用展开运算符
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
])
我想做的是将列表中的小部件放入堆栈。列表中的每个小部件都将 return 一个具有不同对齐方式的容器。
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]; })
))])
这里即使我的容器出现在堆栈中,它们的位置也不是我想要的位置。它们的对齐是在 listtile 内完成的。我想要的是对齐 SizedBox.I 内 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], ])
这种方式即使可以让列表中的小部件位于需要的位置,它也不是动态的。我需要帮助才能动态执行此操作。
使用展开运算符
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
])