← 返回 Skills 市场
symboy

flutter-hive-database

作者 symboy · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
249
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install flutter-hive-database
功能描述
在 Flutter 项目中封装 Hive 本地数据库服务,遵循 Repository 模式和 MVVM 架构。当用户需要使用 Hive 数据库、本地持久化存储、离线数据缓存、或提到 hive、本地数据库、数据持久化时使用。支持三种独立模式:创建数据服务、创建数据库操作、创建数据模型并自动注入 CRUD。
使用说明 (SKILL.md)

Flutter Hive 数据库封装

存储策略

模型 → toJson()Box\x3CMap>fromJson() → 模型

  • 无需 TypeAdapter,无 ~200 个类型上限
  • 无需 build_runner,依赖精简
  • HiveService 懒加载 Box,新增模型无需修改 Service

目录结构

lib/
├── services/
│   ├── hive_service.dart          # 模式1:数据服务
│   └── hive_repository.dart       # 模式1:基类
└── \x3Cfeature>/
    └── database/
        ├── \x3Cname>_repository.dart # 模式2:数据库操作
        └── models/
            └── \x3Cname>_model.dart  # 模式3:数据模型

三种触发模式

模式1:创建数据服务

触发词:「创建数据服务」「初始化 Hive」「配置 Hive」

执行命令

python ~/.cursor/skills/flutter-hive-database/scripts/generate.py \
  --mode service \
  --project \x3C项目根目录绝对路径>

生成文件:

  • lib/service/hive_service.dart — 懒加载 Box 管理
  • lib/service/hive_repository.dart — 通用 CRUD 基类

完成后在 main.dart 添加:

import 'package:\x3Cpkg>/service/hive_service.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await HiveService.init();
  runApp(const MyApp());
}

模式2:创建 xxx 数据库操作

触发词:「创建xxx数据库操作」「创建xxx的 Repository」

执行前询问用户

请问功能模块的路径是什么?(如 features/useruser) Repository 的名称是什么?(PascalCase,如 User

执行命令

python ~/.cursor/skills/flutter-hive-database/scripts/generate.py \
  --mode repository \
  --project \x3C项目根目录绝对路径> \
  --feature \x3Clib下的功能路径> \
  --name \x3CPascalCase名称>

示例

python generate.py --mode repository \
  --project /Users/me/myapp \
  --feature features/user \
  --name User

生成文件:

  • lib/features/user/database/user_repository.dart — 含原始 Map CRUD,等待模型注入

模式3:创建数据模型(并注入 CRUD)

触发词:「创建xxx数据模型」「提供 JSON 创建数据库模板」

执行前询问用户

请提供实体的 JSON 数据或字段定义

entity 参数格式

{
  "name": "User",
  "fields": [
    {"name": "id",        "type": "int",      "nullable": false},
    {"name": "name",      "type": "String",   "nullable": false},
    {"name": "age",       "type": "int",      "nullable": true},
    {"name": "createdAt", "type": "DateTime", "nullable": false}
  ]
}

支持的 typeintdoubleStringboolDateTimeListMap

执行命令

python ~/.cursor/skills/flutter-hive-database/scripts/generate.py \
  --mode model \
  --project \x3C项目根目录绝对路径> \
  --feature \x3Clib下的功能路径> \
  --entity '\x3CJSON字符串>'

示例

python generate.py --mode model \
  --project /Users/me/myapp \
  --feature features/user \
  --entity '{"name":"User","fields":[{"name":"id","type":"int","nullable":false},{"name":"name","type":"String","nullable":false}]}'

生成 / 更新文件:

  • lib/features/user/database/models/user_model.dart — 模型(含 toJson/fromJson/copyWith)
  • lib/features/user/database/user_repository.dart自动注入 save/findById/getAll/update/deleteById 方法

如果 Repository 不存在,脚本会自动创建后再注入


依赖配置

flutter pub add hive_ce hive_ce_flutter

无需 hive_ce_generator,无需 build_runner

验证清单

  • HiveService.init()runApp() 之前调用
  • UI 层只通过 Repository 操作数据,不直接调用 HiveService
  • fromJson 中可选字段使用 as Type? 保证旧数据兼容

参考文件

安全使用建议
This skill appears coherent: it is a local code generator that writes Dart files into a Flutter project. Before running it, commit or back up your project so you can review changes; inspect diffs after generation to ensure injected code matches expectations. Only run the script on projects you trust. Although the script validates paths and names to prevent path traversal, it will modify files under the provided project root (including injecting CRUD methods into existing repository files), so review generated code and run tests. If you want tighter control, run the generator manually from a shell rather than allowing autonomous agent invocation.
功能分析
Type: OpenClaw Skill Name: flutter-hive-database Version: 1.0.0 The skill is a Flutter code generator for Hive database integration, providing automated scaffolding for services, repositories, and models. The included Python script (scripts/generate.py) implements robust input validation, including checks for valid Flutter project roots and protections against path traversal in the feature paths. The behavior is consistent with its stated purpose, and no evidence of data exfiltration, malicious execution, or prompt injection was found.
能力评估
Purpose & Capability
Name/description (Flutter Hive codegen) match the behavior: the skill provides a local Python generator that reads pubspec.yaml and writes Dart files under the project's lib/ tree. No unrelated credentials, binaries, or external services are requested.
Instruction Scope
SKILL.md instructs running the included generate.py with a project root and optional feature/name/entity. The script legitimately reads pubspec.yaml and lib/ and creates or updates Dart files. This is in-scope for a code generator, but be aware it will write into your project files and can inject CRUD code into existing repository files.
Install Mechanism
No install spec; the skill is instruction-only with one bundled Python script. Nothing is downloaded or executed from remote URLs; risk is limited to local file operations performed by the script.
Credentials
The skill requires no environment variables, credentials, or config paths. The script only reads project-local files (pubspec.yaml) and uses the validated --project and --feature inputs. No sensitive environment access is requested.
Persistence & Privilege
always is false and the skill does not request persistent platform-wide privileges. It affects only the specified project directory and does not attempt to modify other skills or global agent configuration.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install flutter-hive-database
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /flutter-hive-database 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- Initial release: Provides a plug-and-play Hive local database service for Flutter using Repository pattern and MVVM architecture. - Supports three trigger modes: service creation, repository/database operation creation, and data model generation with automatic CRUD injection. - No need for TypeAdapter or build_runner; supports more than 200 model types without generator dependencies. - Models use toJson/fromJson mapping, enabling flexible Box storage and simple model expansion. - Includes command-line scripts for scaffolding data services, repositories, and models. - Clear directory structure and usage instructions provided in SKILL.md.
元数据
Slug flutter-hive-database
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

flutter-hive-database 是什么?

在 Flutter 项目中封装 Hive 本地数据库服务,遵循 Repository 模式和 MVVM 架构。当用户需要使用 Hive 数据库、本地持久化存储、离线数据缓存、或提到 hive、本地数据库、数据持久化时使用。支持三种独立模式:创建数据服务、创建数据库操作、创建数据模型并自动注入 CRUD。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 249 次。

如何安装 flutter-hive-database?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install flutter-hive-database」即可一键安装,无需额外配置。

flutter-hive-database 是免费的吗?

是的,flutter-hive-database 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

flutter-hive-database 支持哪些平台?

flutter-hive-database 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 flutter-hive-database?

由 symboy(@symboy)开发并维护,当前版本 v1.0.0。

💬 留言讨论