Do not assert callbacks contains key if disposed (#104292)
This commit is contained in:
@@ -214,7 +214,7 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin {
|
||||
}());
|
||||
};
|
||||
return () {
|
||||
assert(_callbacks.containsKey(callbackId));
|
||||
assert(debugDisposed || _callbacks.containsKey(callbackId));
|
||||
_callbacks.remove(callbackId);
|
||||
_updateSubtreeCompositionObserverCount(-1);
|
||||
};
|
||||
|
||||
@@ -965,6 +965,21 @@ void main() {
|
||||
expect(root.subtreeHasCompositionCallbacks, false);
|
||||
expect(a1.subtreeHasCompositionCallbacks, false);
|
||||
});
|
||||
|
||||
test('Double removing a observe callback throws', () {
|
||||
final ContainerLayer root = ContainerLayer();
|
||||
final VoidCallback callback = root.addCompositionCallback((_) { });
|
||||
callback();
|
||||
|
||||
expect(() => callback(), throwsAssertionError);
|
||||
});
|
||||
|
||||
test('Removing an observe callback on a disposed layer does not throw', () {
|
||||
final ContainerLayer root = ContainerLayer();
|
||||
final VoidCallback callback = root.addCompositionCallback((_) { });
|
||||
root.dispose();
|
||||
expect(() => callback(), returnsNormally);
|
||||
});
|
||||
}
|
||||
|
||||
class FakeEngineLayer extends Fake implements EngineLayer {
|
||||
|
||||
Reference in New Issue
Block a user