mirror of
https://github.com/flutter/flutter
synced 2024-08-27 20:10:11 +00:00
Can call ChangeNotifier.hasListeners after disposed (#108931)
This commit is contained in:
parent
c22b7f697f
commit
6225bea261
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue