Home > other >  Emulator crashes with lost connection to device while trying to read pdf
Emulator crashes with lost connection to device while trying to read pdf

Time:08-31

I have a following screen, that gets a pdf or file from the next page. But when I try to read PDF, the emulator crashes with 'Lost Connection to Device' and following error. I am using advanced_pdf_viewer for reading the pdf. This issue is only with android and not ios

Error : I/System.out( 5829): Already closed W/System.err( 5829): java.lang.IllegalStateException: Already closed D/PdfViewerPlugin( 5829): Retrieving page failed. D/AndroidRuntime( 5829): Shutting down VM E/flutter ( 5829): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method getPage on channel flutter_plugin_pdf_viewer)

class FilePage extends StatefulWidget {
  const FilePage({this.file, this.isImage = false});
  final FirebaseFile? file;
  final isImage;
  @override
  _FilePageState createState() => _FilePageState();
}

class _FilePageState extends State<FilePage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    //final isPdf = ['.pdf', 'pdf', '.PDF', 'PDF'].any(file.name.contains);
    //final isEpub = ['.epub'].any(file.name.contains);
    // final isImg = ['.jpg', '.JPG', '.png', '.PNG', '.jpeg', '.JPEG']
    //   .any(file.name.contains);
    //  int _totalPages=0;
    //   int _currentPage=0;
    //   bool pdfReady=false;
    //   PDFViewController _pdfViewController;

    //initState(){
    return WillPopScope(
      onWillPop: () async => true,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.indigo[900],
          title: Text(widget.file!.name.split('.').first),
          centerTitle: true,
        ),
        body: FutureBuilder(
            future: PDFDocument.fromURL(widget.file!.url),
            builder: (context, snapshot) {
              switch (snapshot.connectionState) {
                case ConnectionState.waiting:
                case ConnectionState.active:
                  return Center(
                    child: CircularProgressIndicator(),
                  );
                default:
                  var pdf = snapshot.data as PDFDocument;
                  return PDFViewer(document: pdf);
              }
            }),
      ),
    );
  }
}

CodePudding user response:

Try this.

 flutter clean
 flutter run
  

CodePudding user response:

I don't know what is the real problem behind this but you can try these simple steps.

  1. flutter clean (in terminal)
  2. Restart your code editor
  3. pub get (in terminal)
  4. Cold boot your emulator
  • Related