bloc_dependency_manager 1.10.0 copy "bloc_dependency_manager: ^1.10.0" to clipboard
bloc_dependency_manager: ^1.10.0 copied to clipboard

This is a package that helps manage Bloc and Cubit dependencies. It is based on the Bloc package and utilizes the Observer design pattern to manage dependencies.

example/lib/example.dart

import 'package:bloc_dependency_manager/bloc_dependency_manager.dart';
import 'package:bloc_dependency_manager_example/counter_bloc.dart';
import 'package:bloc_dependency_manager_example/counter_state_emitter.dart';
import 'package:bloc_dependency_manager_example/logger_bloc.dart';

Future<void> main() async {
  // Register all the blocs.
  BlocManager().register(LoggerBloc());
  BlocManager().register(CounterBloc());

  // Register the state emitter for the [CounterBloc].
  StateDispatcher(BlocManager()).register<CounterBloc, CounterStateEmitter>(
    (BaseBlocManager blocManager) =>
        CounterStateEmitter(blocManager as BlocManager),
  );

  // Resolve the [LoggerBloc] and listen to its state changes.
  BlocManager().resolve<LoggerBloc>().stream.listen(print);

  // Resolve the [CounterBloc] and dispatch some events.
  BlocManager().resolve<CounterBloc>().decrement();
  await Future<void>.delayed(const Duration(seconds: 1));
  BlocManager().resolve<CounterBloc>().increment();
  await Future<void>.delayed(const Duration(seconds: 1));
  BlocManager().resolve<CounterBloc>().reset();
  await Future<void>.delayed(const Duration(seconds: 1));

  // Dispose [BlocManager] to clean up resources.
  await BlocManager().dispose<LoggerBloc>();
  await BlocManager().dispose<CounterBloc>();

  print('All blocs disposed.');
}
2
likes
160
points
39
downloads

Publisher

unverified uploader

Weekly Downloads

This is a package that helps manage Bloc and Cubit dependencies. It is based on the Bloc package and utilizes the Observer design pattern to manage dependencies.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc, get_it

More

Packages that depend on bloc_dependency_manager