1

I have two PageViews in one screen (with different viewportFraction), I need to implement the next behavior: when a user scroll PageView 2, PageView 1, also need to be scroll with PageView 2. (Like safari tabs in iOS 15)

I would be very grateful for any hints on how to implement this behavior, maybe i can use some other widgets for this?

UPD: I have tried to use jumpTo, but it glitch. And if I scroll PageView 2 only to the half of page, PageView 2 automatically scrolls to next page

enter image description hereenter image description here

Alex Smith
  • 31
  • 3
  • 1
    you need to setup a `PageController` to the other page view and use its `jumpTo` method – pskink Oct 30 '21 at 11:40
  • I have tried, but when i scroll, it glitch, because 1 PageView automatically want to scroll to some page position. Another words: if I scroll half of page, 1 PageView automatically scrolls back or to next page – Alex Smith Oct 30 '21 at 11:56
  • post your code then – pskink Oct 30 '21 at 12:23

1 Answers1

0

From what I understand you should maybe add controllers in your PageViews and then listen to the PageView2 controller

Like this:

    const Duration _duration = Duration(milliseconds: 100);
    
    final PageController _controller1 = PageController();
    final PageController _controller2 = PageController();
    
    _controller2.addListener(() {
      setState(() {
        _controller1.animateTo(_controller2.offset, duration: _duration, curve: Curves.ease);
      });
    });

PS: If your two PageViews have the same number of pages and the same width

mms59
  • 31
  • 2