该问题的预期实施类似于 Instagram 故事。flutter 中有一个名为 story_view 的包,它的作用相同,但根据我的理解,不可能将 Pageview 添加为子项。那么,这可以在颤振中实现吗?
问问题
203 次
1 回答
2
您可以在页面视图上使用GestureDetector
andPageController
来实现此目的。WhereGestureDetector
用于获取屏幕的点击位置,并根据该位置调用页面控制器前进或后退。
包装PageView(controller: _pageController,...)
,GestureDetector
然后定义onTapDown
如下内容:
GestureDetector(
onTapDown: (TapDownDetails details) {
final RenderBox box = context.findRenderObject();
final localOffset = box.globalToLocal(details.globalPosition);
final x = localOffset.dx;
// if x is less than halfway across the screen and user is not on first page
if(x < box.size.width / 2){
// _pageController.previousPage(...)
}else{
// Assume the user tapped on the other half of the screen and check they are not on the last page
// _pageController.nextPage(...)
}
},
child: PageView(
controller: _pageController,
...
)
)
如您所见,我尚未完全实施解决方案,但这应该是您想要的
于 2020-06-18T10:12:23.137 回答