packages.flutter icon indicating copy to clipboard operation
packages.flutter copied to clipboard

Using this with Scrollable widgets like PageView

Open urusaich opened this issue 2 years ago • 2 comments

Hi Serge! How it is possible to using pdf viewer with Scrollable widgets? How example, if vertical pdf viewers puts in horizontal PageView pages, functionality may got broken. If pdf was zoomed before, PageView's horizontal drag gesture wins, and page get scrolled insteadof moving zoomed pdx image Any ideas?

urusaich avatar Nov 08 '23 19:11 urusaich

any workaround on this?

mohsin2217A avatar Jan 20 '25 14:01 mohsin2217A

It seems that single page PDF works fine with PageView, however multi page PDF breaks the PageView left/right swipe scrollable behavior.

We use PageView like that:

 final pageView = PageView.builder(
    itemBuilder: (context, index) {
      return pdfWidget;
    },
    physics: const FastScrollPhysics(speedFactor: 4.0),
    controller: _pageController,
    itemCount: pdfs.length,
  );

class FastScrollPhysics extends PageScrollPhysics {
  final double speedFactor;

  const FastScrollPhysics({this.speedFactor = 2.0, ScrollPhysics? parent}) : super(parent: parent);

  @override
  FastScrollPhysics applyTo(ScrollPhysics? ancestor) {
    return FastScrollPhysics(
      speedFactor: speedFactor,
      parent: buildParent(ancestor),
    );
  }

  @override
  Simulation? createBallisticSimulation(
    ScrollMetrics position,
    double velocity,
  ) {
    return super.createBallisticSimulation(position, velocity * speedFactor);
  }
}

Unfortunately that doesn't work with multi page PDFs. E.g. when swiping right, the subsequent PDFs page are opened, but when user reaches the end the further swipe doesn't do anything, where in fact it should trigger scroll to next PageView page. Conversely when swiping left and reaching the beginning of the PDF, PageView doesn't go to the previous item.

tomekit avatar Mar 30 '25 20:03 tomekit