Add Android background geolocation with notification error handling

Add flutter_background_geolocation for background location tracking on Android.
Service automatically sends coordinates to server when app is in background.
Error messages are shown as system notifications using flutter_local_notifications.
This commit is contained in:
dmit.b
2026-06-25 13:20:39 +03:00
parent 86e9b5a22a
commit 5f59e17da8
8 changed files with 281 additions and 13 deletions
+13 -1
View File
@@ -9,6 +9,7 @@ import '../providers/auth_provider.dart';
import '../providers/map_provider.dart';
import '../providers/share_provider.dart';
import '../services/geo_service.dart';
import '../services/background_geo_service.dart';
class MapScreen extends StatefulWidget {
const MapScreen({super.key});
@@ -69,6 +70,14 @@ class _MapScreenState extends State<MapScreen> {
position.longitude,
position.latitude,
);
if (!mounted) return;
final bgGeo = context.read<BackgroundGeoService>();
bgGeo.configure(
token: authProvider.token,
geoId: shareProvider.geoId,
);
await bgGeo.start();
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(
@@ -219,8 +228,11 @@ class _MapScreenState extends State<MapScreen> {
),
IconButton(
icon: const Icon(Icons.logout),
onPressed: () {
onPressed: () async {
_geoTimer?.cancel();
final bgGeo = context.read<BackgroundGeoService>();
await bgGeo.stop();
bgGeo.dispose();
authProvider.logout();
Navigator.of(context).pushReplacementNamed('/');
},