Skip to content

Commit

Permalink
Keep screen on if the map follows the users location
Browse files Browse the repository at this point in the history
  • Loading branch information
Xennis committed Nov 10, 2023
1 parent 429f350 commit 2689022
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
4 changes: 3 additions & 1 deletion green_walking/lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@
"geocodingResultLegalNotice": "Suchergebnisse: {legalNotice}",
"geocodingAdvancedSearchButton": "Erweiterte Suche",
"openLocationInDefaultAppSemanticLabel": "Öffnen mit Standardapp",
"openLocationDetailsSemanticLabel": "Details anzeigen"
"openLocationDetailsSemanticLabel": "Details anzeigen",
"followLocationToast": "Position folgen",
"followLocationOffToast": "Position folgen aus"
}
8 changes: 8 additions & 0 deletions green_walking/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,13 @@
"openLocationDetailsSemanticLabel": "Show details",
"@openLocationDetailsSemanticLabel": {
"description": "Semantic label to open details of a location."
},
"followLocationToast": "Follow location",
"@followLocationToast": {
"description": "Toast message if the map follows the user location."
},
"followLocationOffToast": "Follow location off",
"@followLocationOffToast": {
"description": "Toast message if the map stops following the users location."
}
}
15 changes: 13 additions & 2 deletions green_walking/lib/widgets/map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:developer' show log;
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

import '../library/map_utils.dart';
import '../services/shared_prefs.dart';
Expand Down Expand Up @@ -43,7 +44,7 @@ class _MapViewState extends State<MapView> {
final AppLocalizations locale = AppLocalizations.of(context)!;
return Stack(
children: <Widget>[
_mapWidget(),
_mapWidget(locale),
LocationButton(
trackUserLocation: _userLocationTracking,
onOkay: (bool permissionGranted) => _onLocationSearchPressed(locale, permissionGranted),
Expand Down Expand Up @@ -76,7 +77,7 @@ class _MapViewState extends State<MapView> {
super.dispose();
}

Widget _mapWidget() {
Widget _mapWidget(AppLocalizations locale) {
return MapWidget(
key: const ValueKey('mapWidget'),
resourceOptions: ResourceOptions(accessToken: widget.accessToken),
Expand Down Expand Up @@ -113,6 +114,10 @@ class _MapViewState extends State<MapView> {
if (_userLocationTracking.value != UserLocationTracking.no) {
// Turn off tracking because user scrolled to another location.
_userLocationTracking.value = UserLocationTracking.no;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(locale.followLocationOffToast),
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.fromLTRB(20.0, 0.0, 92.0, 22.0)));
}
},
);
Expand Down Expand Up @@ -154,6 +159,10 @@ class _MapViewState extends State<MapView> {
if (_userLocationTracking.value == UserLocationTracking.position) {
_userLocationTracking.value = UserLocationTracking.positionBearing;
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(locale.followLocationToast),
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.fromLTRB(20.0, 0.0, 92.0, 22.0)));
_userLocationTracking.value = UserLocationTracking.position;
}
await _mapboxMap.location.updateSettings(LocationComponentSettings(
Expand Down Expand Up @@ -185,8 +194,10 @@ class _MapViewState extends State<MapView> {

void _refreshTrackLocation() async {
_updateUserLocation?.cancel();
WakelockPlus.enable();
_updateUserLocation = Timer.periodic(const Duration(milliseconds: 900), (timer) async {
if (_userLocationTracking.value == UserLocationTracking.no) {
WakelockPlus.disable();
_updateUserLocation?.cancel();
return;
}
Expand Down
56 changes: 56 additions & 0 deletions green_walking/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.0.2+3"
dbus:
dependency: transitive
description:
name: dbus
sha256: "6f07cba3f7b3448d42d015bfd3d53fe12e5b36da2423f23838efc1d5fb31a263"
url: "https://pub.dev"
source: hosted
version: "0.7.8"
enum_to_string:
dependency: transitive
description:
Expand Down Expand Up @@ -341,6 +349,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
package_info_plus:
dependency: transitive
description:
name: package_info_plus
sha256: "7e76fad405b3e4016cd39d08f455a4eb5199723cf594cd1b8916d47140d93017"
url: "https://pub.dev"
source: hosted
version: "4.2.0"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -373,6 +397,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.1"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
url: "https://pub.dev"
source: hosted
version: "5.4.0"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -634,6 +666,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
wakelock_plus:
dependency: "direct main"
description:
name: wakelock_plus
sha256: f45a6c03aa3f8322e0a9d7f4a0482721c8789cb41d555407367650b8f9c26018
url: "https://pub.dev"
source: hosted
version: "1.1.3"
wakelock_plus_platform_interface:
dependency: transitive
description:
name: wakelock_plus_platform_interface
sha256: "40fabed5da06caff0796dc638e1f07ee395fb18801fbff3255a2372db2d80385"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
Expand All @@ -658,6 +706,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.3"
xml:
dependency: transitive
description:
name: xml
sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84"
url: "https://pub.dev"
source: hosted
version: "6.3.0"
sdks:
dart: ">=3.1.0 <4.0.0"
flutter: ">=3.13.0"
1 change: 1 addition & 0 deletions green_walking/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
shared_preferences: ^2.2.2
turf: ^0.0.8
url_launcher: ^6.2.1
wakelock_plus: ^1.1.3

dev_dependencies:
#flutter_launcher_icons: ^0.8.1
Expand Down

0 comments on commit 2689022

Please sign in to comment.