-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cc3d2c
commit a7fb933
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |