easy_dispose 1.1.0 copy "easy_dispose: ^1.1.0" to clipboard
easy_dispose: ^1.1.0 copied to clipboard

Common interface to dispose different things. Always call dispose() instead of cancel(), stop(), etc.

example/main.dart

import 'dart:async';

import 'package:easy_dispose/easy_dispose.dart';

// ignore_for_file: no-empty-block, avoid_print
Future main() async {
  final myDisposableOwner = MyDisposableOwner();

  // do something

  await myDisposableOwner.dispose();
}

class MyDisposableOwner extends DisposableOwner {
  final StreamController streamController = StreamController<dynamic>();
  final Timer timer = Timer(
    const Duration(seconds: 5),
    () async {},
  );

  MyDisposableOwner()
      : super(
          disposeOrder: DisposeOrder.lifo,
        ) {
    addCustomDisposable(() => print('Final dispose'));
    streamController.disposeWith(this);
    timer.disposeWith(this);

    streamController.stream
        .listen(
          (dynamic event) {},
        )
        .disposeWith(this);
    addCustomDisposable(() => print('First dispose'));
  }
}
1
likes
140
pub points
69%
popularity

Publisher

unverified uploader

Common interface to dispose different things. Always call dispose() instead of cancel(), stop(), etc.

Repository (GitHub)
View/report issues

Documentation

API reference

License

AGPL-3.0 (LICENSE)

More

Packages that depend on easy_dispose