flutter_disposebag 1.0.0
flutter_disposebag: ^1.0.0 copied to clipboard

Flutter Android iOS Linux macOS web Windows

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

example/main.dart

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();
  }
}
2
likes
100
pub points
69%
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