I'm building a custom RenderObject
to draw multiple portions of child widget in different positions and clipped differently (layout, hit testing, semantics and other RenderObject aspects are not revelant here). I managed to get it working, but code breaks for more complex descendants (eg. FlutterLogo()
works but Scaffold()
not) - child is painted only on the first (or maybe last) paintChild
call.
I've read RenderObject
documentation and haven't found anything that would prohibit painting the child multiple times during single paint phase. On the other hand, I haven't found any RenderObjects that would do this. I suspect that this won't work when child is creating its own layer and the layer gets reused between paint
calls. Wrapping any child
in RepaintBoundary
seems enough to break it.
class RenderExample extends RenderProxyBox {
final _clipLayerHandles = [for (int i = 0; i < _gameChildCount; i++) LayerHandle<ClipRectLayer>()];
//...
@override
bool get isRepaintBoundary => true;
@override
void dispose() {
for (final handle in _clipLayerHandles) {
handle.layer?.dispose();
}
super.dispose();
}
@override
void paint(PaintingContext context, Offset offset) {
for (...) {
_clipLayerHandles[childIndex].layer = context.pushClipRect(
needsCompositing,
offset,
parentRect,
(context, offset) => context.paintChild(child!, offset + parentOffset - childOffset),
oldLayer: _clipLayerHandles[childIndex].layer,
);
}
}
}
Do you have any insights? Is it something that is impossible in the engine? If so, why? Is there any hack to make it work?