Production-ready Dart and Flutter patterns covering null safety, immutable state, async composition, widget architecture, popular state management frameworks (BLoC, Riverpod, Provider), GoRouter navigation, Dio networking, Freezed code generation, and clean architecture.
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "dart-flutter-patterns" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/dart-flutter-patterns/SKILL.md 2. 保存为 ~/.claude/skills/dart-flutter-patterns/SKILL.md 3. 装好后重载技能,告诉我可以用了
Use this skill when:
This skill provides copy-paste-ready Dart/Flutter code patterns organized by concern:
!, prefer ?./??/pattern matchingfreezed, copyWithFuture.wait, safe BuildContext after awaitconst propagation, scoped rebuildsrefreshListenableErrorWidget.builder, crashlytics wiring// Sealed state — prevents impossible states
sealed class AsyncState<T> {}
final class Loading<T> extends AsyncState<T> {}
final class Success<T> extends AsyncState<T> { final T data; const Success(this.data); }
final class Failure<T> extends AsyncState<T> { final Object error; const Failure(this.error); }
// GoRouter with reactive auth redirect
final router = GoRouter(
refreshListenable: GoRouterRefreshStream(authCubit.stream),
redirect: (context, state) {
final authed = context.read<AuthCubit>().state is AuthAuthenticated;
if (!authed && !state.matchedLocation.startsWith('/login')) return '/login';
return null;
},
routes: [...],
);
// Riverpod derived provider with safe firstWhereOrNull
@riverpod
double cartTotal(Ref ref) {
final cart = ref.watch(cartNotifierProvider);
final products = ref.watch(productsProvider).valueOrNull ?? [];
return cart.fold(0.0, (total, item) {
final product = products.firstWhereOrNull((p) => p.id == item.productId);
return total + (product?.price ?? 0) * item.quantity;
});
}
Practical, production-ready patterns for Dart and Flutter applications. Library-agnostic where possible, with explicit coverage of the most common ecosystem packages.
// BAD — crashes at runtime if null
final name = user!.name;
// GOOD — provide fallback
final name = user?.name ?? 'Unknown';
// GOOD — Dart 3 pattern matching (preferred for complex cases)
final display = switch (user) {
User(:final name, :final email) => '$name <$email>',
null => 'Guest',
};
// GOOD — guard early return
String getUserName(User? user) {
if (user == null) return 'Unknown';
return user.name; // promoted to non-null after check
}
late Overuse// BAD — defers null error to runtime
late String userId;
// GOOD — nullable with explicit initialization
String? userId;
// OK — use late only when initialization is guaranteed before first access
// (e.g., in initState() before any widget interaction)
late final AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
}
sealed class UserState {}
final class UserInitial extends UserState {}
final class UserLoading extends UserState {}
final class UserLoaded extends UserState {
const UserLoaded(this.user);
final User user;
}
…
帮助团队按 HIPAA 要求处理医疗隐私、安全合规与泄露应对事项
帮助你用地道 Go 实践编写测试、基准、模糊测试并提升覆盖率。
帮助你判断解析结构化文本时何时用正则、何时引入大模型兜底。
读取 ECC 实时仓库信息,指导用户了解代理、技能、命令与项目接入流程
将本地 Hermes 工作流清理并转换为可公开复用的 ECC 技能与发布产物。
为 Spring Boot 项目执行构建、测试、扫描与变更复核的发布前验证流程