android – StateError (Bad state: No element) while scrolling Pageview with Videos

0
79

[ad_1]

I am developing an app with a function like tiktok and I can scrolling videos and display them as well, but everytime I scroll it fast and gave me a Bad State error. I don’t know what else to do. Here’s my code below:

return Observer(builder: (context) {
  return _controller.controllers.isEmpty
      ? _buildLoading()
      : PageView.builder(
          controller: widget.pageController,
          itemCount: widget.posts?.length ?? 0,
          physics: const ClampingScrollPhysics(),
          scrollDirection: Axis.vertical,
          pageSnapping: true,
          onPageChanged: (value) {
            _controller.changeIndex(value);
          },
          itemBuilder: (context, index) {
            var controller = _controller.controllers
                .where((element) => element.position == index)
                .toList()
                .first;

            print(controller.post.subCaption);
            return ISowPost(
                post: controller.post, controller: controller.controller);
          },
        );
});

It seems that controller kinda can’t handle many requests so It breaks and then It reloads.

[ad_2]