Home > Net >  Create a page view with 2 different scrollable list with different index
Create a page view with 2 different scrollable list with different index

Time:10-25

I want to create a screen that can display a scrollable list. Based on a condition, I want to be able to display another list. My program works however the index is the same for the 2 lists so when I scroll a list, the second list is scroll too

My code :

return PageView.builder(
          scrollDirection: Axis.vertical,
          itemCount: category[state.indexView].length,
          itemBuilder: category[state.indexView][0].containsKey('video')
              ? (context2, index2) {
                  return Stack(
                    children: [
                      VideoWidget(
                        videoUrl: category[state.indexView][index2]['video'],
                        asset: true,
                        videoFile: File(''),
                      ),
                      if (category[state.indexView][index2].containsKey('image'))
                        Center(child: Image(image: AssetImage(category[state.indexView][index2]['image']))),
                      _postContent(d_height)
                    ],
                  );
                }
              : (context, index) {
                  return Stack(
                    children: [
                      if (category[state.indexView][index].containsKey('image'))
                        Center(child: Image(image: AssetImage(category[state.indexView][index]['image']))),
                      _postContent(d_height)
                    ],
                  );
                });

CodePudding user response:

You can create second page in pageview similar to first page when you want to jump on second page then pass that index to another page and use it as current index in listview.

CodePudding user response:

Yes but i can't because maybe it will be 1,2 or 3 pages etc... So how i can create dynamically this page :

return PageView.builder(
      scrollDirection: Axis.vertical,
      itemCount: category[state.indexView].length,
      itemBuilder: category[state.indexView][0].containsKey('video')
          ? (context, index) {
              return Stack(
                children: [
                  VideoWidget(
                    videoUrl: category[state.indexView][index2]['video'],
                    asset: true,
                    videoFile: File(''),
                  ),
                  if (category[state.indexView][index2].containsKey('image'))
                    Center(child: Image(image: AssetImage(category[state.indexView][index2]['image']))),
                  _postContent(d_height)
                ],
              );
            });
  • Related