agentsclimarketplace

Flutter bloc

Skill Poorgramer-Zack/dart-expert-skills/skills/flutter-bloc

A comprehensive library of modular Agent Skills for Flutter & Dart development

Install
npx -y skills add Poorgramer-Zack/dart-expert-skills --skill flutter-bloc

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 6 stars6 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Implements BLoC (v9.x) event-driven state management for Flutter with unidirectional data flow using the flutter_bloc package. Use when implementing Bloc/Cubit classes, mapping Events to States, consuming state with BlocBuilder/BlocListener/BlocConsumer, applying event transformers (restartable/droppable/sequential) for concurrency control, setting up BlocProvider/MultiBlocProvider DI, integrating Freezed for sealed union types and exhaustive pattern matching, or testing with blocTest. Ideal for enterprise apps requiring business logic separation, precise concurrency control (search debouncing, form deduplication), or event replay debugging.

SKILL.md

5.2 KB, as published. Nobody here has run it

BLoC State Management (v9.x)

Goal

Strict separation of UI from business logic via event-driven unidirectional data flow. Choose Cubit (lightweight, no events) for simple state, or full Bloc (events + transformers) for complex flows.

Process

1. Install Dependencies

dependencies:
  flutter_bloc: ^9.1.1
  equatable: ^2.0.5
  bloc_concurrency: ^0.3.0  # For event transformers

dev_dependencies:
  bloc_test: ^10.0.0

2. Choose Pattern

PatternWhen to Use
CubitSimple state (toggle, counter, form validation)
BlocEvent tracking, transformers, complex flows (login, search debounce)

3A. Implement Cubit

class CounterState extends Equatable {
  final int value;
  const CounterState({required this.value});
  @override
  List<Object?> get props => [value];
}

class CounterCubit extends Cubit<CounterState> {
  CounterCubit() : super(const CounterState(value: 0));
  void increment() => emit(CounterState(value: state.value + 1));
  void decrement() => emit(CounterState(value: state.value - 1));
}

3B. Implement Bloc

abstract class CounterEvent extends Equatable {
  const CounterEvent();
  @override
  List<Object?> get props => [];
}
class CounterIncremented extends CounterEvent {}
class CounterDecremented extends CounterEvent {}

class CounterBloc extends Bloc<CounterEvent, CounterState> {
  CounterBloc() : super(const CounterState(value: 0)) {
    on<CounterIncremented>((e, emit) => emit(CounterState(value: state.value + 1)));
    on<CounterDecremented>((e, emit) => emit(CounterState(value: state.value - 1)));
  }
}

4. Provide to Widget Tree

MultiBlocProvider(
  providers: [
    BlocProvider(create: (context) => CounterCubit()),
    BlocProvider(create: (context) => AuthBloc()),
  ],
  child: MyApp(),
)

5. Consume State

WidgetUse For
BlocBuilderRebuild UI on state changes
BlocListenerSide effects only (navigation, snackbars)
BlocConsumerRebuild + side effects together
// Trigger events
context.read<CounterBloc>().add(CounterIncremented());
context.read<CounterCubit>().increment(); // Cubit: direct method call

See BLoC Best Practices for full widget examples with buildWhen/listenWhen.

6. Event Transformers

TransformerBehaviorUse Case
concurrent (default)All events in parallelIndependent API calls
sequentialOne at a time, queuedMulti-step transactions
restartableCancel previous, start freshSearch bar, autocomplete
droppableIgnore while processingSubmit button deduplication
import 'package:bloc_concurrency/bloc_concurrency.dart';

on<SearchQueryChanged>(_onQueryChanged, transformer: restartable());
on<FormSubmitted>(_onFormSubmitted, transformer: droppable());

See BLoC Best Practices for custom debounce transformer.

7. Freezed Integration

Use Freezed for sealed union states with exhaustive when/map pattern matching. See BLoC Best Practices for full Freezed setup and examples.

8. Common Errors

See Error Handling & Common Pitfalls for solutions to:

  • Emitting after Bloc close (emit.isDone guard)
  • Mutable state causing silent UI bugs (spread into new instances)
  • Scattered try/catch — use onError + addError instead

Reference Documentation


Constraints

  • Immutable States: All states MUST be immutable. Use Equatable or Freezed.
  • No UI in Bloc: Blocs/Cubits MUST NOT import Flutter widgets or BuildContext.
  • Single Responsibility: Each Bloc handles one feature domain.
  • Event Naming: Past tense nouns (UserLoggedIn, not UserLogin).
  • State Naming: Nouns or adjectives (AuthSuccess, not AuthSucceeded).
  • Always Close: Blocs/Cubits MUST be closed on dispose to prevent memory leaks.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.