搜索分类、插件与代码仓

flutter_blurhash 封面
插件详情v0.9.1

flutter_blurhash

图像占位符的紧凑表示。将模糊图像编码为30个字符以下,以实现类似Medium的即时显示

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
27.8万
喜欢数
1720
Pub 分数
160

安装插件

flutter pub add flutter_blurhash

插件介绍

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

Flutter BlurHash 是一个轻量级包,可使用 BlurHash 编码实时生成图像的紧凑占位符。它将图像的模糊版本编码为一段短字符串(少于 30 个字符),可在加载时立即显示——非常适合提升图像密集型应用的感知性能。编码后的哈希值可直接渲染为占位符,模拟实际图像加载前的颜色和结构。该方法被 Medium 等平台广泛采用,以提升用户体验。

适合场景

  • 图像加载占位符
  • 媒体密集型应用中的性能优化
  • 在图像获取过程中即时视觉反馈
  • 渐进式图像渲染
  • 减少感知加载时间
  • 离线图像预览

主要特点

  • 超紧凑哈希表示
  • 实时占位符生成
  • 保留色彩的模糊效果
  • 跨平台支持
  • 与图像小部件的轻松集成
  • 低带宽使用

适合对象

  • 包含大量图片的应用
  • 内容推送
  • 社交媒体平台
  • 电子商务应用
  • 优先考虑流畅加载的UI
  • 寻求快速图像占位符的开发者

使用建议

  • 非常短的哈希值中细节有限
  • 不适合用于高保真预览
  • 需要在客户端进行解码
  • 最适合低分辨率占位符
  • 可能无法准确匹配复杂纹理
  • 哈希必须预先计算或在服务器端生成

原始 README

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

Flutter Community: flutter_blurhash

pub package Twitter

flutter_blurhash

Blurhash is compact representation of a blurred image. It's often used as a placeholder while waiting for a full image to load.

This package implements the blurhash-decoding algorithm in pure Dart. It also provides the BlurHash widget that displays the blurhash and can transition into the actual image once it is loaded.

Currently, it doesn't support encoding an image into a blurhash.

Generation

A fast and easy way to get a blurhash for your image is to upload it to https://blurha.sh.

Blurhash demo

Example

Constrain your widget's render area and let BlurHash fill the pixels.

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text("BlurHash")),
        body: const SizedBox.expand(
          child: Center(
            child: AspectRatio(
              aspectRatio: 1.6,
              child: BlurHash(hash: "L5H2EC=PM+yV0g-mq.wG9c010J}I"),
            ),
          ),
        ),
      ),
    );
  }
}

Optimization Modes

  • None (BlurHashOptimizationMode.none): The original algorithm, provided for backward compatibility.
  • Standard (BlurHashOptimizationMode.standard): Optimized decoding with better cache locality and performance.
  • Approximation (BlurHashOptimizationMode.approximation): Fastest mode with an approximated sRGB conversion that produces slightly darker results but significantly improves performance.
class BlurHashApp extends StatelessWidget {
  const BlurHashApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => MaterialApp(
    home: Scaffold(
      appBar: AppBar(title: const Text("BlurHash")),
      body: const SizedBox.expand(
        child: Center(
          child: AspectRatio(
            aspectRatio: 1.6,
            child: BlurHash(
              hash: "L5H2EC=PM+yV0g-mq.wG9c010J}I",
              optimizationMode: BlurHashOptimizationMode.approximation,
            ),
          ),
        ),
      ),
    ),
  );
}

所属分类

源码仓库

使用此插件的项目