0

How can I rebuild my PageView.builder? when I change _type property in MyPage, I want rebuild it

child: PageView.builder(
            controller: _controller,
            itemCount: items.length,
            allowImplicitScrolling: true,
            reverse: false,
            onPageChanged: (int position) {
              item = items[position];
            },
            itemBuilder: (context, position) => MyPage(
                  item: items[position],
                  type: _type)),
esfsef
  • 193
  • 3
  • 11
  • setState should be able to `rebuild` your widgets – JideGuru Jun 22 '20 at 12:43
  • When build PageView flutter preload 3 pages. When in ``MyPage`` I change ``type`` property, I want rebuild another 2 pages, because, if I change my ``type`` and swipe left, in first page ``type`` property isn't changed – esfsef Jun 22 '20 at 12:47

1 Answers1

0

i think the problem is in your onPageChanged part. you should do something like this.

child: PageView.builder(
      controller: _controller,
      itemCount: items.length,
      allowImplicitScrolling: true,
      reverse: false,
       onPageChanged: (int position) {
          setState(
             () {
            currentIndex = position;
             },
            );
           },
         itemBuilder: (context, position) => MyPage(
            item: items[position],
            type: _type)),
Salim Murshed
  • 1,423
  • 1
  • 8
  • 19