1212
1313import 'dart:async' show FutureOr;
1414
15- import 'package:df_type/df_type.dart' show FutureOrController;
16- import 'package:flutter/foundation.dart'
17- show kDebugMode, mustCallSuper, nonVirtual;
15+ import 'package:df_type/df_type.dart' show SequentialController;
16+ import 'package:flutter/foundation.dart' show kDebugMode, mustCallSuper, nonVirtual;
1817
1918// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2019
@@ -27,8 +26,7 @@ import 'package:flutter/foundation.dart'
2726/// invoked on each resource wrapped with [willDispose] .
2827mixin WillDisposeMixin on DisposeMixin {
2928 /// The list of resources marked for dispose via [willDispose] .
30- Set <_ToDisposeResource <dynamic >> get toDisposeResources =>
31- Set .unmodifiable (_toDisposeResources);
29+ Set <_ToDisposeResource <dynamic >> get toDisposeResources => Set .unmodifiable (_toDisposeResources);
3230
3331 final Set <_ToDisposeResource <dynamic >> _toDisposeResources = {};
3432
@@ -50,14 +48,11 @@ mixin WillDisposeMixin on DisposeMixin {
5048 _verifyDisposeMethod (resource);
5149 final disposable = (
5250 resource: resource as dynamic ,
53- onBeforeDispose: onBeforeDispose != null
54- ? (dynamic e) => onBeforeDispose (e as T )
55- : null ,
51+ onBeforeDispose: onBeforeDispose != null ? (dynamic e) => onBeforeDispose (e as T ) : null ,
5652 );
5753
5854 // Check for any duplicate resource.
59- final duplicate =
60- _toDisposeResources.where ((e) => e.resource == resource).firstOrNull;
55+ final duplicate = _toDisposeResources.where ((e) => e.resource == resource).firstOrNull;
6156
6257 if (duplicate != null ) {
6358 if (kDebugMode) {
@@ -79,11 +74,11 @@ mixin WillDisposeMixin on DisposeMixin {
7974 @mustCallSuper
8075 @override
8176 FutureOr <void > dispose () {
82- final foc = FutureOrController <void >();
77+ final sc = SequentialController <void >();
8378
8479 try {
8580 // Call the parent's dispose method.
86- foc .add ((_) => super .dispose ());
81+ sc .add ((_) => super .dispose ());
8782
8883 for (final disposable in _toDisposeResources) {
8984 final resource = disposable.resource;
@@ -93,13 +88,13 @@ mixin WillDisposeMixin on DisposeMixin {
9388 // Attempt to call onBeforeDispose, catching and copying any exceptions.
9489 Object ? onBeforeDisposeError;
9590 try {
96- foc .add ((_) => disposable.onBeforeDispose? .call (resource));
91+ sc .add ((_) => disposable.onBeforeDispose? .call (resource));
9792 } catch (e) {
9893 onBeforeDisposeError = e;
9994 }
10095
10196 // Attempt to call dispose on the resource.
102- foc .add ((_) => resource.dispose ());
97+ sc .add ((_) => resource.dispose ());
10398
10499 // If successful, rethrow any exception from onBeforeDispose.
105100 if (onBeforeDisposeError != null ) {
@@ -109,11 +104,11 @@ mixin WillDisposeMixin on DisposeMixin {
109104 } catch (e) {
110105 // Collect exceptions to throw them all at the end, ensuring dispose gets
111106 // called on all resources.
112- foc .addException (e);
107+ sc .addException (e);
113108 }
114109
115110 // Return a Future or complete synchronously.
116- return foc .complete ();
111+ return sc .complete ();
117112 }
118113
119114 /// Throws [NoDisposeMethodDebugError] if [resource] does not have a `dispose`
@@ -168,8 +163,7 @@ final class WillAlreadyDisposeDebugError<T> extends Error {
168163 WillAlreadyDisposeDebugError (this .resource);
169164
170165 @override
171- String toString () =>
172- '[$WillAlreadyDisposeDebugError ] willDispose has already '
166+ String toString () => '[$WillAlreadyDisposeDebugError ] willDispose has already '
173167 'been called on the resource ${resource .hashCode } and of type $T .' ;
174168}
175169
0 commit comments