diff --git a/example/lib/simple_example.dart b/example/lib/simple_example.dart index f1fd200..7f21acb 100644 --- a/example/lib/simple_example.dart +++ b/example/lib/simple_example.dart @@ -28,6 +28,28 @@ class _SimpleExampleState extends State { ), ); } + controller.addChild( + const Offset(0, 200), + Container( + width: 300, + height: 150, + color: Colors.grey[200], + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + 'This is a very long text inside a scrollable container. ' + 'You can scroll to see more content. ' + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' + 'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' + 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' + 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.', + style: const TextStyle(fontSize: 16), + ), + ), + ), + ), + ); } @override diff --git a/lib/core/render.dart b/lib/core/render.dart index 1d61e59..ccf15b6 100644 --- a/lib/core/render.dart +++ b/lib/core/render.dart @@ -246,14 +246,22 @@ class _CanvasRenderBox extends RenderBox while (child != null) { final _CanvasWidgetParentData childParentData = child.parentData! as _CanvasWidgetParentData; - context.canvas.save(); - // relying purely on canvas manips here final drawAt = canvasStartOffset + childParentData.offset; - context.canvas.translate(drawAt.dx, drawAt.dy); - context.canvas.scale(childParentData.scale, childParentData.scale); - context.paintChild(child, Offset.zero); // paint at 0 as already translated - context.canvas.restore(); + // Apply transformation using pushTransform for proper coordinate handling + final transform = Matrix4.identity() + ..translate(drawAt.dx, drawAt.dy) + ..scale(childParentData.scale, childParentData.scale); + + // Note: initially I was using context.canvas.translate and context.canvas.scale + // but that doesn't work with say using a SingleChildScrollView inside a child + // so using pushTransform is the way to go here + + // 0 offset since transform will take care of it + context.pushTransform(needsCompositing, Offset.zero, transform, (context, offset) { + context.paintChild(child!, Offset.zero); + }); + child = childParentData.nextSibling; }