File tree 2 files changed +20
-5
lines changed
2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -62,11 +62,11 @@ abstract class Listenable {
62
62
/// Return a [Listenable] that triggers when any of the given [Listenable] s
63
63
/// themselves trigger.
64
64
///
65
- /// The list must not be changed after this method has been called. Doing so
66
- /// will lead to memory leaks or exceptions.
65
+ /// Once the factory is called, items must not be added or removed from the iterable.
66
+ /// Doing so will lead to memory leaks or exceptions.
67
67
///
68
- /// The list may contain nulls; they are ignored.
69
- factory Listenable .merge (List <Listenable ?> listenables) = _MergingListenable ;
68
+ /// The iterable may contain nulls; they are ignored.
69
+ factory Listenable .merge (Iterable <Listenable ?> listenables) = _MergingListenable ;
70
70
71
71
/// Register a closure to be called when the object notifies its listeners.
72
72
void addListener (VoidCallback listener);
@@ -491,7 +491,7 @@ mixin class ChangeNotifier implements Listenable {
491
491
class _MergingListenable extends Listenable {
492
492
_MergingListenable (this ._children);
493
493
494
- final List <Listenable ?> _children;
494
+ final Iterable <Listenable ?> _children;
495
495
496
496
@override
497
497
void addListener (VoidCallback listener) {
Original file line number Diff line number Diff line change @@ -314,6 +314,21 @@ void main() {
314
314
log.clear ();
315
315
});
316
316
317
+ test ('Merging change notifiers supports any iterable' , () {
318
+ final TestNotifier source1 = TestNotifier ();
319
+ final TestNotifier source2 = TestNotifier ();
320
+ final List <String > log = < String > [];
321
+
322
+ final Listenable merged = Listenable .merge (< Listenable ? > {source1, source2});
323
+ void listener () => log.add ('listener' );
324
+
325
+ merged.addListener (listener);
326
+ source1.notify ();
327
+ source2.notify ();
328
+ expect (log, < String > ['listener' , 'listener' ]);
329
+ log.clear ();
330
+ });
331
+
317
332
test ('Merging change notifiers ignores null' , () {
318
333
final TestNotifier source1 = TestNotifier ();
319
334
final TestNotifier source2 = TestNotifier ();
You can’t perform that action at this time.
0 commit comments