简体   繁体   中英

Flutter app crashing while using flutter_pdfview package

Package: flutter_pdfview

My app crashes when the pdf downloading is completed in apk I build using flutter apk build .

At the same operation in debugging after downloading is finished console gives an error but does not crashes and pdf_viewer works fine.

 W/System  (31159): A resource failed to call release.

Please suggest what i can do to stop my app to crash after downloading the file.

Code is like this

import 'dart:async';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';

class PdfViewerPage extends StatefulWidget {
  final name;
  final title;
  PdfViewerPage({this.name, this.title});
  @override
  _PdfViewerPageState createState() => _PdfViewerPageState();
}

class _PdfViewerPageState extends State<PdfViewerPage> {
  bool loading = true;
  String localfile;
  int current = 1;
  int total;

  Future<String> loaddata() async {
    var dir = await getTemporaryDirectory();
    File file = new File(dir.path + widget.name);

    await FirebaseStorage()
        .ref()
        .child(widget.name)
        .getData(50000000)
        .then((value) async {
      file.writeAsBytes(value);
    }).catchError((onError) {
      Fluttertoast.showToast(msg: onError);
    });
    return file.path;
  }

  @override
  void initState() {
    super.initState();
    loaddata().then((value) {
      setState(() {
        localfile = value;
        loading = false;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      appBar: AppBar(
        title: Text(widget.title, style: TextStyle(color: Colors.black)),
      ),
      body: loading
          ? Center(
              child: CircularProgressIndicator(),
            )
          : PDFView(
              filePath: localfile,
              fitEachPage: true,
              onPageChanged: (t, c) {
                setState(() {
                  current = t + 1;
                  total = c;
                });
              },
            ),
      floatingActionButton: total != null
          ? FloatingActionButton.extended(
              backgroundColor: Colors.white,
              onPressed: () {},
              label: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  Text(current.toString()),
                  SizedBox(
                    width: 20,
                  ),
                  Text(total.toString())
                ],
              ))
          : Container(),
    ));
  }
}

I found a similar Question on StackOverflow link .

When we build apk from the code, Flutter blocks the plugin code which results in crashing of the app. Solution is to use progaurd rules to enable the pdf plugin to work. ProGaurd rules are mentioned in the link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM