ワンクリックで
flutter-databases
Work with databases in a Flutter app
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Work with databases in a Flutter app
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
PocketMind 本地无头浏览器爬取架构,适用于小红书/知乎抓取、后台爬虫服务、MethodChannel、Cookie 管理与 MetadataManager 协作场景。
Use when implementing or debugging PocketMind mobile chat flows, including note-scoped sessions, global multi-session switching, sync gating, stream send behavior, and dialog interaction regressions.
PocketMind 后端 notes->resource_records->context_catalog 一致性改造专项 Skill。当用户讨论 resource_records 真相层、context_catalog 索引层、Outbox/Projector、检索 fallback、SessionCommit 长事务、transcript 重复同步或相关回归测试时必须触发。
Use when you need to understand or modify PocketMind note save to resource indexing flow, including outbox, MQ hint/DLQ compensation, projector consumption, and consistency boundaries.
PocketMind 移动端笔记同步架构专项 Skill。当涉及以下问题时必须触发:预览字段(previewTitle等)被同步覆盖、多端一致性与离线冲突问题、同步链路改造(Pull/Push)、UI层违规调用底层Provider、抓取/轮询等写入未进入同步队列、或维护同步守卫测试。
设计、重构和实现 PocketMind 项目中的整体上下文架构(Context Architecture),用于统一规划和落地 resources、user memories、agent memories、tenant skills、session、retrieval、ingestion、storage 与现有 Note/Chat/Asset 的边界。当用户要求为 PocketMind 新增长期记忆、重构 AI 上下文体系、借鉴 OpenViking 的上下文类型/层级/URI/存储/检索/会话思想,或需要分阶段实施 Context Service 时使用。
SOC 職業分類に基づく
| name | flutter-databases |
| description | Work with databases in a Flutter app |
| metadata | {"model":"models/gemini-3.1-pro-preview","last_modified":"Wed, 04 Mar 2026 18:34:08 GMT"} |
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.
Evaluate the user's data persistence requirements using the following decision tree to select the appropriate caching strategy:
shared_preferences.sqflite or drift).hive_ce or isar_community).cached_network_image to store images on the file system.shared_preferences but doesn't require querying?
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.
Configure Dependencies Based on the decision logic, add the required dependencies. For a standard SQLite implementation, execute:
flutter pub add sqflite path
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,
);
}
}
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],
);
}
}
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 [];
}
}
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();
}
}
}
Validate-and-Fix Review the generated implementation against the following checks:
_databaseService, _apiClient) private members of the Repository? If not, refactor to restrict UI layer access._ensureDbOpen() pattern.id) used effectively in SQLite queries to optimize update/delete times?DatabaseService or ApiClient). All data requests must route through the Repository.whereArgs: [id]) in sqflite operations. Never use string interpolation for SQL queries.