bloc_dispose_scope 3.0.0 copy "bloc_dispose_scope: ^3.0.0" to clipboard
bloc_dispose_scope: ^3.0.0 copied to clipboard

Package supporting bloc types for dispose_scope.

example/main.dart

import 'package:bloc/bloc.dart';
import 'package:bloc_dispose_scope/bloc_dispose_scope.dart';

class DependencyCubit extends Cubit<String> {
  DependencyCubit() : super('');
}

class MainCubit extends Cubit<String> with BlocBaseDisposeScopeMixin {
  MainCubit(this._dependencyCubit) : super('') {
    // StreamSubscription will be cancelled when MainCubit is closed
    _dependencyCubit.stream
        .listen(_onDependencyCubitStateChanged)
        .disposedBy(scope);
  }

  final DependencyCubit _dependencyCubit;

  void _onDependencyCubitStateChanged(String dependencyState) {}
}

void main() {
  final disposeScope = DisposeScope();

  // Both cubits will be disposed when disposeScope is disposed
  final dependencyCubit = DependencyCubit()..disposedBy(disposeScope);
  MainCubit(dependencyCubit).disposedBy(disposeScope);

  disposeScope.dispose();
}
2
likes
150
points
792
downloads

Publisher

verified publisherodrowaz.dev

Weekly Downloads

Package supporting bloc types for dispose_scope.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc, dispose_scope, meta

More

Packages that depend on bloc_dispose_scope