Skip to content

Automatically disposes StreamSubscription and closes Sink when disposing State<T>.

License

Notifications You must be signed in to change notification settings

Flutter-Dart-Open-Source/flutter_disposebag

Folders and files

NameName
Last commit message
Last commit date
Aug 12, 2022
Feb 14, 2021
Dec 10, 2021
Feb 14, 2021
Feb 14, 2021
Feb 14, 2021
Oct 6, 2021
Mar 21, 2021
Feb 14, 2021
Feb 22, 2021
Mar 21, 2021
Oct 6, 2021
Jul 6, 2021

Repository files navigation

flutter_disposebag

Pub Pub Version codecov Flutter Tests

  • A package to help disposing Streams and closing Sinks easily for Flutter.
  • Automatically disposes StreamSubscription and closes Sink when disposing State<T>.

Medium article

How to easily cancel streams in Flutter

Usage

A simple usage example:

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_disposebag/flutter_disposebag.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with DisposeBagMixin {
  final controller = StreamController<int>();

  @override
  void initState() {
    super.initState();

    Stream.periodic(const Duration(milliseconds: 500), (i) => i)
        .listen((event) {})
        .disposedBy(bag);

    controller.stream.listen((event) {}).disposedBy(bag);
    controller.disposedBy(bag);
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Features and bugs

Please file feature requests and bugs at the issue tracker.