搜索插件、代码仓与 APP 分类

插件详情v1.0.1

power_file_view

一个强大的文件查看小部件,支持多种文件类型,如 Doc、Eexcl、PPT、TXT、PDF 等,Android 平台由腾讯 X5 实现,iOS 平台由 WKWebView 实现。

AndroidiOS
近 30 天下载
16
喜欢数
26
Pub 分数
130

安装插件

flutter pub add power_file_view

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

PowerFileView 是一个 Flutter 小部件,可实现对多种文件类型的无缝查看,包括 DOC、XLS、PPT、TXT 和 PDF。在 Android 上,它利用腾讯 X5 进行渲染,而在 iOS 上则使用 WKWebView。该包简化了在 Flutter 应用中集成文件预览的过程,提供可靠的跨平台支持,设置简单。非常适合需要文档浏览功能且无需依赖外部应用的应用程序。

适合场景

  • 移动应用中的文档预览
  • 教育平台的内部文件查看器
  • 商务应用文档共享
  • PDF 和办公文件显示
  • 离线文档访问

主要特点

  • 支持多种文件格式
  • 使用原生网页引擎(X5 和 WKWebView)
  • 跨平台兼容性
  • 与 Flutter 的轻松集成
  • 轻量级且快速渲染

适合对象

  • 教育类应用
  • 企业文档管理
  • 内容分发平台
  • 移动生产力工具
  • 具有文件共享功能的应用程序

使用建议

  • 需要互联网访问部分在线内容
  • 网页视图外观的自定义选项有限
  • 可能需要额外的权限才能访问文件
  • 依赖外部网络引擎的性能
  • 不适合复杂交互式文档

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

PowerFileView

pub package

English | 简体中文

A local file preview plugin, using PowerFileView, you can preview doc, docx, ppt, pptx, xls, xlsx, pdf and other files as easily as android and ios.

illustrate

  • Android uses Tencent TBS service, supports preview of doc, docx, ppt, pptx, xls, xlsx, pdf, txt, epub files
  • 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.

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

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

buildTypes {
        release {
            //Close delete useless resources
            shrinkResources false
            //Close delete useless code
            minifyEnabled false
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
2. TBS initialization

Since android uses the TBS service, it needs to be initialized before use, which takes about 3-30 seconds.

  1. 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.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  PowerFileViewManager.initEngine();
  runApp(const MyApp());
}
  1. Initialize when opening

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
  1. 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
  1. 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<PowerFileViewPage> createState() => _PowerFileViewPageState();
}

class _PowerFileViewPageState extends State<PowerFileViewPage> {
  @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.

 PowerFileViewWidget(
        downloadUrl: widget.downloadUrl,
        filePath: widget.downloadPath,
        loadingBuilder: (viewType, progress) {
          return Container(
            color: Colors.grey,
            alignment: Alignment.center,
            child: Text("Loading: $progress"),
          );
        },
        errorBuilder: (viewType) {
          return Container(
            color: Colors.red,
            alignment: Alignment.center,
            child: const Text("Something went wrong!!!!"),
          );
        },
      ),
5. HTTP configuration (optional)

If you need to use plaintext download, you need to configure the following

1. android

Create a new network_config.xml under android/app/src/main/res/xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true"/>
</network-security-config>

and configure in android/app/src/main/AndroidManifest.xml

<application
       android:networkSecurityConfig="@xml/network_config">
2. iOS

Make sure to add the following keys in ios/Runner/Info.plist

 <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。