Skip to content

Commit

Permalink
Do not assert callbacks contains key if disposed (#104292)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored May 20, 2022
1 parent 6631e63 commit 1c852ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/rendering/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
15 changes: 15 additions & 0 deletions packages/flutter/test/rendering/layers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1c852ce

Please sign in to comment.