-
Notifications
You must be signed in to change notification settings - Fork 1
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
7960166
commit 505d7ff
Showing
3 changed files
with
72 additions
and
30 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 |
---|---|---|
@@ -1,14 +1,22 @@ | ||
# flutter_dispose_scope | ||
# BlocDisposeScope | ||
|
||
A new Flutter package project. | ||
BlocDisposeScope adds support for bloc related types to [dispose_scope](https://pub.dev/packages/dispose_scope) package. | ||
|
||
## Getting Started | ||
## Usage | ||
|
||
This project is a starting point for a Dart | ||
[package](https://flutter.dev/developing-packages/), | ||
a library module containing code that can be shared easily across | ||
multiple Flutter or Dart projects. | ||
```dart | ||
import 'package:bloc_dispose_scope/bloc_dispose_scope.dart'; | ||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. | ||
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) {} | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,14 +1,26 @@ | ||
# dispose_scope | ||
# DisposeScope | ||
|
||
A new Flutter package project. | ||
DisposeScope reduces the amount of boilerplate related to disposing/canceling/closing objects when no longer needed. | ||
The `DisposeScope` class stores references to appropriate `dispose`/`close`/`cancel` methods and calls them when the scope is disposed. | ||
|
||
## Getting Started | ||
This package can be used by itself however it's mainly intended as base for [flutter_dispose_scope](https://pub.dev/packages/flutter_dispose_scope) and [bloc_dispose_scope](https://pub.dev/packages/bloc_dispose_scope) packages. | ||
|
||
This project is a starting point for a Dart | ||
[package](https://flutter.dev/developing-packages/), | ||
a library module containing code that can be shared easily across | ||
multiple Flutter or Dart projects. | ||
## Usage | ||
|
||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. | ||
```dart | ||
import 'package:dispose_scope/dispose_scope.dart'; | ||
final disposeScope = DisposeScope(); | ||
// StreamSubscription will be cancelled when disposeScope is disposed | ||
const Stream.empty().listen((event) {}).disposed(disposeScope); | ||
// Timer will be cancelled when disposeScope is disposed | ||
Timer(Duration.zero, () {}).disposed(disposeScope); | ||
disposeScope.dispose(); | ||
``` | ||
|
||
## Supported types | ||
|
||
This package contains extension methods for dart standard library classes requiring clean up. For additional extension methods checkout [flutter_dispose_scope](https://pub.dev/packages/flutter_dispose_scope) and [bloc_dispose_scope](https://pub.dev/packages/bloc_dispose_scope). |
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 |
---|---|---|
@@ -1,14 +1,36 @@ | ||
# flutter_dispose_scope | ||
# BlocDisposeScope | ||
|
||
A new Flutter package project. | ||
BlocDisposeScope adds support for flutter related types to [dispose_scope](https://pub.dev/packages/dispose_scope) package. | ||
|
||
## Getting Started | ||
## Usage | ||
|
||
This project is a starting point for a Dart | ||
[package](https://flutter.dev/developing-packages/), | ||
a library module containing code that can be shared easily across | ||
multiple Flutter or Dart projects. | ||
```dart | ||
import 'package:flutter_dispose_scope/flutter_dispose_scope.dart'; | ||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. | ||
class App extends StatefulWidget { | ||
const App({Key? key}) : super(key: key); | ||
@override | ||
_AppState createState() => _AppState(); | ||
} | ||
class _AppState extends State<App> with StateDisposeScopeMixin { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
// StreamSubscription will be cancelled when widget is disposed | ||
const Stream.empty().listen((event) {}).disposed(scope); | ||
// Timer will be cancelled when widget is disposed | ||
Timer(Duration.zero, () {}).disposed(scope); | ||
} | ||
@override | ||
Widget build(BuildContext context) { | ||
return const MaterialApp( | ||
home: SizedBox(), | ||
); | ||
} | ||
} | ||
``` |