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

blurhash_ffi 封面
插件详情v1.2.7

blurhash_ffi

一个紧凑、快速且易于使用的模糊图像占位符生成器,适用于 Flutter,使用原生 FFI 绑定。

AndroidiOSmacOSWindowsLinux
近 30 天下载
3150
喜欢数
107
Pub 分数
130

安装插件

flutter pub add blurhash_ffi

插件介绍

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

blurhash_ffi 是一个高性能的 Flutter 包,使用原生 FFI 绑定生成紧凑且视觉上吸引人的模糊图像占位符。它高效地编码和解码 BlurHash 字符串,实现快速占位符渲染,而无需依赖纯 Dart 实现。非常适合在图像加载期间提升感知性能,支持 Android、iOS、macOS、Windows 和 Linux。该包优先考虑速度和最小内存占用,同时保持视觉质量。

适合场景

  • 加载屏幕占位符
  • 图像画廊预览
  • 网络图像加载指示器
  • 离线内容占位符
  • 媒体密集型应用中的性能优化

主要特点

  • 原生 FFI 性能
  • 跨平台支持
  • 紧凑哈希编码
  • 快速解码
  • 低内存占用

适合对象

  • 加载大量图片的应用
  • 高性能UI需求
  • 寻求原生速度的开发者
  • 需要轻量级占位符的项目
  • 跨平台 Flutter 应用

使用建议

  • 需要原生编译设置
  • 仅限 BlurHash 格式
  • 可能会略微增加应用大小
  • 不适用于复杂的图像处理
  • 依赖于平台特定的 FFI 库

原始 README

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

blurhash_ffi

A Blurhash compact Image placeholder encoder and decoder FFI implementation for Flutter in Rust via experemental feature Native Assets.

Matches the official Blurhash implementation in performance and quality.

blurhash_ffi

Supports

Platform Status Description
Android ✅ -
iOS ✅ -
macOS ✅ -
Linux ⚠️ Not tested
Windows ✅ -
Web ❌ Rust can compiled to WebAssembly, but no supported yet. This library compiled on standalone wasm module (not in Empscripten, AssemblyScript) that Dart can't be use non-JS enviroments. Also, Dart should use FFI bindings for call wasm module. Stopped issues: comment

Installation

Add dependency to your pubspec.yaml file following the command below:

For dart projects:

dart pub add dart_blurhash_ffi

For flutter projects:

dart pub add flutter_blurhash_ffi

Usage

To use this plugin, add blurhash_ffi as a dependency in your pubspec.yaml file

Flutter usage

import 'package:flutter_blurhash_ffi/flutter_blurhash_ffi.dart';

/// Encoding and Decoding all in One Step
///
/// `ImageProvider` in    -> Send your Image to be encoded.
/// `ImageProvider` out   -> Get your blurry image version.
class BlurhashMyImage extends StatelessWidget {
  final String imageUrl;
  const BlurhashMyImage({required this.imageUrl, super.key});

  @override
  Widget build(BuildContext context) {
    return Image(
      image: BlurhashFfiImage.fromImageProvider(
        NetworkImage(imageUrl),  // you can use any image provider of your choice.
        decodingHeight: 1920,
        decodingWidth: 1080,
      ),
      alignment: Alignment.center,
      fit: BoxFit.cover
    );
  }
}


class BlurhashMyImage2 extends StatelessWidget {
  final String blurhash;
  const BlurhashMyImage2({required this.blurhash, super.key});

  @override
  Widget build(BuildContext context) {
    return Image(
      image: BlurhashFfiImage(blurhash),
      width: 200,
      height: 200,
      alignment: Alignment.center,
      fit: BoxFit.cover
    );
  }
}

[!WARNING] Not recommend use it (without blurhash string param), because in this case, encoding and decoding will be performed. This effect can be obtained almost through ImageFiltered.

Encoding

Encoding now uses sync interface (without Future).

import 'package:dart_blurhash_ffi/dart_blurhash_ffi.dart';

final Uint8List blurhashImageBytes = File('assets/image.webp').readAsBytesSync();

/// Signature
/// static String encode(
///   Uint8List data, {
///   int componentX = 4,
///   int componentY = 3,
/// })
/// may throw `BlurhashFFIException` if encoding fails.
final String blurHash = BlurhashFFI.encode(blurhashImageBytes);

// Or via codec

final String blurHashSame = BlurhashFfiCodec().encoder.convert(blurhashImageBytes);

Decoding

Decoding now uses sync interface (without Future).

import 'package:dart_blurhash_ffi/dart_blurhash_ffi.dart';

final String blurhash = 'LGFO~6Yk^6#M@-5c,1Ex@@or[j6o';

/// Signature
///
/// static Uint8List decode(
///   String blurhash, {
///   int width = 32,
///   int height = 32,
///   int punch = 1,
/// })
/// may throw `BlurhashFFIException` if decoding fails.
final decoded = BlurhashFFI.decode(blurhash);

// or via codec

final String decodedSame = BlurhashFfiCodec().decoder.convert(blurhash);

Check the example for more details

contributions in the form of PR's and Issues are a welcome

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。