Do not assert callbacks contains key if disposed (#104292)

This commit is contained in:
Dan Field
2022-05-20 14:51:14 -07:00
committed by GitHub
parent 6631e63eee
commit 1c852cedaa
2 changed files with 16 additions and 1 deletions

View File

@@ -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);
};

View File

@@ -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 {