now doesnt leave the addcam when user canceles save as file option

This commit is contained in:
nico
2024-04-30 19:04:52 +02:00
parent 21db03d348
commit e0d74591c8
3 changed files with 118 additions and 33 deletions

View File

@@ -2,11 +2,7 @@ todo:
maybe auch vorschläge aus templates in dropdown menüs anzeigen maybe auch vorschläge aus templates in dropdown menüs anzeigen
im englischen abändern im englischen abändern
zurückfeld in datenansicht zurückfeld in datenansicht
dropdown menü fixen (ai fragen)
fehler beim speichern anzeigen fehler beim speichern anzeigen
nach koordinaten lkr auswählen (esri-leaflet-geocoder)
fix ktage und nebeneinander positioniere
textdateien auch an server senden
error check wenn dateiauswahl abgebrochen wurde einfügen error check wenn dateiauswahl abgebrochen wurde einfügen
save option einfügen nur zum speichern save option einfügen nur zum speichern
ausvon und ausbis fixen (falsches datum übergeben (20000-01-01)) ausvon und ausbis fixen (falsches datum übergeben (20000-01-01))
@@ -27,6 +23,9 @@ eintrg in db wenn http response (in sent column)
not to do: not to do:
fix ktage und nebeneinander positioniere
nach koordinaten lkr auswählen (esri-leaflet-geocoder)
dropdown menü fixen (ai fragen)
überschriften für view cams überschriften für view cams
standartwert in textfeld standartwert in textfeld
überschriften für view cams überschriften für view cams

View File

@@ -270,11 +270,6 @@ class _AddCamMainState extends State<AddCamMain> {
saveData(); saveData();
saveFile(); saveFile();
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
Navigator.pushNamedAndRemoveUntil(
// ignore: use_build_context_synchronously
context,
'/home',
(route) => false);
}, },
child: Text(AppLocalizations.of(context)!.saveasfile)), child: Text(AppLocalizations.of(context)!.saveasfile)),
TextButton( TextButton(
@@ -325,14 +320,13 @@ class _AddCamMainState extends State<AddCamMain> {
Future<void> saveFile() async { Future<void> saveFile() async {
String? selectedDirectory = await FilePicker.platform.getDirectoryPath(); String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
Map place = getPlace(); Map place = getPlace();
String jsonPlace = jsonEncode(place); String jsonPlace = jsonEncode(place);
if (selectedDirectory == null) { if (selectedDirectory == null) {
// ignore: use_build_context_synchronously
Navigator.pop(context);
return; return;
} }
await prefs.setString('saveDir', selectedDirectory); await prefs.setString('saveDir', selectedDirectory);
@@ -344,6 +338,12 @@ class _AddCamMainState extends State<AddCamMain> {
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Datei gespeichert in $selectedDirectory'))); SnackBar(content: Text('Datei gespeichert in $selectedDirectory')));
Navigator.pushNamedAndRemoveUntil(
// ignore: use_build_context_synchronously
context,
'/home',
(route) => false);
} }
// checks if required fields are not empty. If one is the name will be returned // checks if required fields are not empty. If one is the name will be returned
@@ -401,7 +401,7 @@ class _AddCamMainState extends State<AddCamMain> {
Map<String, dynamic> place = getPlace(); Map<String, dynamic> place = getPlace();
await placeDB.addPlace(place); await placeDB.addPlace(place);
if (widget.isTemplate) { if (widget.isTemplate) {
await placeDB.deleteTemplate(id.text); await placeDB.deleteTemplate(id.text);
} }
@@ -518,11 +518,19 @@ class _AddCamMainState extends State<AddCamMain> {
const SizedBox( const SizedBox(
height: 15, height: 15,
), ),
VarTextField(textController: kSchloNrC, localization: AppLocalizations.of(context)!.kschlonr, dbName: "KSchloNr", required: false), VarTextField(
textController: kSchloNrC,
localization: AppLocalizations.of(context)!.kschlonr,
dbName: "KSchloNr",
required: false),
const SizedBox( const SizedBox(
height: 5, height: 5,
), ),
VarTextField(textController: rudelC, localization: AppLocalizations.of(context)!.rudel, dbName: "Rudel", required: true), VarTextField(
textController: rudelC,
localization: AppLocalizations.of(context)!.rudel,
dbName: "Rudel",
required: true),
const SizedBox( const SizedBox(
height: 15, height: 15,
), ),
@@ -548,6 +556,7 @@ class _AddCamMainState extends State<AddCamMain> {
.push<LatLng>( .push<LatLng>(
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return Karte( return Karte(
beiOrtC: beiOrtC,
currentPosition: currentPosition, currentPosition: currentPosition,
onPositionChange: (updatedPosition) { onPositionChange: (updatedPosition) {
setState(() { setState(() {
@@ -575,10 +584,28 @@ class _AddCamMainState extends State<AddCamMain> {
}, },
child: Text(AppLocalizations.of(context)!.openMap)), child: Text(AppLocalizations.of(context)!.openMap)),
), ),
VarTextField(textController: bLandC, localization: AppLocalizations.of(context)!.bland, dbName: "BLand", required: true, default_value: "bLand",), VarTextField(
VarTextField(textController: lkrC, localization: AppLocalizations.of(context)!.lkr, dbName: "Lkr", required: true), textController: bLandC,
VarTextField(textController: beiOrtC, localization: AppLocalizations.of(context)!.beiort, dbName: "BeiOrt", required: true), localization: AppLocalizations.of(context)!.bland,
VarTextField(textController: ortInfoC, localization: AppLocalizations.of(context)!.ortinfo, dbName: "OrtInfo", required: false), dbName: "BLand",
required: true,
default_value: "bLand",
),
VarTextField(
textController: lkrC,
localization: AppLocalizations.of(context)!.lkr,
dbName: "Lkr",
required: true),
VarTextField(
textController: beiOrtC,
localization: AppLocalizations.of(context)!.beiort,
dbName: "BeiOrt",
required: true),
VarTextField(
textController: ortInfoC,
localization: AppLocalizations.of(context)!.ortinfo,
dbName: "OrtInfo",
required: false),
const SizedBox( const SizedBox(
height: 15, height: 15,
), ),
@@ -627,7 +654,13 @@ class _AddCamMainState extends State<AddCamMain> {
], ],
), ),
), ),
VarTextField(textController: kTage1C, localization: AppLocalizations.of(context)!.ktage1, dbName: "KTage1", required: true, default_value: "kTage1",), VarTextField(
textController: kTage1C,
localization: AppLocalizations.of(context)!.ktage1,
dbName: "KTage1",
required: true,
default_value: "kTage1",
),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
@@ -642,7 +675,13 @@ class _AddCamMainState extends State<AddCamMain> {
) )
], ],
)), )),
VarTextField(textController: kTage2C, localization: AppLocalizations.of(context)!.ktage2, dbName: "KTage1", required: true, default_value: "kTage2",), VarTextField(
textController: kTage2C,
localization: AppLocalizations.of(context)!.ktage2,
dbName: "KTage1",
required: true,
default_value: "kTage2",
),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
@@ -661,9 +700,22 @@ class _AddCamMainState extends State<AddCamMain> {
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
VarTextField(textController: auftragC, localization: AppLocalizations.of(context)!.auftrag, dbName: "Auftrag", required: false), VarTextField(
VarTextField(textController: kontAbspC, localization: AppLocalizations.of(context)!.kontabsp, dbName: "KontAbsp", required: false), textController: auftragC,
VarTextField(textController: sonstBemC, localization: AppLocalizations.of(context)!.sonstbemerkungen, dbName: "SonstBem", required: false), localization: AppLocalizations.of(context)!.auftrag,
dbName: "Auftrag",
required: false),
VarTextField(
textController: kontAbspC,
localization: AppLocalizations.of(context)!.kontabsp,
dbName: "KontAbsp",
required: false),
VarTextField(
textController: sonstBemC,
localization:
AppLocalizations.of(context)!.sonstbemerkungen,
dbName: "SonstBem",
required: false),
], ],
)), )),
// Fourth step // Fourth step
@@ -671,16 +723,46 @@ class _AddCamMainState extends State<AddCamMain> {
title: Text(AppLocalizations.of(context)!.fourthstep), title: Text(AppLocalizations.of(context)!.fourthstep),
content: Column( content: Column(
children: [ children: [
VarTextField(textController: adresse1C, localization: AppLocalizations.of(context)!.adresse1, dbName: "Adresse1", required: true, default_value: "addresse1",), VarTextField(
VarTextField(textController: adresse2C, localization: AppLocalizations.of(context)!.adresse2, dbName: "Adresse2", required: false), textController: adresse1C,
VarTextField(textController: adresse3C, localization: AppLocalizations.of(context)!.adresse3, dbName: "Adresse2", required: false), localization: AppLocalizations.of(context)!.adresse1,
dbName: "Adresse1",
required: true,
default_value: "addresse1",
),
VarTextField(
textController: adresse2C,
localization: AppLocalizations.of(context)!.adresse2,
dbName: "Adresse2",
required: false),
VarTextField(
textController: adresse3C,
localization: AppLocalizations.of(context)!.adresse3,
dbName: "Adresse2",
required: false),
const SizedBox( const SizedBox(
height: 15, height: 15,
), ),
VarTextField(textController: fKontakt1C, localization: AppLocalizations.of(context)!.fkontakt1, dbName: "FKontakt1", required: false), VarTextField(
VarTextField(textController: fKontakt2C, localization: AppLocalizations.of(context)!.fkontakt2, dbName: "FKontakt2", required: false), textController: fKontakt1C,
VarTextField(textController: fKontakt3C, localization: AppLocalizations.of(context)!.fkontakt3, dbName: "FKontakt3", required: false), localization: AppLocalizations.of(context)!.fkontakt1,
VarTextField(textController: intKommC, localization: AppLocalizations.of(context)!.intkomm, dbName: "IntKomm", required: false), dbName: "FKontakt1",
required: false),
VarTextField(
textController: fKontakt2C,
localization: AppLocalizations.of(context)!.fkontakt2,
dbName: "FKontakt2",
required: false),
VarTextField(
textController: fKontakt3C,
localization: AppLocalizations.of(context)!.fkontakt3,
dbName: "FKontakt3",
required: false),
VarTextField(
textController: intKommC,
localization: AppLocalizations.of(context)!.intkomm,
dbName: "IntKomm",
required: false),
], ],
)) ))
]; ];

View File

@@ -142,13 +142,15 @@ class _VarTextFieldState extends State<VarTextField> {
// ! completely new page // ! completely new page
class Karte extends StatefulWidget { class Karte extends StatefulWidget {
final TextEditingController beiOrtC;
final Position currentPosition; final Position currentPosition;
final Function(Position) onPositionChange; final Function(Position) onPositionChange;
const Karte( const Karte(
{super.key, {super.key,
required this.currentPosition, required this.currentPosition,
required this.onPositionChange}); required this.onPositionChange,
required this.beiOrtC});
@override @override
KarteState createState() => KarteState(); KarteState createState() => KarteState();
@@ -194,11 +196,13 @@ class KarteState extends State<Karte> {
onPressed: () async { onPressed: () async {
List<Placemark> placemarks = await placemarkFromCoordinates(selectedPosition!.latitude, selectedPosition!.longitude); List<Placemark> placemarks = await placemarkFromCoordinates(selectedPosition!.latitude, selectedPosition!.longitude);
print(placemarks);
if (selectedPosition != null) { if (selectedPosition != null) {
setState(() { setState(() {
widget.beiOrtC.text = placemarks.first.locality!;
updatedPosition = Position( updatedPosition = Position(
longitude: selectedPosition!.longitude, longitude: selectedPosition!.longitude,
latitude: selectedPosition!.latitude, latitude: selectedPosition!.latitude,