123456789101112131415161718192021222324 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- mixin SubscriptionState<T extends StatefulWidget> on State<T> {
- final List<StreamSubscription<dynamic>> _streamSubscriptions = <StreamSubscription<dynamic>>[];
- void addSubscription(StreamSubscription<dynamic> streamSubscription) {
- _streamSubscriptions.add(streamSubscription);
- }
- @override
- void dispose() {
- disposeSubscription();
- super.dispose();
- }
- disposeSubscription() async {
- for (StreamSubscription<dynamic> subscription in _streamSubscriptions.reversed) {
- await subscription.cancel();
- }
- _streamSubscriptions.clear();
- }
- }
|