From 5839501f49a10e69d48157fb92b8b13ef0e48391 Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Tue, 25 Jun 2024 12:10:58 +0200 Subject: [PATCH] Fix #437 toggling myLocationEnabled in example (#457) `myLocationEnabled` can only be disabled for `MyLocationRenderMode.normal` - it is required for gps/compass. This change disables the appropriate buttons and actually passes the current render mode to the map widget. Fixes #437 Co-authored-by: Joscha <34318751+josxha@users.noreply.github.com> --- example/lib/map_ui.dart | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/example/lib/map_ui.dart b/example/lib/map_ui.dart index 8321fd50..dc405f5c 100644 --- a/example/lib/map_ui.dart +++ b/example/lib/map_ui.dart @@ -62,6 +62,7 @@ class MapUiBodyState extends State { bool _telemetryEnabled = true; bool _countriesVisible = true; MyLocationTrackingMode _myLocationTrackingMode = MyLocationTrackingMode.none; + MyLocationRenderMode _myLocationRenderMode = MyLocationRenderMode.normal; List? _featureQueryFilter; Fill? _selectedFill; @@ -97,6 +98,22 @@ class MapUiBodyState extends State { ); } + Widget _myLocationRenderModeCycler() { + final MyLocationRenderMode nextType = MyLocationRenderMode.values[ + (_myLocationRenderMode.index + 1) % MyLocationRenderMode.values.length]; + return TextButton( + onPressed: + _myLocationEnabled == true || nextType == MyLocationRenderMode.normal + ? () { + setState(() { + _myLocationRenderMode = nextType; + }); + } + : null, + child: Text('change to $nextType'), + ); + } + Widget _queryFilterToggler() { return TextButton( child: Text( @@ -251,12 +268,14 @@ class MapUiBodyState extends State { Widget _myLocationToggler() { return TextButton( + onPressed: _myLocationRenderMode == MyLocationRenderMode.normal + ? () { + setState(() { + _myLocationEnabled = !_myLocationEnabled; + }); + } + : null, child: Text('${_myLocationEnabled ? 'disable' : 'enable'} my location'), - onPressed: () { - setState(() { - _myLocationEnabled = !_myLocationEnabled; - }); - }, ); } @@ -355,7 +374,7 @@ class MapUiBodyState extends State { doubleClickZoomEnabled: _doubleClickToZoomEnabled, myLocationEnabled: _myLocationEnabled, myLocationTrackingMode: _myLocationTrackingMode, - myLocationRenderMode: MyLocationRenderMode.gps, + myLocationRenderMode: _myLocationRenderMode, onMapClick: (point, latLng) async { debugPrint( "Map click: ${point.x},${point.y} ${latLng.latitude}/${latLng.longitude}"); @@ -420,6 +439,7 @@ class MapUiBodyState extends State { _queryFilterToggler(), _compassToggler(), _myLocationTrackingModeCycler(), + _myLocationRenderModeCycler(), _latLngBoundsToggler(), _setStyleToSatellite(), _zoomBoundsToggler(),