Token导航 LogoToken导航TokenDH.com
待分类需要联网github未标认证来源可访问许可证需确认审计通过

flutter-caching-dataFlutter caching 数据

Agent Skill

用于辅助数据整理、表格处理、CSV/Excel 分析、指标计算和图表准备。它适合让 Agent 清洗字段、汇总数据、发现异常、生成统计口径或把分析结果转成可读说明。使用时需要确认数据来源、字段含义和时间范围,避免把样本数据当全量事实;涉及敏感数据、导出文件或批量写回时,应先确认权限和脱敏边界。

总安装

202,536

周安装

8,718

GitHub Stars

1,322

下载量

70,992
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:flutter-caching-data(Flutter caching 数据)
来源仓库:https://github.com/flutter/skills
仓库路径:skills/flutter-caching-data
安装命令:
npx skills add https://github.com/flutter/skills --skill flutter-caching-data
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/flutter/skills --skill flutter-caching-data

简介

Flutter 应用程序的本地数据缓存和离线优先同步模式。

  • 涵盖五种缓存策略:shared_preferences
  • 用于 UI 状态、用于结构化数据的 SQLite/Hive、用于二进制媒体的文件系统、用于导航的状态恢复以及 Android 上的 FlutterEngine 预热
  • 使用读取流(本地生成、远程获取、更新缓存)和双重写入策略(仅在线与后台同步的离线优先)实现离线优先存储库
  • 使用cached_network_image优化图像缓存
  • 、自定义ImageProvider
  • 实现和可配置的 ImageCache.maxByteSize
  • 提供滚动和小部件缓存最佳实践,包括scrollCacheExtent
  • 避免操作符==的配置和指导
  • 覆盖父小部件
  • 包括两个完整的工作流程:构建具有同步标志的离线优先存储库以及预热 Android FlutterEngine 以实现快速初始化

SKILL.md

Implementing Flutter Caching and Offline-First Architectures

Contents

Selecting a Caching Strategy

Apply the appropriate caching mechanism based on the data lifecycle and size requirements.

  • If storing small, non-critical UI states or preferences: Use shared_preferences.
  • If storing large, structured datasets: Use on-device databases (SQLite via sqflite, Drift, Hive CE, or Isar).
  • If storing binary data or large media: Use file system caching via path_provider.
  • If retaining user session state (navigation, scroll positions): Implement Flutter's built-in state restoration to sync the Element tree with the engine.
  • If optimizing Android initialization: Pre-warm and cache the FlutterEngine.

Implementing Offline-First Data Synchronization

Design repositories as the single source of truth, combining local databases and remote API clients.

Read Operations (Stream Approach)

Yield local data immediately for fast UI rendering, then fetch remote data, update the local cache, and yield the fresh data.

Stream<UserProfile> getUserProfile() async* {
  // 1. Yield local cache first
  final localProfile = await _databaseService.fetchUserProfile();
  if (localProfile != null) yield localProfile;

  // 2. Fetch remote, update cache, yield fresh data
  try {
    final remoteProfile = await _apiClientService.getUserProfile();
    await _databaseService.updateUserProfile(remoteProfile);
    yield remoteProfile;
  } catch (e) {
    // Handle network failure; UI already has local data
  }
}

Write Operations

Determine the write strategy based on data criticality:

  • If strict server synchronization is required (Online-only): Attempt the API call first. Only update the local database if the API call succeeds.
  • If offline availability is prioritized (Offline-first): Write to the local database immediately. Attempt the API call. If the API call fails, flag the local record for background synchronization.

Background Synchronization

Add a synchronized boolean flag to your data models. Run a periodic background task (e.g., via workmanager or a Timer) to push unsynchronized local changes to the server.

Managing File System and SQLite Persistence

File System Caching

Use path_provider to locate the correct directory.

  • Use getApplicationDocumentsDirectory() for persistent data.
  • Use getTemporaryDirectory() for cache data the OS can clear.
Future<File> get _localFile async {
  final directory = await getApplicationDocumentsDirectory();
  return File('${directory.path}/cache.txt');
}

SQLite Persistence

Use sqflite for relational data caching. Always use whereArgs to prevent SQL injection.

Future<void> updateCachedRecord(Record record) async {
  final db = await database;
  await db.update(
    'records',
    record.toMap(),
    where: 'id = ?',
    whereArgs: [record.id], // NEVER use string interpolation here
  );
}

Optimizing UI, Scroll, and Image Caching

Image Caching

Image I/O and decompression are expensive.

  • Use the cached_network_image package to handle file-system caching of remote images.
  • Custom ImageProviders: If implementing a custom ImageProvider, override createStream() and resolveStreamForKey() instead of the deprecated resolve() method.
  • Cache Sizing: The ImageCache.maxByteSize no longer automatically expands for large images. If loading images larger than the default cache size, manually increase ImageCache.maxByteSize or subclass ImageCache to implement custom eviction logic.

Scroll Caching

When configuring caching for scrollable widgets (ListView, GridView, Viewport), use the scrollCacheExtent property with a ScrollCacheExtent object. Do not use the deprecated cacheExtent and cacheExtentStyle properties.

// Correct implementation
ListView(
  scrollCacheExtent: const ScrollCacheExtent.pixels(500.0),
  children: // ...
)

Viewport(
  scrollCacheExtent: const ScrollCacheExtent.viewport(0.5),
  slivers: // ...
)

Widget Caching

  • Avoid overriding operator == on Widget objects. It causes O(N²) behavior during rebuilds.
  • Exception: You may override operator == *only* on leaf widgets (no children) where comparing properties is significantly faster than rebuilding, and the properties rarely change.
  • Prefer using const constructors to allow the framework to short-circuit rebuilds automatically.

Caching the FlutterEngine (Android)

To eliminate the non-trivial warm-up time of a FlutterEngine when adding Flutter to an existing Android app, pre-warm and cache the engine.

  1. Instantiate and pre-warm the engine in the Application class.
  2. Store it in the FlutterEngineCache.
  3. Retrieve it using withCachedEngine in the FlutterActivity or FlutterFragment.
// 1. Pre-warm in Application class
val flutterEngine = FlutterEngine(this)
flutterEngine.navigationChannel.setInitialRoute("/cached_route")
flutterEngine.dartExecutor.executeDartEntrypoint(DartEntrypoint.createDefault())

// 2. Cache the engine
FlutterEngineCache.getInstance().put("my_engine_id", flutterEngine)

// 3. Use in Activity/Fragment
startActivity(
  FlutterActivity.withCachedEngine("my_engine_id").build(this)
)

*Note: You cannot set an initial route via the Activity/Fragment builder when using a cached engine. Set the initial route on the engine's navigation channel before executing the Dart entrypoint.*

Workflows

Workflow: Implementing an Offline-First Repository

Follow these steps to implement a robust offline-first data layer.

  • Task Progress:

- Define the data model with a synchronized boolean flag (default false). - Implement the local DatabaseService (SQLite/Hive) with CRUD operations. - Implement the remote ApiClientService for network requests. - Create the Repository class combining both services. - Implement the read method returning a Stream<T> (yield local, fetch remote, update local, yield remote). - Implement the write method (write local, attempt remote, update synchronized flag). - Implement a background sync function to process records where synchronized == false. - Run validator -> review errors -> fix (Test offline behavior by disabling network).

Workflow: Pre-warming the Android FlutterEngine

Follow these steps to cache the FlutterEngine for seamless Android integration.

  • Task Progress:

- Locate the Android Application class (create one if it doesn't exist and register in AndroidManifest.xml). - Instantiate a new FlutterEngine. - (Optional) Set the initial route via navigationChannel.setInitialRoute(). - Execute the Dart entrypoint via dartExecutor.executeDartEntrypoint(). - Store the engine in FlutterEngineCache.getInstance().put(). - Update the target FlutterActivity or FlutterFragment to use .withCachedEngine("id"). - Run validator -> review errors -> fix (Verify no blank screen appears during transition).

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.99%
按下载量换算26,260

Claude

31.1%
按下载量换算22,079

Cursor

16.22%
按下载量换算11,515

Gemini CLI

8.26%
按下载量换算5,864

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills