flutter_file_view 1.1.1
flutter_file_view: ^1.1.1 copied to clipboard
File view plugin for Flutter, support local file and network link of Android, iOS
Flutter File View #
Language: 中文 | English
At present, the plugin is only used by Android, iOS
You can use FileLocalView to preview local files
You can use FileNetworkView to download the network link and
preview the file in combination with FileLocalView
Use of third-party plugins #
- Use
dioto make network requests - The v1.0.0 version no longer provides permission requests. It is recommended to
use
getTemporaryDirectory()as the target path, which can be implemented using the path_provider plugin
Preparing for use #
Version constraints #
sdk: ">=2.14.0 <3.0.0"
flutter: ">=2.5.0"
Flutter #
Add flutter_file_view to pubspec.yaml dependencies.
dependencies:
flutter_file_view: ^latest_version
iOS #
Make sure you add the following key to Info.plist for iOS
<key>io.flutter.embedded_views_preview</key><true/>
Android #
Android P Unable to download kernel Solution
Add a piece of code in label application on AndroidManifst.xml file
android:networkSecurityConfig="@xml/network_security_config"
Add a file named network_security_config.xml in res/xml directory, The content of the file is
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Local File Preview #
Android is implemented by Tencent X5, iOS is implemented by WKWebView.
Supported file type #
- Android
docx,doc,xlsx,xls,pptx,ppt,pdf,txt - IOS
docx,doc,xlsx,xls,pptx,ppt,pdf,txt,jpg,jpeg,png
Usage #
| Name | Type | Description | Default |
|---|---|---|---|
| filePath | String |
Local file address (full address) | Required |
| unSupportPlatformTip | String |
Platform prompts are not supported | 当前仅支持Android、iOS平台 |
| nonExistentFileTip | String |
Prompt that the file does not exist | 文件不存在 |
| fileFailTip | String |
File open failed tip | 文件打开失败 |
| loadingWidget | Widget |
Loading Widget | See source file |
| unSupportFileWidget | Widget |
Unsupported file widget | See source file |
Android special notes #
- The X5 kernel loading method has been integrated in the plugin
- Get the current kernel loading status through
getX5Status() - It can be initialized by itself through
initX5(). It is mainly used to solve the problem of unsuccessful download - Through the following scheme, kernel load listening can be realized after
initX5()call
FlutterFileView.initController.listen((res) {
EX5Status ex5status = res;
print(ex5status);
});
READ #
- Not Support Google Play, Reason: Issues 1.11
- Running on Android emulator is not supported
- If the txt document displays garbled code, please change the txt document code to GBK
Network Link View #
A network link view which based on the WeChat’s UI, with download function and view click effect
Usage #
| Name | Type | Description | Default |
|---|---|---|---|
| fileShowName | String |
The name of the file displayed on the page | Required |
| fileType | String |
The type of file | Required |
| downloadUrl | String |
File link to download | Required |
| downloadPath | String |
Storage address of downloaded files | Required |
| onViewPressed | VoidCallback |
File viewing function | Required |
| fileNameStyle | TextStyle |
TextType of fileShowName |
See source file |
| downloadTitle | Widget |
Button title when downloadable | 文件下载 |
| viewTitle | String |
Button title when viewable | 文件查看 |
| btnTitleColor | Color |
Button title color | Colors.white |
| btnBgColor | Color |
Button background color | Theme.of(context).primaryColor |
| borderSide | BorderSide |
Button border | ElevatedButton 默认 |
| cornerRadius | double |
Button radian | ElevatedButton 默认 |
Future Plans #
- Realize online viewing of network links. At present,
FileNetworkViewcan be used to view after downloading - Optimize the process of
FileLocalViewloading and reduce the jamming - Deal with the garbled TXT document