revert some things ig?
This commit is contained in:
@@ -112,32 +112,48 @@ class _AddCamMainState extends State<AddCamMain> {
|
|||||||
return puff;
|
return puff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
bool isLoadingPosition = false;
|
||||||
void initState() {
|
|
||||||
// updates the currentPosition var after the _determine position has finished. Means user view updates with his live location
|
Future<Position> _initializePosition() async {
|
||||||
GeolocatorService.deteterminePosition()
|
try {
|
||||||
.then((result) => currentPosition = result)
|
final position = await GeolocatorService.deteterminePosition();
|
||||||
.catchError((error) {
|
|
||||||
if (error is LocationDisabledException) {
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
currentPosition = position;
|
||||||
|
isLoadingPosition = false;
|
||||||
|
// Update the text controllers with new position
|
||||||
|
rmap["DECLAT"]!["controller"]!.text = position.latitude.toString();
|
||||||
|
rmap["DECLNG"]!["controller"]!.text = position.longitude.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
} catch (error) {
|
||||||
|
if (!mounted) {
|
||||||
|
return currentPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error is LocationDisabledException) {
|
||||||
SnackBarHelper.showSnackBarMessage(
|
SnackBarHelper.showSnackBarMessage(
|
||||||
context,
|
context,
|
||||||
AppLocalizations.of(context)!.locationDisabled,
|
AppLocalizations.of(context)!.locationDisabled,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} else if (error is LocationForbiddenException) {
|
} else if (error is LocationForbiddenException) {
|
||||||
if (mounted) {
|
|
||||||
SnackBarHelper.showSnackBarMessage(
|
SnackBarHelper.showSnackBarMessage(
|
||||||
context,
|
context,
|
||||||
AppLocalizations.of(context)!.locationForbidden,
|
AppLocalizations.of(context)!.locationForbidden,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return currentPosition;
|
setState(() {
|
||||||
|
isLoadingPosition = false;
|
||||||
});
|
});
|
||||||
// select initial werte
|
return currentPosition;
|
||||||
rmap["DECLAT"]!["controller"]!.text = currentPosition.latitude.toString();
|
}
|
||||||
rmap["DECLNG"]!["controller"]!.text = currentPosition.longitude.toString();
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
isTemplate = widget.isTemplate;
|
isTemplate = widget.isTemplate;
|
||||||
|
|
||||||
@@ -156,7 +172,40 @@ class _AddCamMainState extends State<AddCamMain> {
|
|||||||
rmap["Platzung"]!["controller"]!.text = "";
|
rmap["Platzung"]!["controller"]!.text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
super.initState();
|
// Set initial default position
|
||||||
|
rmap["DECLAT"]!["controller"]!.text = currentPosition.latitude.toString();
|
||||||
|
rmap["DECLNG"]!["controller"]!.text = currentPosition.longitude.toString();
|
||||||
|
|
||||||
|
// Try to get current position
|
||||||
|
GeolocatorService.deteterminePosition()
|
||||||
|
.then((result) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
currentPosition = result;
|
||||||
|
// Update coordinates after getting the position
|
||||||
|
rmap["DECLAT"]!["controller"]!.text = result.latitude.toString();
|
||||||
|
rmap["DECLNG"]!["controller"]!.text = result.longitude.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catchError((error) {
|
||||||
|
if (error is LocationDisabledException) {
|
||||||
|
if (mounted) {
|
||||||
|
SnackBarHelper.showSnackBarMessage(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context)!.locationDisabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (error is LocationForbiddenException) {
|
||||||
|
if (mounted) {
|
||||||
|
SnackBarHelper.showSnackBarMessage(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context)!.locationForbidden,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentPosition;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -291,6 +340,24 @@ class _AddCamMainState extends State<AddCamMain> {
|
|||||||
const SizedBox(width: 15),
|
const SizedBox(width: 15),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
setState(() {
|
||||||
|
isLoadingPosition = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await _initializePosition();
|
||||||
|
} catch (e) {
|
||||||
|
// Error already handled in _initializePosition
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
isLoadingPosition = false;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
final result = await Navigator.of(context).push<LatLng>(
|
final result = await Navigator.of(context).push<LatLng>(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
@@ -304,7 +371,8 @@ class _AddCamMainState extends State<AddCamMain> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (result != null) {
|
|
||||||
|
if (result != null && mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
currentPosition = Position(
|
currentPosition = Position(
|
||||||
latitude: result.latitude,
|
latitude: result.latitude,
|
||||||
@@ -318,10 +386,33 @@ class _AddCamMainState extends State<AddCamMain> {
|
|||||||
speed: 0.0,
|
speed: 0.0,
|
||||||
speedAccuracy: 0.0,
|
speedAccuracy: 0.0,
|
||||||
);
|
);
|
||||||
|
rmap["DECLAT"]!["controller"]!.text = result.latitude.toString();
|
||||||
|
rmap["DECLNG"]!["controller"]!.text = result.longitude.toString();
|
||||||
|
isLoadingPosition = false;
|
||||||
|
});
|
||||||
|
} else if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
isLoadingPosition = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.openMap),
|
child: isLoadingPosition
|
||||||
|
? Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
color: Theme.of(context).colorScheme.onPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(AppLocalizations.of(context)!.openMap),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: Text(AppLocalizations.of(context)!.openMap),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class KarteState extends State<Karte> {
|
|||||||
Icons.location_on,
|
Icons.location_on,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
));
|
));
|
||||||
|
saveVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -51,29 +52,10 @@ class KarteState extends State<Karte> {
|
|||||||
actions: [
|
actions: [
|
||||||
Visibility(
|
Visibility(
|
||||||
visible: saveVisible,
|
visible: saveVisible,
|
||||||
child: Row(
|
child: Padding(
|
||||||
children: [
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
Text(AppLocalizations.of(context)!.saveMap),
|
child: ElevatedButton.icon(
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// try {
|
|
||||||
// List<Placemark> placemarks =
|
|
||||||
// await placemarkFromCoordinates(
|
|
||||||
// currentMarker!.point.latitude,
|
|
||||||
// currentMarker!.point.longitude);
|
|
||||||
//
|
|
||||||
// widget.beiOrtC.text = placemarks.first.locality!;
|
|
||||||
// widget.ortInfoC.text = placemarks.first.street!;
|
|
||||||
// } catch (e) {
|
|
||||||
// //
|
|
||||||
// // !!! Localization
|
|
||||||
// if (context.mounted) {
|
|
||||||
// SnackBarHelper.showSnackBarMessage(
|
|
||||||
// context, "Geocoding error");
|
|
||||||
// }
|
|
||||||
// debugPrint(e.toString());
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (currentMarker != null) {
|
if (currentMarker != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
widget.decLatC.text =
|
widget.decLatC.text =
|
||||||
@@ -82,11 +64,14 @@ class KarteState extends State<Karte> {
|
|||||||
currentMarker!.point.longitude.toString();
|
currentMarker!.point.longitude.toString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (context.mounted) Navigator.pop(context);
|
if (context.mounted) Navigator.pop(context, currentMarker?.point);
|
||||||
},
|
},
|
||||||
child: const Icon(Icons.save),
|
icon: const Icon(Icons.save),
|
||||||
|
label: Text(AppLocalizations.of(context)!.saveMap),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -43,9 +43,18 @@ class ExcursionMain extends StatefulWidget {
|
|||||||
class _ExcursionMainState extends State<ExcursionMain> {
|
class _ExcursionMainState extends State<ExcursionMain> {
|
||||||
int currentStep = 0;
|
int currentStep = 0;
|
||||||
late bool isTemplate;
|
late bool isTemplate;
|
||||||
Position? currentPosition;
|
Position currentPosition = Position(
|
||||||
bool isLoadingPosition = true;
|
longitude: 10.0,
|
||||||
late Future<Position> _positionFuture;
|
latitude: 51.0,
|
||||||
|
timestamp: DateTime.now(),
|
||||||
|
accuracy: 0.0,
|
||||||
|
altitude: 0.0,
|
||||||
|
heading: 0.0,
|
||||||
|
speed: 0.0,
|
||||||
|
speedAccuracy: 0.0,
|
||||||
|
altitudeAccuracy: 0.0,
|
||||||
|
headingAccuracy: 0.0,
|
||||||
|
);
|
||||||
|
|
||||||
bool bimaExtended = false;
|
bool bimaExtended = false;
|
||||||
|
|
||||||
@@ -114,8 +123,38 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
GeolocatorService.deteterminePosition(
|
||||||
_positionFuture = _initializePosition();
|
alwaysOnNeeded: false,
|
||||||
|
).then((result) => currentPosition = result).catchError((error) async {
|
||||||
|
if (error is LocationDisabledException) {
|
||||||
|
if (mounted) {
|
||||||
|
SnackBarHelper.showSnackBarMessage(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context)!.locationDisabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (error is LocationForbiddenException) {
|
||||||
|
if (mounted) {
|
||||||
|
SnackBarHelper.showSnackBarMessage(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context)!.locationForbidden,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (error is NeedAlwaysLocation) {
|
||||||
|
if (mounted) {
|
||||||
|
bool reload =
|
||||||
|
await AddEntriesDialogHelper.locationSettingsDialog(context);
|
||||||
|
if (reload) {
|
||||||
|
GeolocatorService.deteterminePosition()
|
||||||
|
.then((res) => currentPosition = res)
|
||||||
|
.catchError((error) {
|
||||||
|
return currentPosition;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentPosition;
|
||||||
|
});
|
||||||
|
|
||||||
if (widget.existingData?.isNotEmpty ?? false) {
|
if (widget.existingData?.isNotEmpty ?? false) {
|
||||||
for (var key in widget.existingData!.keys) {
|
for (var key in widget.existingData!.keys) {
|
||||||
@@ -133,87 +172,8 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isTemplate = widget.isTemplate;
|
isTemplate = widget.isTemplate;
|
||||||
}
|
|
||||||
|
|
||||||
Future<Position> _initializePosition() async {
|
super.initState();
|
||||||
try {
|
|
||||||
final position = await GeolocatorService.deteterminePosition(
|
|
||||||
alwaysOnNeeded: true,
|
|
||||||
);
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
currentPosition = position;
|
|
||||||
isLoadingPosition = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return position;
|
|
||||||
} catch (error) {
|
|
||||||
if (!mounted) {
|
|
||||||
return _getDefaultPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error is LocationDisabledException) {
|
|
||||||
SnackBarHelper.showSnackBarMessage(
|
|
||||||
context,
|
|
||||||
AppLocalizations.of(context)!.locationDisabled,
|
|
||||||
);
|
|
||||||
} else if (error is LocationForbiddenException) {
|
|
||||||
SnackBarHelper.showSnackBarMessage(
|
|
||||||
context,
|
|
||||||
AppLocalizations.of(context)!.locationForbidden,
|
|
||||||
);
|
|
||||||
} else if (error is NeedAlwaysLocation) {
|
|
||||||
AddEntriesDialogHelper.locationSettingsDialog(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return default position on any error
|
|
||||||
final defaultPosition = _getDefaultPosition();
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
currentPosition = defaultPosition;
|
|
||||||
isLoadingPosition = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return defaultPosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Position _getDefaultPosition() {
|
|
||||||
return Position(
|
|
||||||
longitude: 10.0,
|
|
||||||
latitude: 51.0,
|
|
||||||
timestamp: DateTime.now(),
|
|
||||||
accuracy: 0.0,
|
|
||||||
altitude: 0.0,
|
|
||||||
heading: 0.0,
|
|
||||||
speed: 0.0,
|
|
||||||
speedAccuracy: 0.0,
|
|
||||||
altitudeAccuracy: 0.0,
|
|
||||||
headingAccuracy: 0.0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _refreshPosition() async {
|
|
||||||
setState(() {
|
|
||||||
isLoadingPosition = true;
|
|
||||||
});
|
|
||||||
_positionFuture = _initializePosition();
|
|
||||||
try {
|
|
||||||
final position = await _positionFuture;
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
currentPosition = position;
|
|
||||||
isLoadingPosition = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// Error already handled in _initializePosition
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
isLoadingPosition = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -392,7 +352,76 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
content: Column(
|
content: Column(
|
||||||
children: [
|
children: [
|
||||||
// ---------- Tracking
|
// ---------- Tracking
|
||||||
_buildTrackingButtons(),
|
ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
// Check for always permission before starting tracking
|
||||||
|
LocationPermission permission = await Geolocator.checkPermission();
|
||||||
|
if (permission != LocationPermission.always) {
|
||||||
|
if (mounted) {
|
||||||
|
bool? shouldContinue = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context)!.trackingPermissionTitle),
|
||||||
|
content: Text(AppLocalizations.of(context)!.trackingPermissionContent),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await Geolocator.openAppSettings();
|
||||||
|
Navigator.of(context).pop(true);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.openSettings),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (shouldContinue != true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for user to change settings and return
|
||||||
|
// Try checking the permission multiple times
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
permission = await Geolocator.checkPermission();
|
||||||
|
if (permission == LocationPermission.always) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is the last attempt and we still don't have permission
|
||||||
|
if (i == 4 && permission != LocationPermission.always) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.permissionNotGranted),
|
||||||
|
duration: const Duration(seconds: 3),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Navigator.push(context, MaterialPageRoute(
|
||||||
|
builder: (context) {
|
||||||
|
return Tracking(
|
||||||
|
weg: rmap["Weg"]!["controller"]!,
|
||||||
|
startPosition: currentPosition,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
));
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
|
||||||
// ---------- Weather
|
// ---------- Weather
|
||||||
@@ -644,64 +673,5 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a refresh position button next to the tracking button
|
|
||||||
Widget _buildTrackingButtons() {
|
|
||||||
return FutureBuilder<Position>(
|
|
||||||
future: _positionFuture,
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
final bool isLoading =
|
|
||||||
snapshot.connectionState == ConnectionState.waiting &&
|
|
||||||
!snapshot.hasData;
|
|
||||||
final Position position =
|
|
||||||
snapshot.data ?? currentPosition ?? _getDefaultPosition();
|
|
||||||
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: isLoading
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
await Navigator.push(context, MaterialPageRoute(
|
|
||||||
builder: (context) {
|
|
||||||
return Tracking(
|
|
||||||
weg: rmap["Weg"]!["controller"]!,
|
|
||||||
startPosition: position,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
));
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
child: isLoading
|
|
||||||
? Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
color: Theme.of(context).colorScheme.onPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(AppLocalizations.of(context)!
|
|
||||||
.trackingAnAusschalten),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
IconButton(
|
|
||||||
onPressed: isLoading ? null : _refreshPosition,
|
|
||||||
icon: const Icon(Icons.refresh),
|
|
||||||
tooltip: 'Position aktualisieren',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user