Skip to content

Commit 264fc66

Browse files
committed
refactor: Address review comments on lazy render contexts
1 parent 7c4ec65 commit 264fc66

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

packages/flame/lib/src/components/core/component.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ class Component {
598598
/// cleans them up afterwards.
599599
@protected
600600
void renderChild(Canvas canvas, Component child) {
601-
final contexts = _renderContexts;
602-
if (contexts == null || contexts.isEmpty) {
601+
final contexts = _renderContexts ?? const <ComponentRenderContext>[];
602+
if (contexts.isEmpty) {
603603
child.renderTree(canvas);
604604
return;
605605
}
@@ -619,8 +619,10 @@ class Component {
619619

620620
void renderTree(Canvas canvas) {
621621
final context = renderContext;
622+
List<ComponentRenderContext>? renderContexts;
622623
if (context != null) {
623-
(_renderContexts ??= []).add(context);
624+
renderContexts = _renderContexts ??= [];
625+
renderContexts.add(context);
624626
}
625627

626628
render(canvas);
@@ -637,9 +639,7 @@ class Component {
637639
renderDebugMode(canvas);
638640
}
639641

640-
if (context != null) {
641-
_renderContexts!.removeLast();
642-
}
642+
renderContexts?.removeLast();
643643
}
644644

645645
//#endregion

0 commit comments

Comments
 (0)