Use when working with Flutter Bloc/Cubit state management. Covers when to choose Bloc vs Cubit, how to use bloc and flutter_bloc together, lifecycle, testing, a
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-bloc-cubit-085bfd7fa7ae ,按照其中的说明把「bloc-cubit」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this skill when building Flutter state management with bloc and flutter_bloc.
Cubit for simple, direct state updates.Bloc for event-driven flows, transitions, and replayable business logic.bloc in Dart-only projects.flutter_bloc in Flutter apps when you need widgets like BlocProvider, BlocBuilder, or BlocListener.flutter_bloc, you do not need to add bloc separately in a Flutter app because flutter_bloc depends on it.Choose Cubit when:
Choose Bloc when:
For Dart-only code:
blocflutter_bloc unless Flutter widgets are neededFor Flutter UI code:
flutter_blocbloc transitivelyBlocProvider at the feature boundaryBlocBuilder for rebuilds and BlocListener for side effectsPrefer this structure:
Keep state immutable.
Keep events explicit when using Bloc.
Keep one bloc or cubit per feature responsibility.
close().BlocProvider.BlocProvider or MultiBlocProvider to let Flutter manage disposal.new or a constructor outside the widget tree, you own its lifecycle.Use BlocBuilder when the widget should rebuild from state.
Use BlocListener when the widget should react without rebuilding.
Use BlocConsumer only when both are needed in one place.
Use buildWhen and listenWhen when rebuilds or listeners need narrowing.
Use BlocSelector when only one field should drive rebuilds.
Cubit by calling methods and asserting emitted states.Bloc by adding events and asserting the transition sequence.Bloc for trivial local state.bloc and flutter_bloc in a Flutter app when only flutter_bloc is needed.close() for manually managed instances.When writing code or advising on design:
bloc or flutter_blocbloc = core logic packageflutter_bloc = Flutter UI integration packageCubit = method-based updatesBloc = event-based transitionsclose()close()