Unverified Commit b2775340 authored by liyuqian's avatar liyuqian Committed by GitHub

Assert cache hints are not set for null painters (#49771)

parent 9fb781a5
...@@ -479,6 +479,7 @@ class CustomPaint extends SingleChildRenderObjectWidget { ...@@ -479,6 +479,7 @@ class CustomPaint extends SingleChildRenderObjectWidget {
}) : assert(size != null), }) : assert(size != null),
assert(isComplex != null), assert(isComplex != null),
assert(willChange != null), assert(willChange != null),
assert(painter != null || foregroundPainter != null || (!isComplex && !willChange)),
super(key: key, child: child); super(key: key, child: child);
/// The painter that paints before the children. /// The painter that paints before the children.
...@@ -503,10 +504,16 @@ class CustomPaint extends SingleChildRenderObjectWidget { ...@@ -503,10 +504,16 @@ class CustomPaint extends SingleChildRenderObjectWidget {
/// frame. If this flag is not set, then the compositor will apply its own /// frame. If this flag is not set, then the compositor will apply its own
/// heuristics to decide whether the this layer is complex enough to benefit /// heuristics to decide whether the this layer is complex enough to benefit
/// from caching. /// from caching.
///
/// This flag can't be set to true if both [painter] and [foregroundPainter]
/// are null because this flag will be ignored in such case.
final bool isComplex; final bool isComplex;
/// Whether the raster cache should be told that this painting is likely /// Whether the raster cache should be told that this painting is likely
/// to change in the next frame. /// to change in the next frame.
///
/// This flag can't be set to true if both [painter] and [foregroundPainter]
/// are null because this flag will be ignored in such case.
final bool willChange; final bool willChange;
@override @override
......
...@@ -223,4 +223,9 @@ void main() { ...@@ -223,4 +223,9 @@ void main() {
expect(renderCustom.isComplex, false); expect(renderCustom.isComplex, false);
expect(renderCustom.willChange, true); expect(renderCustom.willChange, true);
}); });
test('Raster cache hints cannot be set with null painters', () {
expect(() => CustomPaint(isComplex: true), throwsAssertionError);
expect(() => CustomPaint(willChange: true), throwsAssertionError);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment