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
b00efda7
Commit
b00efda7
authored
Jun 24, 2016
by
Adam Barth
Committed by
GitHub
Jun 24, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve change notifier (#4747)
This patch improves some subtle behaviors about the change notifier.
parent
490622b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
change_notifier.dart
packages/flutter/lib/src/foundation/change_notifier.dart
+8
-5
change_notifier_test.dart
packages/flutter/test/foundation/change_notifier_test.dart
+1
-1
No files found.
packages/flutter/lib/src/foundation/change_notifier.dart
View file @
b00efda7
...
...
@@ -30,23 +30,26 @@ abstract class ChangeNotifier {
/// This method should only be called by the object's owner.
@mustCallSuper
void
dispose
()
{
_listeners
=
null
;
_listeners
=
const
<
VoidCallback
>[]
;
}
/// Call all the registered listeners.
///
/// Call this method whenever the object changes, to notify any clients the
/// object may have.
/// object may have. Listeners that are added during this iteration will not
/// be visited. Listeners that are removed during this iteration will not be
/// visited after they are removed.
///
/// Exceptions thrown by listeners will be caught and reported using
/// [FlutterError.reportError].
@protected
void
notifyListeners
()
{
if
(
_listeners
!=
null
)
{
List
<
VoidCallback
>
listeners
=
new
List
<
VoidCallback
>.
from
(
_listeners
);
for
(
VoidCallback
listener
in
listeners
)
{
List
<
VoidCallback
>
l
ocalL
isteners
=
new
List
<
VoidCallback
>.
from
(
_listeners
);
for
(
VoidCallback
listener
in
l
ocalL
isteners
)
{
try
{
listener
();
if
(
_listeners
.
contains
(
listener
))
listener
();
}
catch
(
exception
,
stack
)
{
FlutterError
.
reportError
(
new
FlutterErrorDetails
(
exception:
exception
,
...
...
packages/flutter/test/foundation/change_notifier_test.dart
View file @
b00efda7
...
...
@@ -102,7 +102,7 @@ void main() {
test
.
addListener
(
listener2
);
test
.
addListener
(
listener3
);
test
.
notify
();
expect
(
log
,
equals
(<
String
>[
'listener1'
,
'listener2'
,
'listener3'
]));
expect
(
log
,
equals
(<
String
>[
'listener1'
,
'listener2'
]));
log
.
clear
();
test
.
notify
();
...
...
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