From 0f1d5c452e46e16f2f71e3a655cc311f8e03a47d Mon Sep 17 00:00:00 2001 From: Hagen Schendel Date: Thu, 12 May 2022 14:44:47 -0500 Subject: [PATCH] [BUG] Emit move event even when source is custom #1231 (#1232) * Emit a move event on zoom or center change when event source is custom #1231 * Remove unnecessary ? operator in example code found by dart analyze Co-authored-by: Hagen Schendel --- .../lib/pages/tile_loading_error_handle.dart | 2 +- lib/src/map/map.dart | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/example/lib/pages/tile_loading_error_handle.dart b/example/lib/pages/tile_loading_error_handle.dart index 549e7142e..9aac0764b 100644 --- a/example/lib/pages/tile_loading_error_handle.dart +++ b/example/lib/pages/tile_loading_error_handle.dart @@ -50,7 +50,7 @@ class _TileLoadingErrorHandleState extends State { tileProvider: const NonCachingNetworkTileProvider(), errorTileCallback: (Tile tile, error) { if (_needLoadingError) { - WidgetsBinding.instance?.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( duration: const Duration(seconds: 1), content: Text( diff --git a/lib/src/map/map.dart b/lib/src/map/map.dart index 43c359488..761bbcf65 100644 --- a/lib/src/map/map.dart +++ b/lib/src/map/map.dart @@ -255,6 +255,23 @@ class MapState { source: source, ), ); + } else if (source == MapEventSource.custom) { + // for custom source, emit move event if zoom or center has changed + if (targetZoom != _zoom || + _lastCenter == null || + targetCenter.latitude != _lastCenter!.latitude || + targetCenter.longitude != _lastCenter!.longitude) { + emitMapEvent( + MapEventMove( + id: id, + center: _lastCenter!, + zoom: _zoom, + targetCenter: targetCenter, + targetZoom: targetZoom, + source: source, + ), + ); + } } }