dart - How to solve scrolling in list view when gridview as a child?
问题描述
How to solve the scrolling issue in flutter layout when adding gridview inside listview.
in android studio java we use NestedScrollView to solve this type of issue
What is the solution for flutter?
I need to scrolling continues with out any problem with listview with custom view and gridview.
Now then gridview is only allowing to scroll gridview
if i scroll grid view then top imageview is not scrolling .How to solve this issue?
body:
ListView(
children: <Widget>[
new Image.network("https://www.gizbot.com/img/2013/11/23-weekend-deals-top-10-latest-smartphones.jpg"),
Container(
height: 300.0,
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: .6,
children: _list.map((p) => ProductManagment(p)).toList(),
),
)
],
)
解决方案
而不是使用ListView
,您应该使用如下所示的列小部件。
body:
Column(
children: <Widget>[
Container (
height: 150.0, // Set as you want
child: Image.network("https://www.gizbot.com/img/2013/11/23-weekend-deals-top-10-latest-smartphones.jpg")),
Container(
height: 300.0,
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: .6,
children: _list.map((p) => ProductManagment(p)).toList(),
),
)
],
)
Because of `GridView` itself has scroll effect.
编辑:
Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
child: ListView(
children: <Widget>[
Column(
children: <Widget>[
Container(
height: 200,
child: Image.network(
"https://www.gizbot.com/img/2013/11/23-weekend-deals-top-10-latest-smartphones.jpg"),
),
ConstrainedBox(
constraints: BoxConstraints(
minHeight: 80, // Set as you want or you can remove it also.
maxHeight: double.infinity,
),
child: Container(
child: GridView.count(
crossAxisCount: 3,
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: NeverScrollableScrollPhysics(),
childAspectRatio: .6,
children: _list.map((p) => ProductManagment(p)).toList(),
),
),
)
],
),
],
),
));
您必须使用ConstrainedBox
setmaxHeight: double.infinity
和 GridView.count
set shrinkWrap: true,
。并删除容器高度 300。
另外如果你想改变
Container(
height: 200,
child: Image.network(
"https://www.gizbot.com/img/2013/11/23-weekend-deals-top-10-latest-smartphones.jpg"),
),
只是
Image.network("https://www.gizbot.com/img/2013/11/23-weekend-deals-top-10-latest-smartphones.jpg")
比你可以改变它。
推荐阅读
- python - UTF-8 错误编码,找出错误编码的方式
- javascript - JavaScript数组的长度为1但它是空的?
- php - PDFLib,错误:无法导入 PDF 文档“document.pdf”的第 1 页(文档使用比输出文档更高的 PDF 版本 1.7)
- javascript - 找不到“<%”的匹配关闭标签,我该如何解决?
- parameters - 为什么 Dialogflow 不从履行响应中检索参数值?
- postman - 如何验证组件模式中的嵌套属性(Postman 中的 openapi 3)
- angular - 具有多个系列 Highcharts 的堆叠列中的分段重叠问题
- eloquent - 雄辩的选择项目,在同一关系列上有几个 where 子句
- c++ - 谁能告诉为什么这段代码会产生错误的输出?
- java - 当每个模块都有特定版本时,如何在 Nexus 中将工件关联到一个业务版本?