Flutter PageController AnimateToPage 破坏了应用程序

问题描述 投票:0回答:2

我一直在使用带有页面控制器的页面视图在我的 flutter 应用程序中的页面之间移动,我有五个屏幕。当我从一页转到彼此相邻的另一页时,一切都很好。但是,当我从索引为 0 的页面转到 2 时,应用程序会挂起并且无法正常工作,并且即使使用 try 和 catch,也不会显示任何日志或错误。

另一方面,如果我使用 pageController.jumpToPage() 那么一切都会完美运行。

这个问题只有在我将 flutter 升级到最新版本以及所有依赖项时才出现。

这是我一直在使用的代码:

_pageController.animateToPage(index,
            duration: Duration(milliseconds: 400), curve: Curves.easeIn);
flutter flutter-animation
2个回答
0
投票

颤振版本3.3.9 而且IOS没问题。 但安卓不行。

closeModalBottom(value, courseBrain) {
if (value == "wrong") { //if run this code not working page animate
  // Create Wrong Question Page
  final _wrongQuestion = getQuestionPage(courseBrain.history!);
  pages.add(_wrongQuestion);
}

_pageViewIndex = _pageViewIndex + 1;

// Animate Next Page
controller.animateToPage(
  _pageViewIndex,
  duration: Duration(milliseconds: 500),
  curve: Curves.ease,
);

}

编辑:我确实降级了 Flutter 3.3.2,但无法再次工作。


0
投票

我没有在 animateToPage 中使用index==0 因此,不要从index == 0开始,而是尝试从index==1开始

class Welcome extends StatelessWidget {
  Welcome({super.key});

  final PageController _controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(
        children: [
          PageView(
            controller: _controller,
            scrollDirection: Axis.horizontal, //横にスライド
            children: [
              //first page
              appOnboardingPage(
                _controller,
                imagePath: 'assets/images/reading.png',
                title: 'First See Learning',
                subtitle:
                    'Forget about the paper, now learning all in one place',
                index: 1,//Doesn't work from 0
              ),
              //second page
              appOnboardingPage(
                _controller,
                imagePath: 'assets/images/man.png',
                title: 'Connect With Everyone',
                subtitle:
                    'Always keep in touch with your tutor and friends. Let`s get connected',
                index: 2,
              ),
              appOnboardingPage(
                _controller,
                imagePath: 'assets/images/boy.png',
                title: 'Always Fascinated Learning',
                subtitle:
                    'Anywhere, anytime. the is at your discretion. So study wherever you can',
                index: 3,
              ),
            ],
          ),
        ],
      ),
    );
  }

Widget _nextButton(int index, PageController controller) {
  return GestureDetector(
    onTap: () {
      print("my index is $index");
      if (index < 3) {
        print(index);
        controller.animateToPage(index,
            duration: Duration(milliseconds: 300), curve: Curves.bounceIn);
      }
    },
    child: Container(
      width: 325,
      height: 50,
      margin: EdgeInsets.only(top: 100, left: 25, right: 25),
      decoration: appBoxShadow(),
      child: Center(
        child: text16Normal(
          text: "next",
          color: Colors.white,
        ),
      ),
    ),
  );
}

}
© www.soinside.com 2019 - 2024. All rights reserved.