Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7b5ec588
Unverified
Commit
7b5ec588
authored
Feb 26, 2024
by
Nate
Committed by
GitHub
Feb 26, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow `Listenable.merge()` to use any iterable (#143675)
This is a very small change that fixes #143664.
parent
c82ca469
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
change_notifier.dart
packages/flutter/lib/src/foundation/change_notifier.dart
+5
-5
change_notifier_test.dart
packages/flutter/test/foundation/change_notifier_test.dart
+15
-0
No files found.
packages/flutter/lib/src/foundation/change_notifier.dart
View file @
7b5ec588
...
...
@@ -62,11 +62,11 @@ abstract class Listenable {
/// Return a [Listenable] that triggers when any of the given [Listenable]s
/// themselves trigger.
///
///
The list must not be changed after this method has been called. Doing so
/// will lead to memory leaks or exceptions.
///
Once the factory is called, items must not be added or removed from the iterable.
///
Doing so
will lead to memory leaks or exceptions.
///
/// The
list
may contain nulls; they are ignored.
factory
Listenable
.
merge
(
List
<
Listenable
?>
listenables
)
=
_MergingListenable
;
/// The
iterable
may contain nulls; they are ignored.
factory
Listenable
.
merge
(
Iterable
<
Listenable
?>
listenables
)
=
_MergingListenable
;
/// Register a closure to be called when the object notifies its listeners.
void
addListener
(
VoidCallback
listener
);
...
...
@@ -491,7 +491,7 @@ mixin class ChangeNotifier implements Listenable {
class
_MergingListenable
extends
Listenable
{
_MergingListenable
(
this
.
_children
);
final
List
<
Listenable
?>
_children
;
final
Iterable
<
Listenable
?>
_children
;
@override
void
addListener
(
VoidCallback
listener
)
{
...
...
packages/flutter/test/foundation/change_notifier_test.dart
View file @
7b5ec588
...
...
@@ -314,6 +314,21 @@ void main() {
log
.
clear
();
});
test
(
'Merging change notifiers supports any iterable'
,
()
{
final
TestNotifier
source1
=
TestNotifier
();
final
TestNotifier
source2
=
TestNotifier
();
final
List
<
String
>
log
=
<
String
>[];
final
Listenable
merged
=
Listenable
.
merge
(<
Listenable
?>{
source1
,
source2
});
void
listener
()
=>
log
.
add
(
'listener'
);
merged
.
addListener
(
listener
);
source1
.
notify
();
source2
.
notify
();
expect
(
log
,
<
String
>[
'listener'
,
'listener'
]);
log
.
clear
();
});
test
(
'Merging change notifiers ignores null'
,
()
{
final
TestNotifier
source1
=
TestNotifier
();
final
TestNotifier
source2
=
TestNotifier
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment