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
6225bea2
Unverified
Commit
6225bea2
authored
Aug 04, 2022
by
chunhtai
Committed by
GitHub
Aug 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Can call ChangeNotifier.hasListeners after disposed (#108931)
parent
c22b7f69
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
change_notifier.dart
packages/flutter/lib/src/foundation/change_notifier.dart
+3
-4
change_notifier_test.dart
packages/flutter/test/foundation/change_notifier_test.dart
+14
-0
No files found.
packages/flutter/lib/src/foundation/change_notifier.dart
View file @
6225bea2
...
...
@@ -170,11 +170,10 @@ class ChangeNotifier implements Listenable {
/// [notifyListeners]; and similarly, by overriding [removeListener], checking
/// if [hasListeners] is false after calling `super.removeListener()`, and if
/// so, stopping that same work.
///
/// This method returns false if [dispose] has been called.
@protected
bool
get
hasListeners
{
assert
(
ChangeNotifier
.
debugAssertNotDisposed
(
this
));
return
_count
>
0
;
}
bool
get
hasListeners
=>
_count
>
0
;
/// Register a closure to be called when the object changes.
///
...
...
packages/flutter/test/foundation/change_notifier_test.dart
View file @
6225bea2
...
...
@@ -349,6 +349,20 @@ void main() {
expect
(
error
,
isNull
);
});
test
(
'Can check hasListener on a disposed ChangeNotifier'
,
()
{
final
HasListenersTester
<
int
>
source
=
HasListenersTester
<
int
>(
0
);
source
.
addListener
(()
{
});
expect
(
source
.
testHasListeners
,
isTrue
);
FlutterError
?
error
;
try
{
source
.
dispose
();
expect
(
source
.
testHasListeners
,
isFalse
);
}
on
FlutterError
catch
(
e
)
{
error
=
e
;
}
expect
(
error
,
isNull
);
});
test
(
'Value notifier'
,
()
{
final
ValueNotifier
<
double
>
notifier
=
ValueNotifier
<
double
>(
2.0
);
...
...
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