Token导航 LogoToken导航TokenDH.com
开发external-servicegithub未标认证来源可访问许可证需确认审计通过

flutter-databasesFlutter databases 开发

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

23,561

周安装

972

GitHub Stars

1,310

下载量

7,698
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

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

简介

适用于 Flutter 的符合 MVVM 的数据层,具有存储库模式、无状态服务和智能本地缓存策略。

  • 根据数据类型、大小和关系复杂性指导选择持久性技术(shared_preferences、sqflite、drift、hive_ce、isar_community 或文件 I/O)
  • 将存储库实现为单一事实来源,将 DatabaseService 和 ApiClient 作为私有无状态依赖项隔离
  • 提供域模型、SQLite 操作和离线优先同步模式的完整代码示例,并带有参数化查询以防止 SQL 注入
  • 强制架构约束:UI层仅访问存储库,服务保持无状态,操作前验证数据库连接

SKILL.md

flutter-data-layer-persistence

Goal

Architects and implements a robust, MVVM-compliant data layer in Flutter applications. Establishes a single source of truth using the Repository pattern, isolates external API and local database interactions into stateless Services, and implements optimal local caching strategies (e.g., SQLite via sqflite) based on data requirements. Assumes a pre-configured Flutter environment.

Decision Logic

Evaluate the user's data persistence requirements using the following decision tree to select the appropriate caching strategy:

  • Is the data small, simple key-value pairs (e.g., user preferences, theme settings)?

- *Yes:* Use shared_preferences.

  • Is the data a large, structured, relational dataset requiring fast inserts/queries?

- *Yes:* Use On-device relational databases (sqflite or drift).

  • Is the data a large, unstructured/non-relational dataset?

- *Yes:* Use On-device non-relational databases (hive_ce or isar_community).

  • Is the data primarily API response caching?

- *Yes:* Use a lightweight remote caching system or interceptors.

  • Is the data primarily images?

- *Yes:* Use cached_network_image to store images on the file system.

  • Is the data too large for shared_preferences but doesn't require querying?

- *Yes:* Use direct File System I/O.

Instructions

  1. Analyze Data Requirements STOP AND ASK THE USER: "What specific data entities need to be managed in the data layer, and what are their persistence requirements (e.g., size, relational complexity, offline-first capabilities)?" *Wait for the user's response before proceeding to step 2.*
  2. Configure Dependencies Based on the decision logic, add the required dependencies. For a standard SQLite implementation, execute: flutter pub add sqflite path
  3. Define Domain Models Create pure Dart data classes representing the domain models. These models should contain only the information needed by the rest of the app. class Todo {final int? id; final String title; final bool isCompleted; const Todo({this.id, required this.title, required this.isCompleted}); Map<String, dynamic> toMap() {return {'id': id, 'title': title, 'isCompleted': isCompleted? 1: 0,};} factory Todo.fromMap(Map<String, dynamic> map) {return Todo(id: map['id'] as int?, title: map['title'] as String, isCompleted: map['isCompleted'] == 1,);}}
  4. Implement the Database Service Create a stateless service class to handle direct interactions with the SQLite database. import 'package:path/path.dart'; import 'package:sqflite/sqflite.dart'; class DatabaseService {Database? _database; Future<void> open() async {if (_database!= null && _database!.isOpen) return; _database = await openDatabase(join(await getDatabasesPath(), 'app_database.db'), onCreate: (db, version) {return db.execute('CREATE TABLE todos(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, isCompleted INTEGER)',);}, version: 1,);} bool get isOpen => _database!= null && _database!.isOpen; Future<int> insertTodo(Todo todo) async {return await _database!.insert('todos', todo.toMap(), conflictAlgorithm: ConflictAlgorithm.replace,);} Future<List<Todo>> fetchTodos() async {final List<Map<String, dynamic>> maps = await _database!.query('todos'); return maps.map((map) => Todo.fromMap(map)).toList();} Future<void> deleteTodo(int id) async {await _database!.delete('todos', where: 'id =?', whereArgs: [id],);}}
  5. Implement the API Client Service (Optional/If Applicable) Create a stateless service for remote data fetching. class ApiClient {Future<List<dynamic>> fetchRawTodos() async {// Implementation for HTTP GET request return [];}}
  6. Implement the Repository Create the Repository class. This is the single source of truth for the application data. It must encapsulate the services as private members. class TodoRepository {final DatabaseService _databaseService; final ApiClient _apiClient; TodoRepository({required DatabaseService databaseService, required ApiClient apiClient,}): _databaseService = databaseService, _apiClient = apiClient; Future<List<Todo>> getTodos() async {await _ensureDbOpen(); // Example of offline-first logic: fetch local, optionally sync with remote return await _databaseService.fetchTodos();} Future<void> createTodo(Todo todo) async {await _ensureDbOpen(); await _databaseService.insertTodo(todo); // Trigger API sync here if necessary} Future<void> removeTodo(int id) async {await _ensureDbOpen(); await _databaseService.deleteTodo(id);} Future<void> _ensureDbOpen() async {if (!_databaseService.isOpen) {await _databaseService.open();}}}
  7. Validate-and-Fix Review the generated implementation against the following checks:

- *Check:* Are the services (_databaseService, _apiClient) private members of the Repository? If not, refactor to restrict UI layer access. - *Check:* Does the Repository explicitly ensure the database is open before executing queries? If not, inject the _ensureDbOpen() pattern. - *Check:* Are primary keys (id) used effectively in SQLite queries to optimize update/delete times?

Constraints

  • Single Source of Truth: The UI layer MUST NEVER interact directly with a Service (e.g., DatabaseService or ApiClient). All data requests must route through the Repository.
  • Stateless Services: Service classes must remain stateless and contain no side effects outside of their specific external API/DB wrapper responsibilities.
  • Domain Model Isolation: Repositories must transform raw data (from APIs or DBs) into Domain Models before passing them to the UI layer.
  • SQL Injection Prevention: Always use parameterized queries (e.g., whereArgs: [id]) in sqflite operations. Never use string interpolation for SQL queries.
  • Database State: The Repository must guarantee the database connection is open before attempting any read/write operations.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

39.11%
按下载量换算3,011

Claude

28.56%
按下载量换算2,199

Cursor

20.31%
按下载量换算1,563

Gemini CLI

9.83%
按下载量换算757

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

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

来源信息

继续浏览同类 Skills