Flutter应用程式在读取PDF的发行模式时当机 [英] Flutter app crash on release mode reading PDF
问题描述
我的应用程序中有一个pdf阅读器,通过此功能,我可以从URL获取pdf并将文件保存在本地路径中
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");
}
}
此过程之后,我叫一个班级以新的路线显示此PDF
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()
],
),
);
}
}
所有功能都可以在调试模式下正常运行,但是当我在发行版上运行我的应用程序时,该应用程序在CustomPdfView中崩溃.
All works fine in debug mode, but when I run my app on release, the app crashes in CustomPdfView.
我不知道这是什么错误,我已经在/app/src/main/AndroidManifest.xml中添加了存储权限
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.
推荐答案
同一问题..... 我修好了那个
same issue..... i fixed that one
- 在构建APK后清理项目
如果问题仍然存在 比尝试这些命令
if still problem persist than try these commands
flutter build apk --no-shrink
flutter build apk --no-shrink
flutter build apk --release --split-per-abi --no-shrink
flutter build apk --release --split-per-abi --no-shrink
这篇关于Flutter应用程式在读取PDF的发行模式时当机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!