Poorgramer-Zack/dart-expert-skills / skills/bloc-signals
bloc-signals
VerifiedImplement, review, test, and migrate Dart and Flutter code that uses BlocSignal (bloc_signals, bloc_signals_flutter, bloc_signals_test), the BLoC-style API built on signals. Use this when the code imports package:bloc_signals, extends BlocSignal or CubitSignal, uses BlocSignalProvider, BlocSignalBuilder, BlocSignalListener, or context.select, or when the user asks how BlocSignal differs from flutter_bloc or wants to move from BLoC to synchronous signal-based state.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.5 KB |
| references/core.md | markdown | 3.0 KB |
| references/flutter.md | markdown | 3.0 KB |
| references/migration-from-bloc.md | markdown | 3.5 KB |
| references/testing.md | markdown | 2.2 KB |
references/migration-from-bloc.md
View on GitHub# Migrating from flutter_bloc to BlocSignal
Read this before replacing `bloc`, `flutter_bloc`, or `bloc_test` code. The mapping below comes from the upstream migration guide and the `bloc_signals` 1.7.0 source.
## Code changes
| flutter_bloc | BlocSignal |
|---|---|
| `extends Bloc<E, S>` | `extends BlocSignal<E, S>` |
| `extends Cubit<S>` | `extends CubitSignal<S>` |
| `: super(0)` | `: super(initialState: 0)` |
| `state` (raw value) | `stateValue` or `value` |
| `emit` in stream-based handlers | `emit` is synchronous |
| `BlocProvider` | `BlocSignalProvider` |
| `MultiBlocProvider` | `MultiBlocSignalProvider` |
| `BlocBuilder` | `BlocSignalBuilder` |
| `BlocListener` | `BlocSignalListener` |
| `BlocConsumer` | `BlocSignalConsumer` |
| `BlocSelector` | `BlocSignalSelector` |
| `RepositoryProvider` | Not needed. Use `BlocSignalProvider` or your own DI. |
| `context.select<B, R>((b) => ...)` | Same idea. `context.select<B, R>` takes two type arguments, and the callback receives the bloc. |
Before:
```dart
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<Increment>((event, emit) => emit(state + 1));
}
}
```
After:
```dart
class CounterBloc extends BlocSignal<CounterEvent, int> {
CounterBloc() : super(initialState: 0) {
on<Increment>((event, emit) => emit(stateValue + 1));
}
}
```
## Behavior differences that break code
- **No streams on the base classes.** `BlocSignalBase`, `CubitSignalMixin`, and `BlocSignalMixin` do not expose a `stream` getter. Code that calls `bloc.stream.listen(...)` must use `state` (a `ReadonlySignal`) or `createEffect`. To bring a `Stream` into BlocSignal, use `toBlocSignal`.
- **Synchronous updates.** After `add`, `stateValue` is already updated. Tests that waited for a microtask can drop the wait. Tests that relied on the delay need an explicit `wait:`.
- **Listener does not fire initially.** `BlocSignalListener` skips the first value. `BlocListener` in flutter_bloc behaves differently.
- **Equality skip.** An `emit` equal to the current state does nothing, so no listener and no transition runs.
- **`watch` does not rebuild on state.** Use `BlocSignalBuilder` or `context.value`.
- **One global observer.** `BlocSignalObserver` is a single slot. If you already have a logger, compose both observers.
- **Concurrency transformers** run as plain Dart functions. `bloc_concurrency` transformers are not used.
## Migrating a legacy bloc you do not want to rewrite
Use the bridge in the upstream migration guide. Wrap an existing `Stream` with `toBlocSignal`. Create the wrapper once, in `initState`, and close it in `dispose`. Creating it in `build` leaks subscriptions.
```dart
class _MyWidgetState extends State<MyWidget> {
late final BlocSignalBase<int> _blocSignal;
@override
void initState() {
super.initState();
_blocSignal = widget.legacyBloc.stream.toBlocSignal(
initialState: widget.legacyBloc.state,
);
}
@override
void dispose() {
_blocSignal.close();
super.dispose();
}
}
```
The `Stream.toBlocSignal({initialState})` extension is defined in `bloc_signals` 1.7.0 (`lib/src/stream_adapter.dart`). Check the signature again if you use a different version.
## Checklist
1. Read the installed `bloc_signals` version.
2. Replace the base classes and constructors.
3. Replace `state` reads with `stateValue`.
4. Replace the widget classes.
5. Update tests: drop microtask waits, keep `blocSignalTest`.
6. Check for `stream` usages and listener logic that assumed the initial emission.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |