패키지, 저장소 및 앱 카테고리 검색

패키지 상세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는 DOC, XLS, PPT, TXT 및 PDF를 포함한 여러 파일 형식을 원활하게 볼 수 있도록 해주는 플러터 위젯입니다. 안드로이드에서는 렌더링에 텐센트 X5를 사용하고, iOS에서는 WKWebView를 사용합니다. 이 패키지는 플러터 앱 내에서 파일 미리보기 기능을 쉽게 통합할 수 있게 하며, 최소한의 설정으로 신뢰할 수 있는 크로스플랫폼 지원을 제공합니다. 외부 앱 의존 없이 문서 브라우징이 필요한 애플리케이션에 적합합니다.

사용 사례

  • 모바일 앱에서 문서 미리보기
  • 교육 플랫폼용 내부 파일 뷰어
  • 비즈니스 앱 문서 공유
  • 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.