Jump pages in Pageview.builder with Consumer

Viewed 185

I'm trying to make a feed where once the users uploads a post, the post gets added to the top of the feed and the user can see the post they just made. Right now I have a ChangeNotifierProvider and Consumer that is getting newly updated data from my view model. Inside the ChangeNotifierProvider, I have a pageview.builder. How would I get the pageview.builder to refresh pages so that the users post is now shown? I have tried using the onPageJumped but I can't use that inside the ChangeNotifier.

Widget _buildScreen(VideoPlayerViewModel viewModel) {
    return ChangeNotifierProvider<VideoPlayerViewModel>(
        create: (context) => viewModel,
        child: Consumer<VideoPlayerViewModel>(
            builder: (context, model, child) => PageView.builder(
                controller: pageController,
                scrollDirection: Axis.vertical,
                itemCount: videoPlayerViewModel.intialVideoDataLength,
                itemBuilder: (BuildContext context, int index) {
                  var data = videoPlayerViewModel.intialVideoData;

                  return VideoScaffoldWidget(videoData: data[index]);
                })));
  }
1 Answers

Try adding unique key to the PageView, it should do the trick

 PageView.builder(
      key: UniqueKey(),
Related