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

This commit is contained in:
liyuqian 2020-02-11 02:03:03 +08:00 committed by GitHub
parent 9fb781a54a
commit b277534026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -479,6 +479,7 @@ class CustomPaint extends SingleChildRenderObjectWidget {
}) : assert(size != null),
assert(isComplex != null),
assert(willChange != null),
assert(painter != null || foregroundPainter != null || (!isComplex && !willChange)),
super(key: key, child: child);
/// The painter that paints before the children.
@ -503,10 +504,16 @@ class CustomPaint extends SingleChildRenderObjectWidget {
/// 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
/// 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;
/// Whether the raster cache should be told that this painting is likely
/// 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;
@override

View File

@ -223,4 +223,9 @@ void main() {
expect(renderCustom.isComplex, false);
expect(renderCustom.willChange, true);
});
test('Raster cache hints cannot be set with null painters', () {
expect(() => CustomPaint(isComplex: true), throwsAssertionError);
expect(() => CustomPaint(willChange: true), throwsAssertionError);
});
}