【发布时间】:2021-04-25 16:20:39
【问题描述】:
更新:我想通了。看我的回答below
我将GridView 呈现为一个弹出路由,它会产生
下面的代码
class GridPopup extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Colors.blue,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
RaisedButton(
child: Text('Close popup'),
onPressed: () => Navigator.of(context).pop(),
),
// Expanded(
// child: GridView.count(
GridView.count(
crossAxisCount: 5,
crossAxisSpacing: 2.0,
mainAxisSpacing: 2.0,
childAspectRatio: 1.0,
shrinkWrap: true,
children: List.generate(
25,
(index) => Container(color: Colors.green),
),
),
// ),
],
),
),
),
);
}
}
问题是当GridView中的项目数增加时,会溢出
可以通过用Expanded 包裹GridView 来修复它,但是弹出窗口总是覆盖整个屏幕
我可以在不使用Expanded 小部件且不指定大小的情况下修复溢出吗?换句话说,我希望弹出窗口的高度尽可能小(项目少时少,项目多时多),同时仍包含 GridView,以免溢出。
【问题讨论】:
标签: flutter dart flutter-layout