Skip to content

Commit

Permalink
Add bloc_dispose_scope example
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertOdrowaz committed Aug 31, 2021
1 parent 3cc3d2c commit a7fb933
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/bloc_dispose_scope/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:bloc/bloc.dart';
import 'package:bloc_dispose_scope/bloc_dispose_scope.dart';
import 'package:dispose_scope/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)
.disposed(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()..disposed(disposeScope);
MainCubit(_dependencyCubit).disposed(disposeScope);

disposeScope.dispose();
}

0 comments on commit a7fb933

Please sign in to comment.