flutter_disposebag 1.0.0

Flutter Android iOS web

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

flutter_disposebag #

Author: Petrus Nguyễn Thái Học #

Pub

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

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.

2
likes
110
pub points
62%
popularity

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

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

hoc081098@gmail.com

License

MIT (LICENSE)

Dependencies

disposebag, flutter, meta

More

Packages that depend on flutter_disposebag