PowerFileView - A powerful file view widget, support a variety of file types, such as Doc Eexcl PPT TXT PDF and so on, Android is implemented by Tencent X5, iOS is implemented by WKWebView.
ios uses WKWebView, all supported by WKWebView can be previewed
Supported formats
Format
android
ios
.doc
✅
✅
.docx
✅
✅
.ppt
✅
✅
.pptx
✅
✅
.xls
✅
✅
.xlsx
✅
✅
.pdf
✅
✅
Integration
1. Dependency
Add under the pubspec.yaml file:
power_file_view: ^1.0.0
2. Quick integration
1. Android
Since using android to use TBS service, network permission and storage permission are required. Add the following permissions to the AndroidManifest file of Android.
">
In order to prevent the release version from failing to load the TBS kernel library. Add the following code to the obfuscation file proguard-rules.pro.
-dontwarn dalvik.**
-dontwarn com.tencent.smtt.**
-keep class com.tencent.smtt.** {
*;
}
-keep class com.tencent.tbs.** {
*;
}
Then enable delete useless resources in build.gradle, which can be configured as shown in the following figure
Since android uses the TBS service, it needs to be initialized before use, which takes about 3-30 seconds.
Asynchronous initialization (recommended)
Asynchronous initialization can be performed under the main function of the app's main.dart file, so that the user does not need to wait for TBS initialization when opening the file.
If the asynchronous initialization configuration is not performed, the initialization operation will be performed automatically before the file is opened, and the user does not need to configure
4. Quick use
file preview
Network files: Just pass in the downloadUrl of the file to be previewed and the downloadPath of the storage path of the file to download.
define downloadPath
import 'package:path_provider/path_provider.dart';
...
final _directory = await getTemporaryDirectory();
final downloadPath = "${_directory.path}/fileview/"fileName.pdf";//Set a name you like
Local file: Just pass in the downloadPath of the path where the local file is located.
class PowerFileViewPage extends StatefulWidget {
final String downloadUrl;
final String downloadPath;
const PowerFileViewPage({Key? key, required this.downloadUrl, required this.downloadPath}) : super(key: key);
@override
State createState() => _PowerFileViewPageState();
}
class _PowerFileViewPageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('File Preview'),
),
body: PowerFileViewWidget(
downloadUrl: widget.downloadUrl,
filePath: widget.downloadPath,
),
);
}
}
Custom progress display and error display
You can customize the display style of progress loading and the display style of errors in loadingBuilder and errorBuilder.
We found that your app is using Tencent TBS SDK which contains code to download executable code (e.g. dex, JAR, .so files) from a source other than Google Play.
?? Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.