Flutter app crash on release mode reading PDF

Viewed 2150

I have a pdf reader in my app, with this function I get de pdf from URL and save the file in local path

  Future<File> getFileFromUrl(String url) async {
    try {
      var data = await http.get(url);
      var bytes = data.bodyBytes;
      var dir = await getApplicationSupportDirectory();
      File file = File("${dir.path}/some.pdf");

      File urlFile = await file.writeAsBytes(bytes);
      return urlFile;
    } catch (e) {
      throw Exception("Error opening url file");
    }
  }

After this process, I call a class to show this PDF in a new route

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

class CustomPdfView extends StatefulWidget {
  final String title;
  final String urlPdf;

  CustomPdfView(
    this.title,
    this.urlPdf
  );

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

class _CustomPdfViewState extends State<CustomPdfView> {
  //int _totalPages = 0;
  //int _currentPage = 0;
  bool pdfReady = false;
  //PDFViewController _pdfViewController;

  @override
  Widget build(BuildContext context) {
    print('Aqui entra antes: ${widget.urlPdf}');
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Stack(
        children: <Widget>[
          PDFView(
            filePath: widget.urlPdf,
            autoSpacing: true,
            enableSwipe: true,
            pageSnap: true,
            swipeHorizontal: true,
            nightMode: false,
            onError: (e) {
              print("error $e");
            },
            onRender: (_pages) {
              setState(() {
                //_totalPages = _pages;
                pdfReady = true;
              });
            },
            onViewCreated: (PDFViewController vc) {
              //_pdfViewController = vc;
            },
            onPageChanged: (int page, int total) {
              setState(() {});
            },
            onPageError: (page, e) {},
          ),
          !pdfReady
              ? Center(
                  child: CircularProgressIndicator(),
                )
              : Offstage()
        ],
      ),
    );
  }
}

All works fine in debug mode, but when I run my app on release, the app crashes in CustomPdfView.

I don't know what is the error, I already added, STORAGE permissions in my /app/src/main/AndroidManifest.xml

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

And I don't know how can I get error line in the console, because the app is running on release.

1 Answers

same issue..... i fixed that one

  1. clean your project after build your apk

if still problem persist than try these commands

flutter build apk --no-shrink

flutter build apk --release --split-per-abi --no-shrink

Related