Flutter:如何在PageView构建后跳至没有动态按钮单击事件的初始页面

时间:2019-08-13 02:59:36

标签: flutter

建立综合浏览量后,我需要自动跳至第二页。

我已经尝试过:

_pageController = PageController(initialPage: 1, keepPage: false);
_pageController.jumpToPage(1); //removed this line cause of errors

代码

Widget build(BuildContext context) {
  return SizedBox(
    height: _pageViewHeight,
    child: PageView.builder(
      physics: BouncingScrollPhysics(),
      itemCount: state.accountList.length,
      controller: _pageController,
      onPageChanged: (int pageIndex) {
      },

      // Body
      itemBuilder: (BuildContext context, int itemIndex) {
        return _buildPageViewItem(context, state.accountList[itemIndex]);
      },
    ),
  );
}

发生以下错误:

ScrollController not attached to any scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 110 pos 12: '_positions.isNotEmpty'
When the exception was thrown, this was the stack: ScrollController.position
Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': 
Failed assertion: line 263 pos 16: 'child == null || indexOf(child) > index': is not true.

0 个答案:

没有答案