Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #437 toggling myLocationEnabled in example #457

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions example/lib/map_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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 @@ -99,6 +100,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 @@ -253,12 +270,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 @@ -358,7 +377,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 @@ -423,6 +442,7 @@ class MapUiBodyState extends State<MapUiBody> {
_queryFilterToggler(),
_compassToggler(),
_myLocationTrackingModeCycler(),
_myLocationRenderModeCycler(),
_latLngBoundsToggler(),
_setStyleToSatellite(),
_zoomBoundsToggler(),
Expand Down