From e0d74591c86cc3623185d2bcdd57cab10d49119c Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 30 Apr 2024 19:04:52 +0200 Subject: [PATCH] now doesnt leave the addcam when user canceles save as file option --- Todo.txt | 7 +- lib/addCam/add_cam_main.dart | 136 ++++++++++++++++++++++++++++------- lib/addCam/cam_widgets.dart | 8 ++- 3 files changed, 118 insertions(+), 33 deletions(-) diff --git a/Todo.txt b/Todo.txt index 01dd2a8..07109f4 100644 --- a/Todo.txt +++ b/Todo.txt @@ -2,11 +2,7 @@ todo: maybe auch vorschläge aus templates in dropdown menüs anzeigen im englischen abändern zurückfeld in datenansicht -dropdown menü fixen (ai fragen) 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 save option einfügen nur zum speichern 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: +fix ktage und nebeneinander positioniere +nach koordinaten lkr auswählen (esri-leaflet-geocoder) +dropdown menü fixen (ai fragen) überschriften für view cams standartwert in textfeld überschriften für view cams diff --git a/lib/addCam/add_cam_main.dart b/lib/addCam/add_cam_main.dart index 27ed920..80f0f21 100644 --- a/lib/addCam/add_cam_main.dart +++ b/lib/addCam/add_cam_main.dart @@ -270,11 +270,6 @@ class _AddCamMainState extends State { saveData(); saveFile(); // ignore: use_build_context_synchronously - Navigator.pushNamedAndRemoveUntil( - // ignore: use_build_context_synchronously - context, - '/home', - (route) => false); }, child: Text(AppLocalizations.of(context)!.saveasfile)), TextButton( @@ -325,14 +320,13 @@ class _AddCamMainState extends State { Future saveFile() async { String? selectedDirectory = await FilePicker.platform.getDirectoryPath(); - SharedPreferences prefs = await SharedPreferences.getInstance(); - Map place = getPlace(); - String jsonPlace = jsonEncode(place); if (selectedDirectory == null) { + // ignore: use_build_context_synchronously + Navigator.pop(context); return; } await prefs.setString('saveDir', selectedDirectory); @@ -344,6 +338,12 @@ class _AddCamMainState extends State { // ignore: use_build_context_synchronously ScaffoldMessenger.of(context).showSnackBar( 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 @@ -401,7 +401,7 @@ class _AddCamMainState extends State { Map place = getPlace(); await placeDB.addPlace(place); - + if (widget.isTemplate) { await placeDB.deleteTemplate(id.text); } @@ -518,11 +518,19 @@ class _AddCamMainState extends State { const SizedBox( 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( 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( height: 15, ), @@ -548,6 +556,7 @@ class _AddCamMainState extends State { .push( MaterialPageRoute(builder: (context) { return Karte( + beiOrtC: beiOrtC, currentPosition: currentPosition, onPositionChange: (updatedPosition) { setState(() { @@ -575,10 +584,28 @@ class _AddCamMainState extends State { }, child: Text(AppLocalizations.of(context)!.openMap)), ), - VarTextField(textController: bLandC, localization: AppLocalizations.of(context)!.bland, 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), + VarTextField( + textController: bLandC, + localization: AppLocalizations.of(context)!.bland, + 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( height: 15, ), @@ -627,7 +654,13 @@ class _AddCamMainState extends State { ], ), ), - 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( height: 20, ), @@ -642,7 +675,13 @@ class _AddCamMainState extends State { ) ], )), - 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( height: 20, ), @@ -661,9 +700,22 @@ class _AddCamMainState extends State { const SizedBox( height: 20, ), - VarTextField(textController: auftragC, 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), + VarTextField( + textController: auftragC, + 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 @@ -671,16 +723,46 @@ class _AddCamMainState extends State { title: Text(AppLocalizations.of(context)!.fourthstep), content: Column( children: [ - VarTextField(textController: adresse1C, 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), + VarTextField( + textController: adresse1C, + 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( height: 15, ), - VarTextField(textController: fKontakt1C, localization: AppLocalizations.of(context)!.fkontakt1, 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), + VarTextField( + textController: fKontakt1C, + localization: AppLocalizations.of(context)!.fkontakt1, + 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), ], )) ]; diff --git a/lib/addCam/cam_widgets.dart b/lib/addCam/cam_widgets.dart index ce94130..89fdb2b 100644 --- a/lib/addCam/cam_widgets.dart +++ b/lib/addCam/cam_widgets.dart @@ -142,13 +142,15 @@ class _VarTextFieldState extends State { // ! completely new page class Karte extends StatefulWidget { + final TextEditingController beiOrtC; final Position currentPosition; final Function(Position) onPositionChange; const Karte( {super.key, required this.currentPosition, - required this.onPositionChange}); + required this.onPositionChange, + required this.beiOrtC}); @override KarteState createState() => KarteState(); @@ -194,11 +196,13 @@ class KarteState extends State { onPressed: () async { List placemarks = await placemarkFromCoordinates(selectedPosition!.latitude, selectedPosition!.longitude); - print(placemarks); if (selectedPosition != null) { setState(() { + + widget.beiOrtC.text = placemarks.first.locality!; + updatedPosition = Position( longitude: selectedPosition!.longitude, latitude: selectedPosition!.latitude,