ScerIO Flutter Packages

repository·main·Indexed 19 days ago

https://github.com/scerio/packages.flutter

A collection of Flutter packages and plugins maintained by ScerIO. Includes auto_animated for scroll-based animations (LiveList, LiveGrid, LiveIconButton), epub_view for displaying and navigating EPUB documents using EpubController and EpubCfi, and explorer for implementing universal file and navigation explorer UIs with customizable ExplorerProviders.

Tokens
19.6K
Snippets
69
Records
84
Agent score
66%

What's inside scerio-packages.flutter

  1. Available Flutter packages and plugins

    main

    The scerio/packages.flutter repository contains several active Flutter packages. Use the following list to identify the correct package for your needs:

    • auto_animated: Animation utilities.
    • flutter_color: Color-related utilities.
    • pdfx: PDF rendering and viewing.
    • epub_view: EPUB file viewing.
    • explorer: File explorer capabilities.
  2. How to save and restore reading position using EpubCfi

    main

    You can maintain the exact reading position (even within a chapter) by using EPUB CFI strings.

    1. To restore position: Pass the saved CFI string to the epubCfi parameter in the EpubController constructor.
    2. To get current position: Call _epubController.generateEpubCfi() to get the current CFI string.
    3. To navigate: Use _epubController.gotoEpubCfi('cfi_string') to jump to a specific location.
    // 1. Initialize with saved CFI
    _epubController = EpubController(
      epubCfi: 'epubcfi(/6/6[chapter-2]!/4/2/1612)',
    );
    
    // 2. Attach to view
    EpubView(controller: _epubController);
    
    // 3. Get current CFI to save for later
    final cfi = _epubController.generateEpubCfi();
    
    // 4. Or navigate manually
    _epubController.gotoEpubCfi('epubcfi(/6/6[chapter-2]!/4/2/1612)');
  3. Target specific packages with the --packages flag

    main

    Most commands in flutter_plugin_tools accept a --packages argument to specify the target. You can provide:

    • A package name: e.g., path_provider_android.
    • A federated plugin name: e.g., path_provider (this targets all packages making up that plugin).
    • A combination: federated_plugin_name/package_name (e.g., path_provider/path_provider for the app-facing package).
  4. Quickstart: Display a PDF document

    main

    PDFx provides two main ways to display documents depending on the desired user experience:

    1. PdfViewPinch: Best for high-quality zooming. It re-renders the PDF texture on zoom so quality is not lost. Note: This is not supported on Windows.
    2. PdfView: A simple view that renders the page once. Zooming will result in loss of quality.

    Example Implementation

    import 'package:pdfx/pdfx.dart';
    
    // 1. High-quality pinch view (Web, MacOS, Android, iOS)
    final pdfPinchController = PdfControllerPinch(
      document: PdfDocument.openAsset('assets/sample.pdf'),
    );
    
    PdfViewPinch(
      controller: pdfPinchController,
    );
    
    // 2. Simple view (All platforms including Windows)
    final pdfController = PdfController(
      document: PdfDocument.openAsset('assets/sample.pdf'),
    );
    
    PdfView(
      controller: pdfController,
    );
    import 'package:pdfx/pdfx.dart';
    
    final pdfPinchController = PdfControllerPinch(
      document: PdfDocument.openAsset('assets/sample.pdf'),
    );
    
    PdfViewPinch(
      controller: pdfPinchController,
    );
    
    //-- or --//
    
    final pdfController = PdfController(
      document: PdfDocument.openAsset('assets/sample.pdf'),
    );
    
    PdfView(
      controller: pdfController,
    );
  5. Run native platform tests

    main

    The native-test command runs unit tests and (optionally) integration tests on specific platforms. Use platform flags like --ios, --android, or --macos.

    By default, it runs both unit and integration tests. Use --no-unit or --no-integration to isolate the test type.

    Examples

    Run only unit tests for iOS and Android:

    dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --ios --android --no-integration --packages plugin_name

    Run all tests (unit and integration) for macOS:

    dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --macos --packages plugin_name
    dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --ios --android --no-integration --packages plugin_name
  6. Install PDFx

    main

    To use PDFx in your Flutter project, add the dependency via pub:

    flutter pub add pdfx

    Platform Specific Setup

    Web: You must run the following tool to automatically add the pdfjs library (via CDN) to your index.html:

    flutter pub run pdfx:install_web

    Windows: You must run the following tool to automatically add the override for the pdfium version property in your CMakeLists.txt file:

    flutter pub run pdfx:install_windows
    flutter pub add pdfx
  7. Install and run Flutter Plugin Tools

    main

    Depending on your environment, you can use the tool either from source or via the published version.

    Use this method if you are working directly within the flutter/plugins repository.

    1. Set up dependencies:
      cd ./script/tool && dart pub get && cd ../../
    2. Run the tool:
      dart run ./script/tool/bin/flutter_plugin_tools.dart <args>

    Use this method if you are working in flutter/packages. Note that the package is marked as Discontinued but is still used for updates in flutter/packages.

    1. Activate the tool globally:
      dart pub global activate flutter_plugin_tools
    2. Run the tool:
      dart pub global run flutter_plugin_tools <args>

    Note: Commands are designed to be run from the repository root or <repository-root>/packages/.

    cd ./script/tool && dart pub get && cd ../../
    dart run ./script/tool/bin/flutter_plugin_tools.dart <args>
  8. Open and render PDF documents with `pdfx`

    main

    To use pdfx for PDF rendering, you can open documents from assets, raw data, or local file paths using the PdfDocument class. Once a document is opened, you can access specific pages using getPage(int pageNumber).

    Important Notes:

    • Page Indexing: Page numbers start from 1, not 0.
    • Resource Management: On Android, you must call await page.close() on a page before opening or rendering a new one, as the platform does not support parallel rendering.
    • Rendering Quality: Use the render method on a PdfPage object. You can increase image quality by multiplying the width and height parameters.
    • Visuals: Rendered images include an alpha channel. If your PDF has black text, ensure your UI has a white background (e.g., Scaffold(backgroundColor: Colors.white)) so the text is visible.
    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart';
    import 'package:pdfx/pdf_renderer.dart';
    
    void main() async {
      try {
        // 1. Open the document
        final document = await PdfDocument.openAsset('assets/sample.pdf');
    
        // 2. Get a page (Note: page numbers start at 1)
        final page = await document.getPage(1);
    
        // 3. Render the page to an image
        final pageImage = await page.render(width: page.width, height: page.height);
    
        // 4. Close the page before opening another (Required for Android)
        await page.close();
    
        // 5. Use the image bytes in a widget
        // Image(image: MemoryImage(pageImage.bytes))
    
      } on PlatformException catch (error) {
        print(error);
      }
    }
  9. Customize the iOS launch screen assets

    main

    To change the image displayed on the iOS launch screen, you can either replace the image files directly in the project directory or use Xcode.

    Method 1: Direct File Replacement

    Replace the existing image files located in the LaunchImage.imageset directory with your own assets.

    Method 2: Using Xcode

    1. Open the iOS workspace in Xcode by running open ios/Runner.xcworkspace from your terminal.
    2. In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog to replace the existing launch screen images.
    open ios/Runner.xcworkspace