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

@@ -270,11 +270,6 @@ class _AddCamMainState extends State<AddCamMain> {
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<AddCamMain> {
Future<void> 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<AddCamMain> {
// 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<AddCamMain> {
Map<String, dynamic> place = getPlace();
await placeDB.addPlace(place);
if (widget.isTemplate) {
await placeDB.deleteTemplate(id.text);
}
@@ -518,11 +518,19 @@ class _AddCamMainState extends State<AddCamMain> {
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<AddCamMain> {
.push<LatLng>(
MaterialPageRoute(builder: (context) {
return Karte(
beiOrtC: beiOrtC,
currentPosition: currentPosition,
onPositionChange: (updatedPosition) {
setState(() {
@@ -575,10 +584,28 @@ class _AddCamMainState extends State<AddCamMain> {
},
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<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(
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(
height: 20,
),
@@ -661,9 +700,22 @@ class _AddCamMainState extends State<AddCamMain> {
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<AddCamMain> {
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),
],
))
];