added accuracy and distance traveled
This commit is contained in:
@@ -25,6 +25,8 @@ class _TrackingState extends State<Tracking> {
|
||||
LocationMarkerPosition? locationMarkerPosition;
|
||||
MapController mapController = MapController();
|
||||
StreamSubscription? _positionSubscription;
|
||||
StreamSubscription? _statsSubscription;
|
||||
TrackingStats? _currentStats;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -52,6 +54,12 @@ class _TrackingState extends State<Tracking> {
|
||||
accuracy: widget.startPosition.accuracy,
|
||||
);
|
||||
|
||||
// Initialisiere die Statistiken sofort
|
||||
setState(() {
|
||||
_currentStats = _trackingService.currentStats;
|
||||
});
|
||||
_trackingService.requestStatsUpdate();
|
||||
|
||||
_positionSubscription = _trackingService.positionStream$.listen((position) {
|
||||
setState(() {
|
||||
locationMarkerPosition = LocationMarkerPosition(
|
||||
@@ -62,6 +70,12 @@ class _TrackingState extends State<Tracking> {
|
||||
});
|
||||
});
|
||||
|
||||
_statsSubscription = _trackingService.statsStream$.listen((stats) {
|
||||
setState(() {
|
||||
_currentStats = stats;
|
||||
});
|
||||
});
|
||||
|
||||
GeolocatorService.alwaysPositionEnabled().then((value) {
|
||||
if (!value && mounted) {
|
||||
Navigator.of(context).pop();
|
||||
@@ -73,15 +87,45 @@ class _TrackingState extends State<Tracking> {
|
||||
@override
|
||||
void dispose() {
|
||||
_positionSubscription?.cancel();
|
||||
_statsSubscription?.cancel();
|
||||
widget.weg.text = _trackingService.getPathAsString();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String _formatDistance(double meters) {
|
||||
if (meters >= 1000) {
|
||||
return '${(meters / 1000).toStringAsFixed(2)} km';
|
||||
}
|
||||
return '${meters.toStringAsFixed(1)} m';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.tracking),
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(AppLocalizations.of(context)!.tracking),
|
||||
if (_currentStats != null)
|
||||
DefaultTextStyle(
|
||||
style: Theme.of(context).textTheme.bodySmall!,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${AppLocalizations.of(context)!.accuracy}: ${_currentStats!.currentAccuracy.toStringAsFixed(1)}m (∅ ${_currentStats!.averageAccuracy.toStringAsFixed(1)}m)',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_formatDistance(_currentStats!.totalDistanceMeters),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
|
||||
Reference in New Issue
Block a user