【发布时间】:2020-12-10 11:44:29
【问题描述】:
我有一个网格视图,我想在非特定高度容器中显示它。但是,只有当我使用具有指定高度的容器时,才会显示网格视图。当我将 Container 更改为 Expanded 或 Flexible 时,GridView 变得不可见。
工作代码:
return Container( //using container
height: 250, //with a specific height
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(0.0),
crossAxisSpacing: 10.0,
crossAxisCount: 2,
children: <Widget>[
const Text('He\'d have you all unravel at the'),
const Text('Heed not the rabble'),
const Text('Sound of screams but the'),
const Text('Who scream'),
],
),
);
非工作代码:
return Expanded(
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(0.0),
crossAxisSpacing: 10.0,
crossAxisCount: 2,
children: <Widget>[
const Text('He\'d have you all unravel at the'),
const Text('Heed not the rabble'),
const Text('Sound of screams but the'),
const Text('Who scream'),
],
),
);
【问题讨论】:
标签: flutter gridview flutter-layout