Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdf from asset path #110

Closed
sahmirzali opened this issue Oct 16, 2020 · 1 comment
Closed

pdf from asset path #110

sahmirzali opened this issue Oct 16, 2020 · 1 comment

Comments

@sahmirzali
Copy link

sahmirzali commented Oct 16, 2020

Hello. May i give path like that ? or how can i give ?

like that is not working

        PDFView(
       ----> filePath: 'assets/poladqara.pdf',  <----
                enableSwipe: true,
                swipeHorizontal: true,
                autoSpacing: true,

                pageFling: true,
                pageSnap: true,
                defaultPage: currentPage,
                fitPolicy: FitPolicy.BOTH,
@sahmirzali
Copy link
Author

@override
  void initState() {
    super.initState();
    fromAsset('pdf_asset/poladwhite.pdf', 'poladwhite.pdf').then((f) {
      setState(() {
        whitepathPDF = f.path;
      });
    });
     fromAsset('pdf_asset/poladblack.pdf', 'poladblack.pdf').then((f) {
      setState(() {
        blackpathPDF = f.path;
      });
    });
  }

  Future<File> fromAsset(String asset, String filename) async {
    // To open from assets, you can copy them to the app storage folder, and the access them "locally"
    Completer<File> completer = Completer();

    try {
      var dir = await getApplicationDocumentsDirectory();
      File file = File("${dir.path}/$filename");
      var data = await rootBundle.load(asset);
      var bytes = data.buffer.asUint8List();
      await file.writeAsBytes(bytes, flush: true);
      completer.complete(file);
    } catch (e) {
      throw Exception('Error parsing asset file!');
    }

    return completer.future;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant