diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 765a5fc00b8..0d37556be73 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -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 diff --git a/packages/flutter/test/widgets/custom_paint_test.dart b/packages/flutter/test/widgets/custom_paint_test.dart index cb2f651bb91..83881dfb097 100644 --- a/packages/flutter/test/widgets/custom_paint_test.dart +++ b/packages/flutter/test/widgets/custom_paint_test.dart @@ -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); + }); }