移动端安装
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- 工程开发
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 底层运行要求
- 无特殊要求
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- 网络行为
- 允许外网请求
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: flutter-bloc-setup
description: Configures a Flutter project for Bloc state management with `flutter_bloc`, `freezed`, `bloc_con…
category: 工程开发
runtime: 无特殊运行时
---
# flutter-bloc-setup 输出预览
## PART A: 任务判断
- 适用问题:代码实现、重构、调试或代码审查。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Contents / Dependencies and generators / App-level providers”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于代码实现、重构、调试或代码审查,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Contents / Dependencies and generators / App-level providers”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、会按任务需要访问外部网络、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件。
先用一个小任务确认它会围绕“Contents / Dependencies and generators / App-level providers”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: flutter-bloc-setup
description: Configures a Flutter project for Bloc state management with `flutter_bloc`, `freezed`, `bloc_con…
category: 工程开发
source: tomevault-io/skills-registry
---
# flutter-bloc-setup
## 什么时候使用
- 把工程方向的常用动作沉淀成 Agent 可调用的技能 适合处理工程开发场景下的代码实现、调试、重构、测试或代码审查,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代…
- 面向代码实现、重构、调试或代码审查,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Contents / Dependencies and generators / App-level providers」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "flutter-bloc-setup" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Contents / Dependencies and generators / App-level providers
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> 无特殊运行时 | 读取文件、写入/修改文件 | 会按任务需要访问外部网络
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Bootstrapping Bloc in a Flutter Project
Installs and wires the canonical Bloc stack so feature-level skills (flutter-bloc-feature-pattern, flutter-bloc-async-api, flutter-bloc-stream-tracking, flutter-bloc-testing, flutter-bloc-forms) plug into a project with no further setup. Mobile only — Android and iOS targets. Web and desktop are out of scope.
Contents
- Dependencies and generators
- App-level providers
- Project structure
- Workflow: Bootstrap a Bloc-ready project
- Applied to Talabat-clone
- Examples
Dependencies and generators
Add the runtime dependencies. Pin major versions explicitly so dart run build_runner does not break across upgrades.
flutter pub add flutter_bloc freezed_annotation json_annotation bloc_concurrency hydrated_bloc path_provider
Add the generators as dev_dependencies. build_runner drives both freezed and json_serializable.
flutter pub add --dev build_runner freezed json_serializable
Run the generator continuously while editing freezed-annotated files in a side terminal. This avoids stale *.freezed.dart and *.g.dart artifacts during development.
dart run build_runner watch -d
This skill does not duplicate HTTP setup. Android <uses-permission android:name="android.permission.INTERNET" /> and the iOS com.apple.security.network.client entitlement live in flutter-use-http-package. Run that skill once for the project before adding any feature that calls a backend.
App-level providers
Two app-wide objects belong at the root of the widget tree.
MultiRepositoryProvider— exposes data-layer repositories to every feature below. Start withconst <RepositoryProvider>[](typed, not bareconst [], which tripsstrict-inferencelints);flutter-bloc-async-apiadds repositories to this list as features land. Each repository entry looks like:RepositoryProvider<AuthRepository>( create: (_) => AuthRepository(api: AuthApiClient(...)), lazy: true, // construct only on first read ),AppBlocObserver— a globalBlocObserverthat logs every Bloc transition and error to the console in debug mode. It dramatically shortens the loop when a state machine misbehaves. Gate it onkDebugModeso production builds stay quiet.
HydratedBloc.storage must be initialized before runApp(); otherwise any HydratedBloc constructed during the first frame will crash with HydratedStorageNotFound. Use path_provider to resolve the storage directory on Android and iOS.
Use getApplicationDocumentsDirectory() (durable across app updates and OS reboots), not getTemporaryDirectory() — the latter can be cleared by the OS without warning, which would silently lose the user's cart on a low-storage device. Some upstream examples use the temp directory because it's faster for one-off demos; for a real app with persisted cart/auth state, the documents directory is the right choice.
Project structure
Bloc replaces the view_models/ directory from flutter-apply-architecture-best-practices. The Repository, Service, and Domain Model layers from that skill stay unchanged.
lib/
├── core/
│ ├── bloc/
│ │ └── app_bloc_observer.dart
│ └── result/
│ ├── failure.dart # added by flutter-bloc-async-api
│ └── result.dart # added by flutter-bloc-async-api
├── data/ # unchanged from flutter-apply-architecture-best-practices
│ ├── models/ # API DTOs
│ ├── repositories/ # consumed by Blocs via RepositoryProvider
│ └── services/
├── domain/ # unchanged
│ └── models/
└── ui/
└── features/
└── <feature>/
├── bloc/
│ ├── <feature>_bloc.dart
│ ├── <feature>_event.dart
│ └── <feature>_state.dart
└── view/
└── <feature>_view.dart
One folder per feature, three files per Bloc. Tests for each Bloc mirror the path under test/ui/features/<feature>/bloc/<feature>_bloc_test.dart.
Workflow: Bootstrap a Bloc-ready project
Task Progress
- Step 1 — Install runtime deps.
flutter pub add flutter_bloc freezed_annotation json_annotation bloc_concurrency hydrated_bloc path_provider. - Step 2 — Install generators.
flutter pub add --dev build_runner freezed json_serializable. - Step 3 — Create the observer. Write
lib/core/bloc/app_bloc_observer.dartextendingBlocObserver. OverrideonChangeandonError. - Step 4 — Initialize storage. In
main(), callWidgetsFlutterBinding.ensureInitialized()thenHydratedBloc.storage = await HydratedStorage.build(storageDirectory: HydratedStorageDirectory((await getApplicationDocumentsDirectory()).path))beforerunApp(). - Step 5 — Wire the observer.
if (kDebugMode) Bloc.observer = const AppBlocObserver();— only in debug builds, so production stays quiet. - Step 6 — Wrap the app root. Replace your top-level widget with
MultiRepositoryProvider(providers: const <RepositoryProvider>[], child: MaterialApp(...)). Theproviderslist grows as features land. - Step 7 — Create the feature directory.
mkdir -p lib/ui/features lib/core/bloc. - Step 8 — Run the generator. Open a side terminal:
dart run build_runner watch -d. Leave it running while you work.
Troubleshooting. Run flutter analyze → if dart run build_runner errors, check that every freezed file imports package:freezed_annotation/freezed_annotation.dart and declares part '<file>.freezed.dart'; → re-run. If HydratedStorageNotFound is thrown on first launch, your HydratedBloc.storage initialization happens after runApp() — move it before in main().
Applied to Talabat-clone
For a multi-store delivery app, the Blocs the family will eventually scaffold are (cross-referenced against PRD_states.md):
| Bloc | Persists? | Why |
|---|---|---|
AuthBloc |
yes (HydratedBloc) |
Auth token + the user's User: active lifecycle state are both worth persisting across cold start; see PRD_states.md §14 for the user-account state machine and prd.md for the auth/session flow. |
CartBloc |
yes (HydratedBloc) |
One-cart / one-store / one-city rules; cart survives restart (PRD_states.md §7, PRD_catalog.md §15.5). |
StoreListBloc |
no | Re-fetch on launch; depends on location and operational gating (PRD_states.md §4). |
StoreDetailBloc |
no | Per-route, ephemeral. |
OrderBloc |
no | Authoritative source is the API. |
OrderTrackingBloc |
no | Stream-driven, scoped to an Order's picked_up → delivered window (deferred to flutter-bloc-stream-tracking). |
PromotionBloc |
no | Validity is computed from start_date / end_date / is_paused (PRD_states.md §9 Promotion/Offer; siblings §8 Coupon and §10 Advertisement share the shape with minor variations). |
The root MultiRepositoryProvider will hold AuthRepository, StoreRepository, OrderRepository, CartRepository (cart is local-only; the repository wraps hydrated_bloc storage), and PromotionRepository.
Examples
Minimal main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:path_provider/path_provider.dart';
import 'core/bloc/app_bloc_observer.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: HydratedStorageDirectory(
(await getApplicationDocumentsDirectory()).path,
),
);
if (kDebugMode) {
Bloc.observer = const AppBlocObserver();
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MultiRepositoryProvider(
// Typed empty list — `const []` bare would fail `strict-inference`.
providers: const <RepositoryProvider>[
// Repositories are added here by flutter-bloc-async-api as features land.
// Example:
// RepositoryProvider<AuthRepository>(
// create: (_) => AuthRepository(...),
// lazy: true,
// ),
],
child: MaterialApp(
title: 'Multi-Store Delivery',
home: Scaffold(
appBar: AppBar(title: const Text('Smoke test')),
body: const Center(child: Text('Bloc setup OK')),
),
),
);
}
}
lib/core/bloc/app_bloc_observer.dart
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
/// Logs every Bloc transition and error during development.
/// Wired in `main()` only when `kDebugMode` is true.
class AppBlocObserver extends BlocObserver {
const AppBlocObserver();
// Override `onTransition` (not `onChange`) so Bloc logs show the
// `event + currentState → nextState` triple. `onChange` only sees the
// state diff, which loses the event-causation half. Cubits (no events)
// fall through to `onChange` automatically.
@override
void onTransition(
Bloc<dynamic, dynamic> bloc,
Transition<dynamic, dynamic> transition,
) {
super.onTransition(bloc, transition);
debugPrint('[${bloc.runtimeType}] $transition');
}
@override
void onError(BlocBase<dynamic> bloc, Object error, StackTrace stackTrace) {
debugPrint('[${bloc.runtimeType}] ERROR: $error');
super.onError(bloc, error, stackTrace);
}
}
pubspec.yaml excerpt
dependencies:
flutter:
sdk: flutter
flutter_bloc: ^9.0.0
freezed_annotation: ^3.0.0
json_annotation: ^4.9.0
bloc_concurrency: ^0.3.0
hydrated_bloc: ^10.0.0
path_provider: ^2.1.0
http: ^1.2.0
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.4.0
freezed: ^3.0.0
json_serializable: ^6.8.0
Source: abdallhMoukdad/flutter-bloc-skills — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核