made tracking icon clickable
This commit is contained in:
@@ -29,8 +29,10 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
class ExcursionMain extends StatefulWidget {
|
class ExcursionMain extends StatefulWidget {
|
||||||
/// Whether this is a template excursion
|
/// Whether this is a template excursion
|
||||||
final bool isTemplate;
|
final bool isTemplate;
|
||||||
|
|
||||||
/// Whether the excursion data has been sent to the server
|
/// Whether the excursion data has been sent to the server
|
||||||
final bool isSent;
|
final bool isSent;
|
||||||
|
|
||||||
/// Existing excursion data for editing
|
/// Existing excursion data for editing
|
||||||
final Map<String, dynamic>? existingData;
|
final Map<String, dynamic>? existingData;
|
||||||
|
|
||||||
@@ -49,8 +51,10 @@ class ExcursionMain extends StatefulWidget {
|
|||||||
class _ExcursionMainState extends State<ExcursionMain> {
|
class _ExcursionMainState extends State<ExcursionMain> {
|
||||||
/// Current step in the form
|
/// Current step in the form
|
||||||
int currentStep = 0;
|
int currentStep = 0;
|
||||||
|
|
||||||
/// Whether this is a template excursion
|
/// Whether this is a template excursion
|
||||||
late bool isTemplate;
|
late bool isTemplate;
|
||||||
|
|
||||||
/// Current GPS position
|
/// Current GPS position
|
||||||
Position currentPosition = Position(
|
Position currentPosition = Position(
|
||||||
longitude: 10.0,
|
longitude: 10.0,
|
||||||
@@ -181,7 +185,8 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
rmap["BLand"]!["controller"]!.text = prefs.getString('bLand') ?? "";
|
rmap["BLand"]!["controller"]!.text = prefs.getString('bLand') ?? "";
|
||||||
});
|
});
|
||||||
|
|
||||||
rmap["Datum"]!["controller"]!.text = DateTime.now().toString().split(" ").first;
|
rmap["Datum"]!["controller"]!.text =
|
||||||
|
DateTime.now().toString().split(" ").first;
|
||||||
rmap["Sent"]!["controller"]!.text = "0";
|
rmap["Sent"]!["controller"]!.text = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +229,8 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
Datum(
|
Datum(
|
||||||
initDatum: DateTime.now(),
|
initDatum: DateTime.now(),
|
||||||
onDateChanged: (date) {
|
onDateChanged: (date) {
|
||||||
rmap["Datum"]!["controller"]!.text = date.toString().split(" ").first;
|
rmap["Datum"]!["controller"]!.text =
|
||||||
|
date.toString().split(" ").first;
|
||||||
},
|
},
|
||||||
name: AppLocalizations.of(context)!.date,
|
name: AppLocalizations.of(context)!.date,
|
||||||
),
|
),
|
||||||
@@ -371,51 +377,60 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// Check for always permission before starting tracking
|
// Check for always permission before starting tracking
|
||||||
LocationPermission permission = await Geolocator.checkPermission();
|
LocationPermission permission =
|
||||||
|
await Geolocator.checkPermission();
|
||||||
if (permission != LocationPermission.always) {
|
if (permission != LocationPermission.always) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
bool? shouldContinue = await showDialog<bool>(
|
bool? shouldContinue = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: Text(AppLocalizations.of(context)!.trackingPermissionTitle),
|
title: Text(AppLocalizations.of(context)!
|
||||||
content: Text(AppLocalizations.of(context)!.trackingPermissionContent),
|
.trackingPermissionTitle),
|
||||||
|
content: Text(AppLocalizations.of(context)!
|
||||||
|
.trackingPermissionContent),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
onPressed: () =>
|
||||||
child: Text(AppLocalizations.of(context)!.cancel),
|
Navigator.of(context).pop(false),
|
||||||
|
child:
|
||||||
|
Text(AppLocalizations.of(context)!.cancel),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await Geolocator.openAppSettings();
|
await Geolocator.openAppSettings();
|
||||||
if (context.mounted) Navigator.of(context).pop(true);
|
if (context.mounted)
|
||||||
|
Navigator.of(context).pop(true);
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.openSettings),
|
child: Text(
|
||||||
|
AppLocalizations.of(context)!.openSettings),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (shouldContinue != true) {
|
if (shouldContinue != true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for user to change settings and return
|
// Wait for user to change settings and return
|
||||||
// Try checking the permission multiple times
|
// Try checking the permission multiple times
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
permission = await Geolocator.checkPermission();
|
permission = await Geolocator.checkPermission();
|
||||||
if (permission == LocationPermission.always) {
|
if (permission == LocationPermission.always) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is the last attempt and we still don't have permission
|
// If this is the last attempt and we still don't have permission
|
||||||
if (i == 4 && permission != LocationPermission.always) {
|
if (i == 4 &&
|
||||||
|
permission != LocationPermission.always) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(AppLocalizations.of(context)!.permissionNotGranted),
|
content: Text(AppLocalizations.of(context)!
|
||||||
|
.permissionNotGranted),
|
||||||
duration: const Duration(seconds: 3),
|
duration: const Duration(seconds: 3),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -425,20 +440,21 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
await Navigator.push(context, MaterialPageRoute(
|
await Navigator.push(context, MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return Tracking(
|
return Tracking(
|
||||||
weg: rmap["Weg"]!["controller"]!,
|
weg: rmap["Weg"]!["controller"]!,
|
||||||
startPosition: currentPosition,
|
startPosition: currentPosition,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
child:
|
||||||
|
Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
|
||||||
@@ -559,9 +575,9 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
child: Text(AppLocalizations.of(context)!.nein),
|
child: Text(AppLocalizations.of(context)!.nein),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
saveTemplate(getFieldsText(), DatabasesEnum.excursion);
|
saveTemplate(getFieldsText(), DatabasesEnum.excursion);
|
||||||
Navigator.of(context).pop(1);
|
Navigator.of(context).pop(1);
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.leaveAndSaveTemplate),
|
child: Text(AppLocalizations.of(context)!.leaveAndSaveTemplate),
|
||||||
),
|
),
|
||||||
@@ -599,12 +615,25 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(AppLocalizations.of(context)!.excursion),
|
title: Text(AppLocalizations.of(context)!.excursion),
|
||||||
actions: [
|
actions: [
|
||||||
Image.asset(
|
IconButton(
|
||||||
TrackingService().isTracking
|
onPressed: () async {
|
||||||
? "assets/icons/tracking_on.png"
|
if (context.mounted) {
|
||||||
: "assets/icons/tracking_off.png",
|
await Navigator.push(context, MaterialPageRoute(
|
||||||
width: 40,
|
builder: (context) {
|
||||||
),
|
return Tracking(
|
||||||
|
weg: rmap["Weg"]!["controller"]!,
|
||||||
|
startPosition: currentPosition,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: Image.asset(
|
||||||
|
TrackingService().isTracking
|
||||||
|
? "assets/icons/tracking_on.png"
|
||||||
|
: "assets/icons/tracking_off.png",
|
||||||
|
width: 40,
|
||||||
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: PageTransitionSwitcher(
|
body: PageTransitionSwitcher(
|
||||||
@@ -691,4 +720,3 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user