ScerIO / packages.flutter

👨‍💻 Plugins and packages for Flutter framework
https://pub.dev/publishers/serge.software/packages
MIT License
462 stars 456 forks source link

Not able to open pdf from internal storage #179

Open adityakontikal opened 3 years ago

adityakontikal commented 3 years ago

Describe the bug Not able to open pdf from internal storage, But its working fine with the project assets files.

`import 'dart:io';

import 'package:flutter/material.dart';
import 'package:native_pdf_view/native_pdf_view.dart';

class Pdf extends StatefulWidget {
  final PdfController pdfController;
  final String path;
  Pdf({this.pdfController, this.path});

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

class _PdfState extends State<Pdf> {
  final sample = PdfController(
    document: PdfDocument.openAsset('assets/report.pdf'),
  );
  bool isLoaded = false;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: PdfView(
        controller:
            // sample,
            PdfController(
          document: PdfDocument.openFile(widget.path),
        ),
        onDocumentLoaded: (document) {
          setState(() {
            isLoaded = true;
          });
        },
        pageLoader: Center(child: CircularProgressIndicator()),
      ),
    );
  }
}
`

Error causing widget was PdfView line 25


`D/PDF_RENDER( 4749): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf
D/PDF_RENDER( 4749): OpenAssetDocument. Created file: /data/user/0/com.example.doc_holder/cache/02ca37d1b265469b8c30069dc19871cf.pdf
D/PDF_RENDER( 4749): OpenFileDocument. File: /data/user/0/com.example.doc_holder/cache/02ca37d1b265469b8c30069dc19871cf.pdf
D/PDF_RENDER( 4749): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf

════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building PdfView(dirty, state: _PdfViewState#b86e0):
Null check operator used on a null value

The relevant error-causing widget was
PdfView
lib/const/pdf.dart:23
When the exception was thrown, this was the stack
#0      _PdfViewState._buildLoaded
package:native_pdf_view/src/native_pdf_view.dart:172
#1      _PdfViewState.build
package:native_pdf_view/src/native_pdf_view.dart:205
#2      StatefulElement.build
package:flutter/…/widgets/framework.dart:4683
#3      ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4566
#4      StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4738
...
`

To Reproduce Steps to reproduce the behavior:

  1. Call this stateful class from anywhere
  2. pass a optional parameter path (internal storage file with .pdf extension )
  3. exapmle of the path: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf

Expected behavior Load the pdf file as it usually loads a assets file

Smartphone (please complete the following information):

vicelikedust commented 3 years ago

I seem to being having the same issue as well