Non-center alignment for PageView with viewportFraction < 1.0

柔情痞子 提交于 2019-12-05 14:31:16

I'm actually trying to achieve something similar, I did ask a question here: Is there a way to disable PageView clipping effect?

But thanks to you, your thought of approaching with ListView & PageScrollPhysics is just brilliant, I can solve it now. For calculating the page, you just need to do this:

ScrollController controller = ScrollController();
controller.addListener((){
  int page = (controller.offset / viewportWidth).round();
});
// which "viewportWidth" is the width of your page item.

or if you want to animate to a specific page, do this:

int page = 3;
controller.animateTo(
  page.toDouble() * viewportWidth,
  duration: Duration(milliseconds: 300),
  curve: Curves.ease,
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!