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:
@@ -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('/');
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user