angular_bloc
9.0.0, released 4 years ago by bloclibrary.dev
AngularDart components that bind Bloc/Cubit state to the UI via a pipe.
What it does
Provides a BlocPipe that connects Bloc or Cubit streams to Angular templates, updating the view on state changes. Works with the bloc package to enable BLoC pattern in AngularDart apps.
AI-written summary of version 9.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are building a web app with AngularDart and want to use the Bloc state‑management pattern.
- You need a simple way to bind Bloc/Cubit state to Angular templates without writing manual subscriptions.
Skip it when
- Your project is a Flutter app (use flutter_bloc or bloc instead).
- You require code‑generation or advanced DI features not offered by this package.
Strengths
- Seamless integration of Bloc with AngularDart via a pipe.
- Supports both Bloc and Cubit APIs.
- Minimal boilerplate for UI binding.
Weaknesses
- Limited to AngularDart/web; not usable in Flutter or mobile contexts.
- Frequent breaking changes tied to ngdart and bloc version upgrades.
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- No
- Direct dependencies
- 2
Add angular_bloc, ngdart and bloc to pubspec, import angular_bloc.dart, and use BlocPipe in component metadata.
import 'package:angular/angular.dart';
import 'package:angular_bloc/angular_bloc.dart';
import 'package:bloc/bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}
@Component(
selector: 'counter-page',
template: '''
<h2>Count: {{ $pipe.bloc(counterCubit) }}</h2>
<button (click)="counterCubit.increment()">+</button>
''',
pipes: [BlocPipe],
)
class CounterPageComponent implements OnInit, OnDestroy {
late final CounterCubit counterCubit;
void ngOnInit() => counterCubit = CounterCubit();
void ngOnDestroy() => counterCubit.close();
}Alternatives
Packages that do the same job and could replace angular_bloc.
- yx_state
A state management library for Dart and Flutter applications.
82Compare - bloc_tools
Command-line tools for generating and linting bloc and cubit components.
88Compare - rx_bloc
A BLoC design pattern implementation using reactive streams.
63Compare - riverpod
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
99Compare
Works with
Packages commonly used together with angular_bloc: ones it builds on, ones built on it, and its own family.
- blocangular_bloc depends on itA Dart library for implementing the BLoC pattern with Cubits and Blocs.
- ngdartangular_bloc depends on itFast and productive web framework for Dart.
- flutter_blocSame familyFlutter widgets to easily integrate blocs and cubits for state management.
- bloc_testSame familyA testing library that makes it easy to test blocs and cubits.
- bloc_concurrencySame familyCustom event transformers for the bloc state management package.
- hydrated_blocSame familyAutomatically persists and restores bloc and cubit states.
- replay_blocSame familyAdds automatic undo and redo support to bloc and cubit states.