lohanidamodar / pdf_viewer

A flutter plugin for handling PDF files. Works on both Android & iOS
https://pub.dev/packages/advance_pdf_viewer
BSD 3-Clause "New" or "Revised" License
61 stars 145 forks source link

Unable to JumpTo particular page after load from url #118

Open mumairofficial opened 1 year ago

mumairofficial commented 1 year ago

I am trying to jump to a specific page once the PDF file is loaded from either URL or File. Here is what I have tried, not sure what's wrong.

class _PublicationReaderScreenState extends State<PublicationReaderScreen> {
  late PDFDocument document;
  bool _loading = true;
  final PageController _pageController = PageController();

  @override
  void initState() {
    super.initState();
    loadDocument();
    // _pageController.jumpTo(5.0);
  }

  loadDocument() async {
    document = await PDFDocument.fromURL(widget.publication.downloadUrl);
    setState(() {
      _loading = false;
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 1,
      ),
      body: _loading
          ? const Center(child: CircularProgressIndicator())
          : PDFViewer(
              document: document,
              zoomSteps: 1,
              lazyLoad: true,
              pickerButtonColor: Theme.of(context).colorScheme.primary,
              controller: _pageController,
              showIndicator: true,
              onPageChanged: (int p) {
                print(p+1);
              },
            ),
    );
  }
}

Tried PageController but no success!