Skip to content

Commit

Permalink
Fix #437 toggling myLocationEnabled in example (#457)
Browse files Browse the repository at this point in the history
`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 <[email protected]>
  • Loading branch information
kuhnroyal and josxha committed Jun 25, 2024
1 parent a47b279 commit 5839501
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions example/lib/map_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MapUiBodyState extends State<MapUiBody> {
bool _telemetryEnabled = true;
bool _countriesVisible = true;
MyLocationTrackingMode _myLocationTrackingMode = MyLocationTrackingMode.none;
MyLocationRenderMode _myLocationRenderMode = MyLocationRenderMode.normal;
List<Object>? _featureQueryFilter;
Fill? _selectedFill;

Expand Down Expand Up @@ -97,6 +98,22 @@ class MapUiBodyState extends State<MapUiBody> {
);
}

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(
Expand Down Expand Up @@ -251,12 +268,14 @@ class MapUiBodyState extends State<MapUiBody> {

Widget _myLocationToggler() {
return TextButton(
onPressed: _myLocationRenderMode == MyLocationRenderMode.normal
? () {
setState(() {
_myLocationEnabled = !_myLocationEnabled;
});
}
: null,
child: Text('${_myLocationEnabled ? 'disable' : 'enable'} my location'),
onPressed: () {
setState(() {
_myLocationEnabled = !_myLocationEnabled;
});
},
);
}

Expand Down Expand Up @@ -355,7 +374,7 @@ class MapUiBodyState extends State<MapUiBody> {
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}");
Expand Down Expand Up @@ -420,6 +439,7 @@ class MapUiBodyState extends State<MapUiBody> {
_queryFilterToggler(),
_compassToggler(),
_myLocationTrackingModeCycler(),
_myLocationRenderModeCycler(),
_latLngBoundsToggler(),
_setStyleToSatellite(),
_zoomBoundsToggler(),
Expand Down

0 comments on commit 5839501

Please sign in to comment.