Update AndroidManifest to include foreground service permissions and implement tracking service in excursion screens. Refactor tracking logic to utilize TrackingService for better state management and streamline position updates.
This commit is contained in:
@@ -19,6 +19,7 @@ import 'package:fforte/screens/sharedMethods/save_template.dart';
|
||||
import 'package:fforte/screens/sharedWidgets/datum.dart';
|
||||
import 'package:fforte/screens/sharedWidgets/var_text_field.dart';
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
import 'package:fforte/services/tracking_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -147,7 +148,6 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
return currentPosition;
|
||||
});
|
||||
|
||||
|
||||
if (widget.existingData?.isNotEmpty ?? false) {
|
||||
for (var key in widget.existingData!.keys) {
|
||||
rmap[key]!["controller"]!.text =
|
||||
@@ -188,268 +188,288 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Step> getSteps() => [
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context)!.dateandtime),
|
||||
content: Column(
|
||||
children: [
|
||||
// ---------- Date
|
||||
Datum(
|
||||
initDatum: DateTime.now(),
|
||||
onDateChanged: (date) {
|
||||
rmap["Datum"]!["controller"]!.text = date.toString();
|
||||
},
|
||||
name: AppLocalizations.of(context)!.date,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Pack
|
||||
VarTextField(
|
||||
textController: rmap["Rudel"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.rudel,
|
||||
dbName: "Rudel",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Participants
|
||||
VarTextField(
|
||||
textController: rmap["Teilnehmer"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.teilnehmer,
|
||||
dbName: "Teilnehmer",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Duration
|
||||
VarTextField(
|
||||
textController: rmap["Dauer"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.dauer,
|
||||
dbName: "Dauer",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Dog(leash)
|
||||
HundULeine(
|
||||
mHund: rmap["MHund"]!["controller"]!,
|
||||
mLeine: rmap["MLeine"]!["controller"]!,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- State
|
||||
VarTextField(
|
||||
textController: rmap["BLand"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.bland,
|
||||
dbName: "BLand",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Country
|
||||
VarTextField(
|
||||
textController: rmap["Lkr"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.lkr,
|
||||
dbName: "Lkr",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- By State
|
||||
VarTextField(
|
||||
textController: rmap["BeiOrt"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.beiort,
|
||||
dbName: "BeiOrt",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima number
|
||||
const Divider(),
|
||||
const SizedBox(height: 10),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
child: ExpansionPanelList(
|
||||
expansionCallback:
|
||||
((int index, bool isExpanded) =>
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context)!.dateandtime),
|
||||
content: Column(
|
||||
children: [
|
||||
// ---------- Date
|
||||
Datum(
|
||||
initDatum: DateTime.now(),
|
||||
onDateChanged: (date) {
|
||||
rmap["Datum"]!["controller"]!.text = date.toString();
|
||||
},
|
||||
name: AppLocalizations.of(context)!.date,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Pack
|
||||
VarTextField(
|
||||
textController: rmap["Rudel"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.rudel,
|
||||
dbName: "Rudel",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Participants
|
||||
VarTextField(
|
||||
textController: rmap["Teilnehmer"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.teilnehmer,
|
||||
dbName: "Teilnehmer",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Duration
|
||||
VarTextField(
|
||||
textController: rmap["Dauer"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.dauer,
|
||||
dbName: "Dauer",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Dog(leash)
|
||||
HundULeine(
|
||||
mHund: rmap["MHund"]!["controller"]!,
|
||||
mLeine: rmap["MLeine"]!["controller"]!,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- State
|
||||
VarTextField(
|
||||
textController: rmap["BLand"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.bland,
|
||||
dbName: "BLand",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Country
|
||||
VarTextField(
|
||||
textController: rmap["Lkr"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.lkr,
|
||||
dbName: "Lkr",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- By State
|
||||
VarTextField(
|
||||
textController: rmap["BeiOrt"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.beiort,
|
||||
dbName: "BeiOrt",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima number
|
||||
const Divider(),
|
||||
const SizedBox(height: 10),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
child: ExpansionPanelList(
|
||||
expansionCallback: ((int index, bool isExpanded) =>
|
||||
setState(() => bimaExtended = isExpanded)),
|
||||
expandedHeaderPadding: EdgeInsets.all(0),
|
||||
children: [
|
||||
ExpansionPanel(
|
||||
isExpanded: bimaExtended,
|
||||
canTapOnHeader: true,
|
||||
headerBuilder: (context, bool isOpen) => Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Align(alignment: Alignment.centerLeft, child: Text("BImA", style: Theme.of(context).textTheme.bodyLarge,),),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
VarTextField(
|
||||
textController: rmap["BimaNr"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.bimaNr,
|
||||
dbName: "BimaNr",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
expandedHeaderPadding: EdgeInsets.all(0),
|
||||
children: [
|
||||
ExpansionPanel(
|
||||
isExpanded: bimaExtended,
|
||||
canTapOnHeader: true,
|
||||
headerBuilder: (context, bool isOpen) => Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"BImA",
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima name
|
||||
VarTextField(
|
||||
textController: rmap["BimaName"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.bimaName,
|
||||
dbName: "BimaName",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
VarTextField(
|
||||
textController: rmap["BimaNr"]!["controller"]!,
|
||||
localization:
|
||||
AppLocalizations.of(context)!.bimaNr,
|
||||
dbName: "BimaNr",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima name
|
||||
VarTextField(
|
||||
textController:
|
||||
rmap["BimaName"]!["controller"]!,
|
||||
localization:
|
||||
AppLocalizations.of(context)!.bimaName,
|
||||
dbName: "BimaName",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima user
|
||||
BimaNutzer(
|
||||
onBimaNutzerChanged: (value) {
|
||||
setState(() {
|
||||
rmap["BimaNutzer"]!["controller"]!.text =
|
||||
value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima AGV
|
||||
VarTextField(
|
||||
textController: rmap["BimaAGV"]!["controller"]!,
|
||||
localization:
|
||||
AppLocalizations.of(context)!.bimaAGV,
|
||||
dbName: "BimaAGV",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima user
|
||||
BimaNutzer(
|
||||
onBimaNutzerChanged: (value) {
|
||||
setState(() {
|
||||
rmap["BimaNutzer"]!["controller"]!.text = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Bima AGV
|
||||
VarTextField(
|
||||
textController: rmap["BimaAGV"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.bimaAGV,
|
||||
dbName: "BimaAGV",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context)!.umstaendeUndAktionen),
|
||||
content: Column(
|
||||
children: [
|
||||
// ---------- Tracking
|
||||
ElevatedButton(
|
||||
onPressed:
|
||||
() => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
),
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context)!.umstaendeUndAktionen),
|
||||
content: Column(
|
||||
children: [
|
||||
// ---------- Tracking
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return Tracking(
|
||||
weg: rmap["Weg"]!["controller"]!,
|
||||
startPosition: currentPosition,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
child: Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
));
|
||||
setState(() {});
|
||||
},
|
||||
child:
|
||||
Text(AppLocalizations.of(context)!.trackingAnAusschalten),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// ---------- Weather
|
||||
VarTextField(
|
||||
textController: rmap["Wetter"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.wetter,
|
||||
dbName: "Wetter",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
// ---------- Weather
|
||||
VarTextField(
|
||||
textController: rmap["Wetter"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.wetter,
|
||||
dbName: "Wetter",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Temperature
|
||||
VarTextField(
|
||||
textController: rmap["Temperat"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.temperatur,
|
||||
dbName: "Temperat",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Last precipitation
|
||||
LetzterNiederschlag(
|
||||
controller: rmap["RegenVor"]!["controller"]!),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Track conditions
|
||||
StreckeUSpurbedingungen(
|
||||
kmAutoController: rmap["KmAuto"]!["controller"]!,
|
||||
kmFussController: rmap["KmFuss"]!["controller"]!,
|
||||
kmRadController: rmap["KmRad"]!["controller"]!,
|
||||
spGutController: rmap["SpGut"]!["controller"]!,
|
||||
spMittelController: rmap["SpMittel"]!["controller"]!,
|
||||
spSchlechtController: rmap["SpSchlecht"]!["controller"]!,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Divider(),
|
||||
// ---------- Track found
|
||||
SpurGefunden(
|
||||
spurFund: rmap["SpurFund"]!["controller"]!,
|
||||
spurLang: rmap["SpurLang"]!["controller"]!,
|
||||
spurTiere: rmap["SpurTiere"]!["controller"]!,
|
||||
spSicher: rmap["SpSicher"]!["controller"]!,
|
||||
welpenSp: rmap["WelpenSp"]!["controller"]!,
|
||||
welpenAnz: rmap["WelpenAnz"]!["controller"]!,
|
||||
wpSicher: rmap["WpSicher"]!["controller"]!,
|
||||
),
|
||||
const Divider(),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Counts
|
||||
Anzahlen(
|
||||
losungAnz: rmap["LosungAnz"]!["controller"]!,
|
||||
losungGes: rmap["LosungGes"]!["controller"]!,
|
||||
losungGen: rmap["LosungGen"]!["controller"]!,
|
||||
urinAnz: rmap["UrinAnz"]!["controller"]!,
|
||||
urinGen: rmap["UrinGen"]!["controller"]!,
|
||||
oestrAnz: rmap["OestrAnz"]!["controller"]!,
|
||||
oestrGen: rmap["OestrGen"]!["controller"]!,
|
||||
haarAnz: rmap["HaarAnz"]!["controller"]!,
|
||||
haarGen: rmap["HaarGen"]!["controller"]!,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Divider(),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Clues
|
||||
Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.hinweise,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
Hinweise(hinweise: rmap["Hinweise"]!["controller"]!),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Temperature
|
||||
VarTextField(
|
||||
textController: rmap["Temperat"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.temperatur,
|
||||
dbName: "Temperat",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context)!.intkomm),
|
||||
content: Column(
|
||||
children: [
|
||||
// ---------- Remarks
|
||||
VarTextField(
|
||||
textController: rmap["Bemerk"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.sonstbemerkungen,
|
||||
dbName: "Bemerk",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Internal communication
|
||||
VarTextField(
|
||||
textController: rmap["IntKomm"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.intkomm,
|
||||
dbName: "IntKomm",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// ---------- Last precipitation
|
||||
LetzterNiederschlag(controller: rmap["RegenVor"]!["controller"]!),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Track conditions
|
||||
StreckeUSpurbedingungen(
|
||||
kmAutoController: rmap["KmAuto"]!["controller"]!,
|
||||
kmFussController: rmap["KmFuss"]!["controller"]!,
|
||||
kmRadController: rmap["KmRad"]!["controller"]!,
|
||||
spGutController: rmap["SpGut"]!["controller"]!,
|
||||
spMittelController: rmap["SpMittel"]!["controller"]!,
|
||||
spSchlechtController: rmap["SpSchlecht"]!["controller"]!,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Divider(),
|
||||
// ---------- Track found
|
||||
SpurGefunden(
|
||||
spurFund: rmap["SpurFund"]!["controller"]!,
|
||||
spurLang: rmap["SpurLang"]!["controller"]!,
|
||||
spurTiere: rmap["SpurTiere"]!["controller"]!,
|
||||
spSicher: rmap["SpSicher"]!["controller"]!,
|
||||
welpenSp: rmap["WelpenSp"]!["controller"]!,
|
||||
welpenAnz: rmap["WelpenAnz"]!["controller"]!,
|
||||
wpSicher: rmap["WpSicher"]!["controller"]!,
|
||||
),
|
||||
const Divider(),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Counts
|
||||
Anzahlen(
|
||||
losungAnz: rmap["LosungAnz"]!["controller"]!,
|
||||
losungGes: rmap["LosungGes"]!["controller"]!,
|
||||
losungGen: rmap["LosungGen"]!["controller"]!,
|
||||
urinAnz: rmap["UrinAnz"]!["controller"]!,
|
||||
urinGen: rmap["UrinGen"]!["controller"]!,
|
||||
oestrAnz: rmap["OestrAnz"]!["controller"]!,
|
||||
oestrGen: rmap["OestrGen"]!["controller"]!,
|
||||
haarAnz: rmap["HaarAnz"]!["controller"]!,
|
||||
haarGen: rmap["HaarGen"]!["controller"]!,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Divider(),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Clues
|
||||
Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.hinweise,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
Hinweise(hinweise: rmap["Hinweise"]!["controller"]!),
|
||||
],
|
||||
),
|
||||
),
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context)!.intkomm),
|
||||
content: Column(
|
||||
children: [
|
||||
// ---------- Remarks
|
||||
VarTextField(
|
||||
textController: rmap["Bemerk"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.sonstbemerkungen,
|
||||
dbName: "Bemerk",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// ---------- Internal communication
|
||||
VarTextField(
|
||||
textController: rmap["IntKomm"]!["controller"]!,
|
||||
localization: AppLocalizations.of(context)!.intkomm,
|
||||
dbName: "IntKomm",
|
||||
required: false,
|
||||
dbDesignation: DatabasesEnum.excursion,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
),
|
||||
];
|
||||
|
||||
// Begin of widget tree
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(AppLocalizations.of(context)!.excursion)),
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.excursion),
|
||||
actions: [
|
||||
// Text(TrackingService().isTracking ? "Tracking" : "Not tracking")
|
||||
Image.asset(
|
||||
TrackingService().isTracking ? "assets/icons/tracking_on.png" : "assets/icons/tracking_off.png",
|
||||
width: 40,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: PageTransitionSwitcher(
|
||||
duration: const Duration(microseconds: 800),
|
||||
transitionBuilder: (
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
import 'package:fforte/screens/addCam/services/geolocator_service.dart';
|
||||
import 'package:fforte/screens/helper/add_entries_dialog_helper.dart';
|
||||
import 'package:fforte/screens/helper/snack_bar_helper.dart';
|
||||
import 'package:fforte/services/notification_service.dart';
|
||||
import 'package:fforte/services/tracking_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
|
||||
@@ -22,20 +21,14 @@ class Tracking extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TrackingState extends State<Tracking> {
|
||||
List<LatLng> pathList = [];
|
||||
StreamSubscription<Position>? positionStream;
|
||||
final TrackingService _trackingService = TrackingService();
|
||||
LocationMarkerPosition? locationMarkerPosition;
|
||||
bool positionStreamRunning = false;
|
||||
MapController mapController = MapController();
|
||||
|
||||
Random rand = Random();
|
||||
StreamSubscription? _positionSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// debugging (i guess)
|
||||
// pathList.add(
|
||||
// LatLng(widget.startPosition.latitude, widget.startPosition.longitude),
|
||||
// );
|
||||
super.initState();
|
||||
|
||||
if (widget.weg.text.isNotEmpty) {
|
||||
for (var element in widget.weg.text.split(";")) {
|
||||
@@ -47,7 +40,7 @@ class _TrackingState extends State<Tracking> {
|
||||
// ignore because the double is short enough then
|
||||
}
|
||||
|
||||
pathList.add(
|
||||
_trackingService.pathList.add(
|
||||
LatLng(double.parse(posSplit.first), double.parse(posSplit[1])),
|
||||
);
|
||||
}
|
||||
@@ -59,7 +52,15 @@ class _TrackingState extends State<Tracking> {
|
||||
accuracy: widget.startPosition.accuracy,
|
||||
);
|
||||
|
||||
super.initState();
|
||||
_positionSubscription = _trackingService.positionStream$.listen((position) {
|
||||
setState(() {
|
||||
locationMarkerPosition = LocationMarkerPosition(
|
||||
latitude: position.latitude,
|
||||
longitude: position.longitude,
|
||||
accuracy: position.accuracy,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
GeolocatorService.alwaysPositionEnabled().then((value) {
|
||||
if (!value && mounted) {
|
||||
@@ -71,101 +72,30 @@ class _TrackingState extends State<Tracking> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (positionStream != null) positionStream!.cancel();
|
||||
bool isFirst = true;
|
||||
if (pathList.isNotEmpty) {
|
||||
for (var pos in pathList) {
|
||||
if (!isFirst) {
|
||||
widget.weg.text += ";";
|
||||
} else {
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
widget.weg.text += "${pos.latitude},${pos.longitude}";
|
||||
}
|
||||
}
|
||||
NotificationService().deleteNotification();
|
||||
|
||||
_positionSubscription?.cancel();
|
||||
widget.weg.text = _trackingService.getPathAsString();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
final LocationSettings streamLocationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter: 10,
|
||||
);
|
||||
|
||||
void onTrackingStart() async {
|
||||
// notification handling for tracking in background notification
|
||||
await NotificationService().initNotification();
|
||||
|
||||
if (mounted) {
|
||||
NotificationService().showNotification(
|
||||
title: AppLocalizations.of(context)!.trackingRunningInBackground,
|
||||
);
|
||||
}
|
||||
|
||||
positionStream = Geolocator.getPositionStream(
|
||||
locationSettings: AndroidSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter: 0,
|
||||
foregroundNotificationConfig:
|
||||
mounted
|
||||
? ForegroundNotificationConfig(
|
||||
notificationTitle:
|
||||
AppLocalizations.of(context)!.trackingRunningInBackground,
|
||||
notificationText: "",
|
||||
)
|
||||
: null,
|
||||
|
||||
),
|
||||
).listen((Position? position) {
|
||||
if (position != null) {
|
||||
setState(() {
|
||||
pathList.add(LatLng(position.latitude, position.longitude));
|
||||
// Random value for debugging
|
||||
// pathList.add(LatLng(rand.nextInt(5) + 40, position.longitude));
|
||||
|
||||
locationMarkerPosition = LocationMarkerPosition(
|
||||
latitude: position.latitude,
|
||||
longitude: position.longitude,
|
||||
accuracy: position.accuracy,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
if (mounted) {
|
||||
SnackBarHelper.showSnackBarMessage(
|
||||
context,
|
||||
AppLocalizations.of(context)!.couldntDeterminePosition,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
positionStream!.onError((e) {
|
||||
NotificationService().deleteNotification();
|
||||
NotificationService().showNotification(title: "ERROR: $e");
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.tracking),
|
||||
leading: IconButton(onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}, icon: Icon(Icons.arrow_back_rounded)),
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(Icons.arrow_back_rounded)
|
||||
),
|
||||
actions: [
|
||||
if (!positionStreamRunning)
|
||||
if (!_trackingService.isTracking)
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
bool delete =
|
||||
await AddEntriesDialogHelper.deleteCompleteRouteDialog(
|
||||
context,
|
||||
);
|
||||
|
||||
bool delete = await AddEntriesDialogHelper.deleteCompleteRouteDialog(context);
|
||||
if (delete) {
|
||||
setState(() {
|
||||
pathList = [];
|
||||
_trackingService.clearPath();
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -174,32 +104,32 @@ class _TrackingState extends State<Tracking> {
|
||||
color: Theme.of(context).colorScheme.errorContainer,
|
||||
),
|
||||
),
|
||||
if (positionStreamRunning)
|
||||
if (_trackingService.isTracking)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
positionStreamRunning = false;
|
||||
positionStream!.cancel();
|
||||
NotificationService().deleteNotification();
|
||||
_trackingService.stopTracking();
|
||||
});
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.trackingStop),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (positionStreamRunning) {
|
||||
positionStreamRunning = false;
|
||||
positionStream?.pause();
|
||||
} else {
|
||||
positionStreamRunning = true;
|
||||
onTrackingStart();
|
||||
}
|
||||
setState(() {});
|
||||
setState(() {
|
||||
if (_trackingService.isTracking) {
|
||||
_trackingService.pauseTracking();
|
||||
} else {
|
||||
if (_trackingService.positionStream == null) {
|
||||
_trackingService.startTracking(context);
|
||||
} else {
|
||||
_trackingService.resumeTracking();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
child:
|
||||
positionStreamRunning
|
||||
? Text(AppLocalizations.of(context)!.trackingPause)
|
||||
: Text(AppLocalizations.of(context)!.trackingStart)
|
||||
child: _trackingService.isTracking
|
||||
? Text(AppLocalizations.of(context)!.trackingPause)
|
||||
: Text(AppLocalizations.of(context)!.trackingStart),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -219,8 +149,7 @@ class _TrackingState extends State<Tracking> {
|
||||
mapController: mapController,
|
||||
options: MapOptions(
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags:
|
||||
InteractiveFlag.pinchZoom |
|
||||
flags: InteractiveFlag.pinchZoom |
|
||||
InteractiveFlag.drag |
|
||||
InteractiveFlag.pinchMove,
|
||||
),
|
||||
@@ -235,22 +164,16 @@ class _TrackingState extends State<Tracking> {
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'de.lupus.apps',
|
||||
),
|
||||
if (pathList.isNotEmpty)
|
||||
if (_trackingService.pathList.isNotEmpty)
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
Polyline(strokeWidth: 2.0, points: pathList, color: Colors.red),
|
||||
Polyline(
|
||||
strokeWidth: 2.0,
|
||||
points: _trackingService.pathList,
|
||||
color: Colors.red
|
||||
),
|
||||
],
|
||||
),
|
||||
// CircleLayer(
|
||||
// circles: [
|
||||
// CircleMarker(
|
||||
// color: Colors.blue,
|
||||
// point: pathList.isEmpty ? widget.startPosition : pathList.last,
|
||||
// radius: 5,
|
||||
// useRadiusInMeter: true,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
CurrentLocationLayer(),
|
||||
],
|
||||
),
|
||||
|
||||
83
lib/services/tracking_service.dart
Normal file
83
lib/services/tracking_service.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
import 'package:fforte/services/notification_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
class TrackingService {
|
||||
static final TrackingService _instance = TrackingService._internal();
|
||||
factory TrackingService() => _instance;
|
||||
TrackingService._internal();
|
||||
|
||||
List<LatLng> pathList = [];
|
||||
StreamSubscription<Position>? positionStream;
|
||||
bool isTracking = false;
|
||||
final _positionController = StreamController<Position>.broadcast();
|
||||
|
||||
Stream<Position> get positionStream$ => _positionController.stream;
|
||||
|
||||
Future<void> startTracking(BuildContext context) async {
|
||||
if (isTracking) return;
|
||||
|
||||
await NotificationService().initNotification();
|
||||
if (context.mounted) {
|
||||
NotificationService().showNotification(
|
||||
title: AppLocalizations.of(context)!.trackingRunningInBackground,
|
||||
);
|
||||
}
|
||||
|
||||
positionStream = Geolocator.getPositionStream(
|
||||
locationSettings: AndroidSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter: 0,
|
||||
foregroundNotificationConfig: ForegroundNotificationConfig(
|
||||
notificationTitle: context.mounted ? AppLocalizations.of(context)!.trackingRunningInBackground : "Tracking",
|
||||
notificationText: "",
|
||||
),
|
||||
),
|
||||
).listen((Position? position) {
|
||||
if (position != null) {
|
||||
pathList.add(LatLng(position.latitude, position.longitude));
|
||||
_positionController.add(position);
|
||||
}
|
||||
});
|
||||
|
||||
positionStream!.onError((e) {
|
||||
NotificationService().deleteNotification();
|
||||
NotificationService().showNotification(title: "ERROR: $e");
|
||||
});
|
||||
|
||||
isTracking = true;
|
||||
}
|
||||
|
||||
void pauseTracking() {
|
||||
positionStream?.pause();
|
||||
isTracking = false;
|
||||
}
|
||||
|
||||
void resumeTracking() {
|
||||
positionStream?.resume();
|
||||
isTracking = true;
|
||||
}
|
||||
|
||||
void stopTracking() {
|
||||
positionStream?.cancel();
|
||||
NotificationService().deleteNotification();
|
||||
isTracking = false;
|
||||
}
|
||||
|
||||
void clearPath() {
|
||||
pathList.clear();
|
||||
}
|
||||
|
||||
String getPathAsString() {
|
||||
return pathList.map((pos) => "${pos.latitude},${pos.longitude}").join(";");
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
stopTracking();
|
||||
_positionController.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user