From 12c5eb9b10ced2257da4a82c9ec19aaee972aa16 Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Fri, 18 Aug 2023 16:40:43 +0100 Subject: [PATCH] Removed unnecessary comparisons Improved internal documentation --- lib/src/map/layers_stack.dart | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/src/map/layers_stack.dart b/lib/src/map/layers_stack.dart index 8448e0282..159da726c 100644 --- a/lib/src/map/layers_stack.dart +++ b/lib/src/map/layers_stack.dart @@ -1,5 +1,7 @@ part of 'widget.dart'; +/// Batches all 'normal' layers into as few Stacks as possible whilst not moving +/// any 'anchored' layers, and applies necessary transformations to the Stacks class _LayersStack extends StatefulWidget { const _LayersStack({ required this.camera, @@ -16,8 +18,6 @@ class _LayersStack extends StatefulWidget { } class _LayersStackState extends State<_LayersStack> { - List children = []; - Iterable _prepareChildren() sync* { final stackChildren = []; @@ -37,28 +37,30 @@ class _LayersStackState extends State<_LayersStack> { } for (final Widget child in widget.children) { - if (child is AnchoredLayerStatefulMixin || - child is AnchoredLayerStatelessMixin) { - if (stackChildren.isNotEmpty) yield prepareRotateStack(); - final overlayChild = _AnchoredLayerDetectorAncestor(child: child); - yield widget.options.applyPointerTranslucencyToLayers - ? TranslucentPointer(child: overlayChild) - : overlayChild; - } else { + if (child is! AnchoredLayer) { stackChildren.add( widget.options.applyPointerTranslucencyToLayers ? TranslucentPointer(child: child) : child, ); + continue; } + + if (stackChildren.isNotEmpty) yield prepareRotateStack(); + final overlayChild = _AnchoredLayerDetectorAncestor(child: child); + yield widget.options.applyPointerTranslucencyToLayers + ? TranslucentPointer(child: overlayChild) + : overlayChild; } if (stackChildren.isNotEmpty) yield prepareRotateStack(); } + List _outputChildren = []; + @override void initState() { super.initState(); - children = _prepareChildren().toList(); + _outputChildren = _prepareChildren().toList(); } @override @@ -68,10 +70,10 @@ class _LayersStackState extends State<_LayersStack> { widget.camera != oldWidget.camera || widget.options.applyPointerTranslucencyToLayers != oldWidget.options.applyPointerTranslucencyToLayers) { - children = _prepareChildren().toList(); + _outputChildren = _prepareChildren().toList(); } } @override - Widget build(BuildContext context) => Stack(children: children); + Widget build(BuildContext context) => Stack(children: _outputChildren); }