diff --git a/packages/flutter/lib/src/rendering/layer.dart b/packages/flutter/lib/src/rendering/layer.dart index a298d50489..72f6f859b2 100644 --- a/packages/flutter/lib/src/rendering/layer.dart +++ b/packages/flutter/lib/src/rendering/layer.dart @@ -2503,6 +2503,8 @@ class LeaderLayer extends ContainerLayer { Matrix4.translationValues(offset.dx, offset.dy, 0.0).storage, oldLayer: _engineLayer as ui.TransformEngineLayer?, ); + } else { + engineLayer = null; } addChildrenToScene(builder); if (offset != Offset.zero) { diff --git a/packages/flutter/test/widgets/composited_transform_test.dart b/packages/flutter/test/widgets/composited_transform_test.dart index 42a076def3..f46294f304 100644 --- a/packages/flutter/test/widgets/composited_transform_test.dart +++ b/packages/flutter/test/widgets/composited_transform_test.dart @@ -56,6 +56,35 @@ void main() { expect(box.localToGlobal(Offset.zero), const Offset(118.0, 451.0)); }); + testWidgets('LeaderLayer should not cause error', (WidgetTester tester) async { + final LayerLink link = LayerLink(); + + Widget buildWidget({ + required double paddingLeft, + Color siblingColor = const Color(0xff000000), + }) { + return Directionality( + textDirection: TextDirection.ltr, + child: Stack( + children: [ + Padding( + padding: EdgeInsets.only(left: paddingLeft), + child: CompositedTransformTarget( + link: link, + child: RepaintBoundary(child: ClipRect(child: Container(color: const Color(0x00ff0000)))), + ), + ), + Positioned.fill(child: RepaintBoundary(child: ColoredBox(color: siblingColor))), + ], + ), + ); + } + + await tester.pumpWidget(buildWidget(paddingLeft: 10)); + await tester.pumpWidget(buildWidget(paddingLeft: 0)); + await tester.pumpWidget(buildWidget(paddingLeft: 0, siblingColor: const Color(0x0000ff00))); + }); + group('Composited transforms - only offsets', () { final GlobalKey key = GlobalKey();