'Why does my flutter app keep crashing when loading pdf from the internet?

I am building an app in flutter that reads pdf files from the internet. The package I'm using is "advance_pdf_viewer." I have followed everything as instructed in the documentation. But my app always crashes a few seconds after showing the Circular Progress Indicator Widget.

Here's is my code

//@dart=2.9
import 'package:flutter/material.dart';
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';

class PDFviewerPage extends StatefulWidget {
  const PDFviewerPage({Key key}) : super(key: key);

  @override
  _PDFviewerPageState createState() => _PDFviewerPageState();
}

class _PDFviewerPageState extends State<PDFviewerPage> {
  bool _isLoading = true;
  PDFDocument _document;

  loadDocument() async {
    setState(() {
      _isLoading = true;
    });
    final document = await PDFDocument.fromURL(
        "https://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf");
    setState(() {
      _document = document;
      _isLoading = false;
    });
  }

  @override
  void initState() {
    super.initState();
    loadDocument();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Example'),
      ),
      body: _isLoading
          ? const Center(child: CircularProgressIndicator())
          : PDFViewer(document: _document),
    );
  }
}

Also, I have these permissions enabled in my manifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

This is the error message returned in my debug console [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getPage on channel flutter_plugin_pdf_viewer)

What could be the cause of the consistent crashing? And how do I fix it?



Solution 1:[1]

I actually solved the issue by replacing the package to flutter_pdfview: ^1.2.1

Solution 2:[2]

I had the same issue, the only thing that worked for me so far was using the previous version of the package:

(on pubspec.yaml)

advance_pdf_viewer: 2.0.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kings Samuel
Solution 2 Osmany Becerra Gonzalez