From 4a54a9783f3a1af5f031c2c7a999a759a699ae30 Mon Sep 17 00:00:00 2001 From: Jan Stehno Date: Thu, 30 Jul 2026 11:29:31 +0200 Subject: [PATCH] Preserve async tile loading state Fixes flickering during map movement when tiles are loaded asynchronously. This change adds a ValueKey to each tile widget based on its zoom level and tile coordinates. --- CHANGELOG.md | 4 ++++ lib/src/layers/tile_layer.dart | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0896ac..34ade50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.0.3] + +* Preserve tile widget state during map movement to prevent flickering with asynchronously loaded tiles. + ## [2.0.2] * Shape layers are more customizable now. diff --git a/lib/src/layers/tile_layer.dart b/lib/src/layers/tile_layer.dart index f4a9dbd..4699521 100644 --- a/lib/src/layers/tile_layer.dart +++ b/lib/src/layers/tile_layer.dart @@ -80,12 +80,12 @@ class _TileLayerState extends State { final oy = (j * tileSizeScaled) + centerY - ttl.y; final child = Positioned( + key: ValueKey('$fixedZoom/$i/$j'), width: tileSizeScaled.ceilToDouble(), height: tileSizeScaled.ceilToDouble(), left: ox.floorToDouble(), top: oy.floorToDouble(), - child: widget.builder - .call(context, i, j, (_controller.zoom + 0.0000001).floor()), + child: widget.builder.call(context, i, j, fixedZoom), ); children.add(child); diff --git a/pubspec.yaml b/pubspec.yaml index 35e902b..24b6c0b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: map description: Geographical Map widget for flutter supporting different projections including EPSG4326/Mercator/WGS1984. -version: 2.0.2 +version: 2.0.3 homepage: https://pwa.ir repository: https://github.com/xclud/flutter_map