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;
}
…
调用最新框架与库文档,快速回答配置、API与代码示例问题
依据C++核心指南辅助编写、审查与重构更现代安全的C++代码。
为 Spring Boot 与 Quarkus 服务生成并统一应用 Java 编码规范。
读取计划文档并拆解步骤,生成可直接粘贴的 /orchestrate 链式提示词
帮助用户搭建 WireGuard VPN、配置客户端并安全远程访问家庭网络。
帮助你设计 Quarkus 3 后端架构模式,覆盖消息、REST、数据访问与异步处理。