有没有办法在Flutter中使用PageView进行无限循环?

有没有办法在Flutter中使用PageView进行无限循环?

问题描述:

是否可以使用Flutter中的 PageView 进行无限循环?例如,如果我的PageView有5个页面,则在滑动到第5页后,我将能够再次向同一方向滑动以进入第1页.

Is there a way to have an infinite loop using PageView in Flutter? For example if my PageView has 5 pages, after swiping to page 5, I would be able to swipe again in the same direction to get to Page 1.

默认情况下, PageView.builder 扑朔迷离.除非您提供 itemCount .

By default, PageView.builder is infinite in flutter. Unless you provide an itemCount.

以下内容将从0到4无限打印页面

The following will print page from 0 to 4 infinitely

final controller = new PageController(initialPage: 999);
 ...

new PageView.builder(
      controller: controller,
      itemBuilder: (context, index) {
        return new Center(
          child: new Text('${index % 5}'),
        );
      },
)