[英]Make a ListView scroll horizontal in a PageView
I'm trying to create a ListView of images that stays in a PageView so I can swipe left or right to move to other images.我正在尝试创建一个保留在 PageView 中的图像列表视图,以便我可以向左或向右滑动以移动到其他图像。
But I currently end up with an error that it only displays as a column and swipe vertically not horizontally as I wanted.但是我目前遇到了一个错误,它只显示为一列并且垂直滑动而不是我想要的水平滑动。
Anyone who gets solutions or ideas, please help me.任何获得解决方案或想法的人,请帮助我。
Here is my code:这是我的代码:
final PageController _controller = PageController(
initialPage: initialImageIndex, keepPage: true, viewportFraction: 1);
return SafeArea(
child: Scaffold(
body: PageView(
controller: _controller,
scrollDirection: Axis.horizontal,
onPageChanged: (index) {
print("changed to $index");
},
children: [
Row(
children: [
Container(
width: size.width,
child: ListView.builder(
controller: ScrollController(
),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
// physics: NeverScrollableScrollPhysics(),
itemCount: imagesInCategory.length,
itemBuilder: (context, index) {
return BuildImageDetail(
size: size, imageData: imagesInCategory[index]);
},
),
),
],
),
])),
I just got it with a function to render the widgets that Listview currently does now.我刚刚用 function 得到它来呈现 Listview 当前所做的小部件。 Then in children of PageView, i just call this function.然后在 PageView 的子项中,我只是将其称为 function。
Hope this helps somebody.希望这可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.