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/flutter.md
View on GitHub# BlocSignal in Flutter
Verified against `bloc_signals_flutter` 1.5.0 source.
## Provide
```dart
import 'package:bloc_signals_flutter/bloc_signals_flutter.dart';
BlocSignalProvider(
create: (context) => CounterBloc(), // lazy by default; BlocSignalProvider owns and closes it
child: const CounterScreen(),
);
BlocSignalProvider(
create: (_) => CounterBloc(),
lazy: false, // create eagerly
child: const CounterScreen(),
);
BlocSignalProvider.value(
value: existingBloc, // does not own or close the bloc
child: const CounterScreen(),
);
```
- Multiple providers: `MultiBlocSignalProvider`.
- `BlocSignalProvider` and `BlocSignalListener` take an optional `child`, so `MultiBlocSignalProvider` and `MultiBlocSignalListener` do not need placeholder children.
## Read the bloc
```dart
context.read<CounterBloc>().add(Increment()); // in callbacks
final bloc = context.read<CounterBloc>();
```
- `context.read<T>()` returns the instance without subscribing.
- `context.watch<T>()` rebuilds when the *provider instance* changes, not when state changes. Do not use it to react to state.
## Rebuild on state
```dart
BlocSignalBuilder<CounterBloc, int>(
builder: (context, count) => Text('$count'),
);
```
- `BlocSignalBuilder` takes the bloc from the nearest provider. Pass `bloc:` to use an explicit instance.
- Inside `build`, `context.value<CounterBloc, int>()` reads the current value and subscribes to it.
- `context.state<CounterBloc, int>()` returns a `ReadonlySignal<int>` for composing with `computed()`.
## Listen for side effects
```dart
BlocSignalListener<CounterBloc, int>(
listenWhen: (previous, current) => current > 10,
listener: (context, count) => ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Reached $count')),
),
child: const CounterBody(),
);
```
- `BlocSignalListener` does not run its listener on the initial value.
- `listenWhen(previous, current)` filters transitions. The listener receives only the current state.
## Consumer and selector
- `BlocSignalConsumer` combines `builder` and `listener`.
- `BlocSignalSelector<CounterBloc, int, V>` rebuilds only when the selected value changes.
- `context.select<CounterBloc, bool>((bloc) => bloc.stateValue > 0)` reads a derived value. It takes two type arguments (bloc type and result type), and the callback receives the bloc instance.
## flutter_hooks
Use the `signals_hooks` integration in a `HookWidget`:
```dart
class CounterHookView extends HookWidget {
const CounterHookView({super.key});
@override
Widget build(BuildContext context) {
final bloc = useMemoized(() => CounterBloc());
final count = useSignalValue(bloc.state);
return Text('$count');
}
}
```
Dispose the bloc yourself when you create it inside a hook (use `useEffect` to call `bloc.close()` on dispose).
## Ownership rules
- A bloc created by `BlocSignalProvider(create:)` is closed automatically.
- A bloc created in a `StatefulWidget` must be created once in `initState` and closed in `dispose`. Creating it in `build` leaks it on every rebuild.
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 |