[英]ListView.builder with scrollDirection horizontal got error
I have this code:我有这个代码:
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => addProductClass()),
);
},
child: const Icon(
Icons.add,
color: Colors.black,
),
),
body: Column(children: [
FutureBuilder(
future: getDocId(),
builder: (context, snapshot) {
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: dataIDs.length,
itemBuilder: (BuildContext context, int index) {
return GetProduct(
documentId: dataIDs[index],
);
},
);
}),
Text("text")
]));
}
And i want to use scrollDirection: Axis.horizontal
for listview.我想使用scrollDirection: Axis.horizontal
的列表视图。 When I insert this value, I got the error:当我插入这个值时,我得到了错误:
Horizontal viewport was given unbounded height水平视口被赋予了无限的高度
Viewports expand in the cross axis to fill their container and ' 'constrain their children to match their extent in the cross axis.视口在横轴上扩展以填充其容器并“约束其子项以匹配其在横轴上的范围。 ' 'In this case, a horizontal viewport was given an unlimited amount of ' 'vertical space in which to expand ' '在这种情况下,水平视口被赋予了无限量的 ' '垂直空间来扩展
How can I resolve this?我该如何解决这个问题?
Try to set shrinkwrap to true for listview builder here is an example of listview builder in horizontal mode:尝试将 listview builder 的shrinkwrap设置为 true 这里是水平模式下 listview builder 的示例:
Column(
children :[
Expanded(
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: 15,
itemBuilder: (BuildContext context, int index) => Card(
child: Center(child: Text('Dummy Card Text')),
),
),
]
)
hope it will help !希望它会有所帮助!
Easiest way is to provide a fixed height, either using a SizedBox
or a ConstrainedBox
with a maxHeight
set.最简单的方法是提供一个固定的高度,或者使用SizedBox
或带有maxHeight
集的ConstrainedBox
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.