【发布时间】:2021-08-05 07:13:19
【问题描述】:
我想做一个自动填充容器的网格项。
我想要的是这样的。这个我用childAspectRatio,但是如果我减少项目编号,它就无法填满容器。
这是我的网格代码
Column (
children: <Widget>[
Row(
children: [
Expanded(
child: Container(
color: Colors.grey,
height: 150,
child: _gridView ()),
),
],
),
)
Widget _gridView () {
return GridView.count(
crossAxisCount: 2,
scrollDirection: Axis.horizontal,
mainAxisSpacing: 5,
crossAxisSpacing: 3,
children: List.generate(6, (index) {
return Container(
alignment: Alignment.center,
child: SizedBox(
child: FloatingActionButton(
backgroundColor: Colors.green,
child: null,
onPressed: () {
print("Cliked");
},)
));
})
);
}
一些参考说我应该使用Expanded,但我仍然不知道该放在哪里。
【问题讨论】:
-
你在说什么空格?
-
@EhsanAskari 我的意思是我想装满容器。我将给出预期的结果以使其更清楚。
-
你想让它水平滚动吗?
-
@EhsanAskari 是的
-
如果它是水平滚动的,你为什么要它填满容器?
标签: flutter dart flutter-layout