简体   繁体   English

Flutter 应用程序在使用 flutter_pdfview package 时崩溃

[英]Flutter app crashing while using flutter_pdfview package

Package: flutter_pdfview Package: flutter_pdfview

My app crashes when the pdf downloading is completed in apk I build using flutter apk build .当 pdf 下载在我使用flutter apk build 构建的 apk 中完成时,我的应用程序崩溃。

At the same operation in debugging after downloading is finished console gives an error but does not crashes and pdf_viewer works fine.在下载完成后调试的同一操作中,控制台会出错但不会崩溃,并且 pdf_viewer 工作正常。

 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 .我在 StackOverflow 链接上发现了一个类似的问题。

When we build apk from the code, Flutter blocks the plugin code which results in crashing of the app.当我们从代码构建 apk 时,Flutter 会阻止插件代码,从而导致应用程序崩溃。 Solution is to use progaurd rules to enable the pdf plugin to work.解决方案是使用 progaurd 规则来启用 pdf 插件工作。 ProGaurd rules are mentioned in the link.链接中提到了 ProGaurd 规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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