556 lines
22 KiB
Dart
556 lines
22 KiB
Dart
import 'package:animations/animations.dart';
|
|
import 'package:fforte/enums/databases.dart';
|
|
import 'package:fforte/screens/addCam/exceptions/location_disabled_exception.dart';
|
|
import 'package:fforte/screens/addCam/exceptions/location_forbidden_exception.dart';
|
|
import 'package:fforte/screens/addCam/services/geolocator_service.dart';
|
|
import 'package:fforte/screens/excursion/exceptions/need_always_location_exception.dart';
|
|
import 'package:fforte/screens/excursion/widgets/anzahlen.dart';
|
|
import 'package:fforte/screens/excursion/widgets/bima_nutzer.dart';
|
|
import 'package:fforte/screens/excursion/widgets/hinweise.dart';
|
|
import 'package:fforte/screens/excursion/widgets/hund_u_leine.dart';
|
|
import 'package:fforte/screens/excursion/widgets/letzter_niederschlag.dart';
|
|
import 'package:fforte/screens/excursion/widgets/spur_gefunden.dart';
|
|
import 'package:fforte/screens/excursion/widgets/strecke_u_spurbedingungen.dart';
|
|
import 'package:fforte/screens/excursion/widgets/tracking.dart';
|
|
import 'package:fforte/screens/helper/add_entries_dialog_helper.dart';
|
|
import 'package:fforte/screens/helper/snack_bar_helper.dart';
|
|
import 'package:fforte/screens/sharedMethods/check_required.dart';
|
|
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';
|
|
|
|
class ExcursionMain extends StatefulWidget {
|
|
final bool isTemplate;
|
|
final bool isSent;
|
|
final Map<String, dynamic>? existingData;
|
|
|
|
const ExcursionMain({
|
|
super.key,
|
|
this.isTemplate = false,
|
|
this.isSent = false,
|
|
this.existingData,
|
|
});
|
|
|
|
@override
|
|
State<ExcursionMain> createState() => _ExcursionMainState();
|
|
}
|
|
|
|
class _ExcursionMainState extends State<ExcursionMain> {
|
|
int currentStep = 0;
|
|
late bool isTemplate;
|
|
Position currentPosition = 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,
|
|
);
|
|
|
|
bool bimaExtended = false;
|
|
|
|
// all TextEditingController because its easier
|
|
Map<String, Map<String, dynamic>> rmap = {
|
|
"ID": {"controller": TextEditingController(), "required": false},
|
|
// Step 1
|
|
"Datum": {"controller": TextEditingController(), "required": false},
|
|
"Rudel": {"controller": TextEditingController(), "required": false},
|
|
"Teilnehmer": {"controller": TextEditingController(), "required": false},
|
|
"Dauer": {"controller": TextEditingController(), "required": false},
|
|
"MHund": {"controller": TextEditingController(), "required": false},
|
|
"MLeine": {"controller": TextEditingController(), "required": false},
|
|
"BLand": {"controller": TextEditingController(), "required": false},
|
|
"Lkr": {"controller": TextEditingController(), "required": false},
|
|
"BeiOrt": {"controller": TextEditingController(), "required": false},
|
|
"BimaNr": {"controller": TextEditingController(), "required": false},
|
|
"BimaName": {"controller": TextEditingController(), "required": false},
|
|
"BimaNutzer": {"controller": TextEditingController(), "required": false},
|
|
"BimaAGV": {"controller": TextEditingController(), "required": false},
|
|
|
|
// Step 2
|
|
"Weg": {"controller": TextEditingController(), "required": false},
|
|
"Wetter": {"controller": TextEditingController(), "required": false},
|
|
"Temperat": {"controller": TextEditingController(), "required": false},
|
|
"RegenVor": {"controller": TextEditingController(), "required": false},
|
|
"KmAuto": {"controller": TextEditingController(), "required": false},
|
|
"KmFuss": {"controller": TextEditingController(), "required": false},
|
|
"KmRad": {"controller": TextEditingController(), "required": false},
|
|
"KmTotal": {"controller": TextEditingController(), "required": false},
|
|
"KmAuProz": {"controller": TextEditingController(), "required": false},
|
|
"KmFuProz": {"controller": TextEditingController(), "required": false},
|
|
"KmRaProz": {"controller": TextEditingController(), "required": false},
|
|
|
|
// Spur maybe own step?
|
|
"SpGut": {"controller": TextEditingController(), "required": false},
|
|
"SpMittel": {"controller": TextEditingController(), "required": false},
|
|
"SpSchlecht": {"controller": TextEditingController(), "required": false},
|
|
"SpurFund": {"controller": TextEditingController(), "required": false},
|
|
"SpurLang": {"controller": TextEditingController(), "required": false},
|
|
"SpurTiere": {"controller": TextEditingController(), "required": false},
|
|
"SpSicher": {"controller": TextEditingController(), "required": false},
|
|
"WelpenSp": {"controller": TextEditingController(), "required": false},
|
|
"WelpenAnz": {"controller": TextEditingController(), "required": false},
|
|
"WpSicher": {"controller": TextEditingController(), "required": false},
|
|
|
|
"LosungGes": {"controller": TextEditingController(), "required": false},
|
|
"LosungAnz": {"controller": TextEditingController(), "required": false},
|
|
"LosungGen": {"controller": TextEditingController(), "required": false},
|
|
"UrinAnz": {"controller": TextEditingController(), "required": false},
|
|
"UrinGen": {"controller": TextEditingController(), "required": false},
|
|
"OestrAnz": {"controller": TextEditingController(), "required": false},
|
|
"OestrGen": {"controller": TextEditingController(), "required": false},
|
|
"HaarAnz": {"controller": TextEditingController(), "required": false},
|
|
"HaarGen": {"controller": TextEditingController(), "required": false},
|
|
"LosungKm": {"controller": TextEditingController(), "required": false},
|
|
"GenetiKm": {"controller": TextEditingController(), "required": false},
|
|
"Hinweise": {"controller": TextEditingController(), "required": false},
|
|
|
|
// Step 3
|
|
"Bemerk": {"controller": TextEditingController(), "required": false},
|
|
"IntKomm": {"controller": TextEditingController(), "required": false},
|
|
"FallNum": {"controller": TextEditingController(), "required": false},
|
|
"Sent": {"controller": TextEditingController(), "required": false},
|
|
};
|
|
|
|
@override
|
|
void initState() {
|
|
GeolocatorService.deteterminePosition(
|
|
alwaysOnNeeded: true,
|
|
).then((result) => currentPosition = result).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,
|
|
);
|
|
}
|
|
} else if (error is NeedAlwaysLocation) {
|
|
if (mounted) {
|
|
AddEntriesDialogHelper.locationSettingsDialog(context);
|
|
}
|
|
}
|
|
return currentPosition;
|
|
});
|
|
|
|
if (widget.existingData?.isNotEmpty ?? false) {
|
|
for (var key in widget.existingData!.keys) {
|
|
rmap[key]!["controller"]!.text =
|
|
widget.existingData?[key].toString() ?? "";
|
|
}
|
|
} else {
|
|
// Set BLand and default values if there is no existing data
|
|
SharedPreferences.getInstance().then((prefs) {
|
|
rmap["BLand"]!["controller"]!.text = prefs.getString('bLand') ?? "";
|
|
});
|
|
|
|
rmap["Datum"]!["controller"]!.text = DateTime.now().toString();
|
|
}
|
|
|
|
isTemplate = widget.isTemplate;
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
for (String key in rmap.keys) {
|
|
rmap[key]!["controller"].dispose();
|
|
}
|
|
super.dispose();
|
|
}
|
|
|
|
Map<String, String> getFieldsText() {
|
|
Map<String, String> puff = {};
|
|
|
|
for (var itemKey in rmap.keys) {
|
|
puff[itemKey] = rmap[itemKey]!["controller"]!.text;
|
|
}
|
|
|
|
return puff;
|
|
}
|
|
|
|
@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) =>
|
|
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,
|
|
),
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
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,
|
|
);
|
|
},
|
|
));
|
|
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,
|
|
),
|
|
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"]!),
|
|
],
|
|
),
|
|
),
|
|
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),
|
|
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: (
|
|
Widget child,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
) {
|
|
return SharedAxisTransition(
|
|
animation: animation,
|
|
secondaryAnimation: secondaryAnimation,
|
|
transitionType: SharedAxisTransitionType.vertical,
|
|
child: child,
|
|
);
|
|
},
|
|
child: Stepper(
|
|
key: ValueKey<int>(currentStep),
|
|
steps: getSteps(),
|
|
currentStep: currentStep,
|
|
onStepTapped: (value) {
|
|
setState(() {
|
|
currentStep = value;
|
|
});
|
|
},
|
|
onStepContinue: () async {
|
|
final isLastStep = currentStep == getSteps().length - 1;
|
|
|
|
if (!isLastStep) {
|
|
var res = await saveTemplate(
|
|
getFieldsText(),
|
|
DatabasesEnum.excursion,
|
|
);
|
|
|
|
isTemplate = true;
|
|
setState(() {
|
|
rmap["ID"]!["controller"]!.text = res.toString();
|
|
currentStep += 1;
|
|
});
|
|
} else {
|
|
if (widget.isSent) {
|
|
Navigator.pushNamedAndRemoveUntil(
|
|
context,
|
|
'/home',
|
|
(route) => false,
|
|
);
|
|
return;
|
|
}
|
|
|
|
bool empty = CheckRequired.checkRequired(rmap);
|
|
// for debugging always false
|
|
// empty = false;
|
|
|
|
if (empty) {
|
|
AddEntriesDialogHelper.showTemplateDialog(
|
|
context,
|
|
getFieldsText(),
|
|
DatabasesEnum.excursion,
|
|
);
|
|
return;
|
|
} else {
|
|
bool pop = await AddEntriesDialogHelper.showSaveOptionsDialog(
|
|
context,
|
|
getFieldsText(),
|
|
widget.isTemplate,
|
|
DatabasesEnum.excursion,
|
|
);
|
|
if (pop && context.mounted) Navigator.of(context).pop();
|
|
}
|
|
}
|
|
},
|
|
onStepCancel: () {
|
|
if (currentStep == 0) {
|
|
Navigator.pop(context);
|
|
} else {
|
|
setState(() {
|
|
currentStep -= 1;
|
|
});
|
|
}
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|