FLUTTER ECOSYSTEM

mirkancal/pdf_thumbnail

mirkancal/pdf_thumbnail open-source repository details.

pdf_thumbnail のプロジェクト画像
Stars
6
Forks
10
最終プッシュ(UTC)
2024/02/11
プロジェクト状態
公開中
mirkancal GitHub avatar
GITHUB User

mirkancal ↗

言語Dart

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 5 件

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

README を開く / 閉じる

Pdf Thumbnail

style: very good analysis Powered by Mason License: MIT

Thumbnail viewer for pdfs

Installation 💻

❗ In order to start using Pdf Thumbnail you must have the Flutter SDK installed on your machine.

Add pdf_thumbnail to your pubspec.yaml:

dependencies:
  pdf_thumbnail:

Install it:

flutter packages get

Example ✍️

 return Stack(
              children: [
                SizedBox(
                  height: MediaQuery.of(context).size.height,
                  width: MediaQuery.of(context).size.width,
                  child: PdfViewer(
                    filePath: snapshot.data!.path,
                  ),
                ),
                if (showThumbnail)
                  Positioned(
                    bottom: 0,
                    width: MediaQuery.of(context).size.width,
                    // Here's the thumbnail widget.
                    child: PdfThumbnail.fromFile(snapshot.data!.path),
                  ),
              ],
            );

There is a detailed example app in the repo, but I've deleted iOS and Android folders. Simple go to example folder, and run flutter create . inside the folder to add missing native files for the example app.

Demo

gif

Caching ⏲

I left caching part unopinionated to keep the package simple. Just create your own class from ImageThumbnailCacher and implement the read/write methods. Holding images as Uint8List, so Map<int, Uint8List> is what's need to be written to and read from the cache. It maps page numbers to the images.

class ThumbnailCacher implements ImageThumbnailCacher {
  @override
  Future<PageToImage?> read(String id) async {
    return api.localStorage.readThumbnails(id);
  }

  @override
  Future<bool> write({required String id, required PageToImage map}) {
    return api.localStorage.writeThumbnails(id: id, map: map);
  }
}

I'm using Hive to cache.

Roadmap 🗺️

  • [X] Customization for colors, decoration etc.
  • [X] onTap callback and page number.
  • [X] Caching.
  • [ ] Different layouts and scroll axises.
  • [ ] Lazy loading.