![](/img/trans.png)
[英]Flutter RenderFlex Overflow error when using CustomScrollView
[英]RenderFlex overflow using Flutter GridView
我使用 GridView.count() 在我的應用程序中顯示動態數據,但我的每個 GridView 元素都沒有完全顯示。
這是它的樣子:
這是我的代碼:
Column(
children: [
buildSubheadingText('Mes projets'),
buildVerticalSpace(5.0),
GridView.count(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
//physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
children: ContextManager.projects.map((value) {
return ProjectCard(project: value);
}).toList()
)
],
);
按照本主題的答案中的建議,我已經在 BouncingScrollPhysics 或 NeverScrollableScrollPhysics 中添加了屬性 shrinkWrap 和物理屬性,但您可以看到它對我不起作用。
另外,我不想使用固定高度,因為這里的數據是動態的。
感謝您的幫助。
您可以使用 childAspectRatio 屬性為網格設置自定義高度
例子:-
Column(
children: [
buildSubheadingText('Mes projets'),
buildVerticalSpace(5.0),
GridView.count(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
childAspectRatio: 2/3, //gives custom height to your grid element
crossAxisCount: 2,
children: ContextManager.projects.map((value) {
return ProjectCard(project: value);
}).toList()
)
],
);
GridView
兒童尺寸取決於childAspectRatio
,默認為1.0
,您可以通過更改默認childAspectRatio
來增加高度。 喜歡
child: GridView.count(
crossAxisCount: 2,
childAspectRatio: 1 / 1.2, //width /height
請嘗試使用這個庫, staggered_grid_view
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.