diff --git a/lib/enums/databases.dart b/lib/enums/databases.dart new file mode 100644 index 0000000..3cc3099 --- /dev/null +++ b/lib/enums/databases.dart @@ -0,0 +1,4 @@ +enum DatabasesEnum { + place, + excursion, +} diff --git a/lib/methods/excursion_db_helper.dart b/lib/methods/excursion_db_helper.dart new file mode 100644 index 0000000..6441562 --- /dev/null +++ b/lib/methods/excursion_db_helper.dart @@ -0,0 +1,151 @@ +import 'package:path_provider/path_provider.dart'; +import 'package:sqflite/sqflite.dart'; +import 'dart:io' as io; +import 'package:path/path.dart'; + +// * Gives the complete functionality for the databases +// ! functions may not be named complete correctly + +class ExcursionDBHelper { + static Database? _excursionDB; + + // checks if the databses are existing and creates them with the initPlaceDatabase function if not + Future get excursionDB async { + if (_excursionDB != null) { + return _excursionDB!; + } + _excursionDB = await initExcursionDatabase(); + return _excursionDB!; + } + + // Creates the databases with help from the _onCreateExcursion function + initExcursionDatabase() async { + io.Directory documentsDirectory = await getApplicationCacheDirectory(); + String path = join(documentsDirectory.path, 'excursionDB.db'); + var excursionDB = + await openDatabase(path, version: 1, onCreate: _onCreateExcursion); + return excursionDB; + } + + // The function that helps + _onCreateExcursion(Database excursionDB, int version) async { + await excursionDB.execute( + 'CREATE TABLE excursion (ID INTEGER PRIMARY KEY AUTOINCREMENT, Datum TEXT, Rudel TEXT, Teilnehmer TEXT, Jahr TEXT, Mjahr TEXT, Monat INTEGER, Saison TEXT, Dauer TEXT, BLjahr TEXT, BLand, TEXT, Lkr TEXT, BeiOrt TEXT, Wetter TEXT, Temperat TEXT, RegenVor TEXT, KmAuto TEXT, KmFuss TEXT, KmRad TEXT, KmTotal TEXT, KmAuProf TEXT, KmFuProz TEXT, KmRaProz TEXT, SpGut TEXT, SpSchlecht TEXT, SpurFund TEXT, SpurLang TEXT, SpurTiere Text, SpSicher TEXT, WelpenSp TEXT, WelpenAnz TEXT, WpSicher TEXT, LosungGes TEXT, LosunAnz TEXT, LosunGen TEXT, UrinAnz TEXT, UrinGen TEXT, OestrAnz TEXT, OestrGen TEXT, HaarAnz TEXT, HaarGen TEXT, LosungKm TEXT, GenetiKm TEXT, Hinweise TEXT, Bemerk TEXT, IntKomm TEXT, BimaNr TEXT, BimaName TEXT, BimaNutzer TEXT, BimaAGV TEXT, FallNum INTEGER, MHund TEXT, MLeine TEXT, LogDat TEXT, HinweiseSonstiges TEXT)'); + await excursionDB.execute( + 'CREATE TABLE excursionTemplates (ID INTEGER PRIMARY KEY AUTOINCREMENT, Datum TEXT, Rudel TEXT, Teilnehmer TEXT, Jahr TEXT, Mjahr TEXT, Monat INTEGER, Saison TEXT, Dauer TEXT, BLjahr TEXT, BLand, TEXT, Lkr TEXT, BeiOrt TEXT, Wetter TEXT, Temperat TEXT, RegenVor TEXT, KmAuto TEXT, KmFuss TEXT, KmRad TEXT, KmTotal TEXT, KmAuProf TEXT, KmFuProz TEXT, KmRaProz TEXT, SpGut TEXT, SpSchlecht TEXT, SpurFund TEXT, SpurLang TEXT, SpurTiere Text, SpSicher TEXT, WelpenSp TEXT, WelpenAnz TEXT, WpSicher TEXT, LosungGes TEXT, LosunAnz TEXT, LosunGen TEXT, UrinAnz TEXT, UrinGen TEXT, OestrAnz TEXT, OestrGen TEXT, HaarAnz TEXT, HaarGen TEXT, LosungKm TEXT, GenetiKm TEXT, Hinweise TEXT, Bemerk TEXT, IntKomm TEXT, BimaNr TEXT, BimaName TEXT, BimaNutzer TEXT, BimaAGV TEXT, FallNum INTEGER, MHund TEXT, MLeine TEXT, LogDat TEXT, HinweiseSonstiges TEXT)'); + } + +// Function to add a finished entry and return its ID + Future addExcursion(Map excursion) async { + var excursionDBClient = await excursionDB; + final existingID = await excursionDBClient.query( + 'excursion', + where: 'ID = ?', + whereArgs: [excursion['ID']], + ); + + if (existingID.isNotEmpty) { + updateExcursion(excursion); + return existingID.first['ID'] as int; // Return existing ID + } + + int id = await excursionDBClient.insert( + 'excursion', + excursion, + //conflictAlgorithm: ConflictAlgorithm.replace, + ); + + return id; // Return the ID of the newly inserted entry + } + + Future updateExcursion(Map excursion) async { + var excursionDBClient = await excursionDB; + + await excursionDBClient + .update('excursion', excursion, where: "ID = ?", whereArgs: [excursion['ID']]); + } + + // function to update the sent value + Future updateSent(int id) async { + var excursionDBClient = await excursionDB; + + await excursionDBClient.update('excursion', {'Sent': 1}, + where: 'ID = ?', whereArgs: [id]); + } + + // same thing as before but with templatews + Future addTemplate(Map templates) async { + var excursionDBClient = await excursionDB; + + final existingCID = await excursionDBClient.query( + 'excursionTemplates', + where: 'ID = ?', + whereArgs: [templates['ID']], + ); + if (existingCID.isNotEmpty) { + return; + } + + await excursionDBClient.insert( + 'excursionTemplates', + templates, + // conflictAlgorithm: ConflictAlgorithm.replace, + ); + } + + // Updates a existing template + Future updateTemplate(Map template) async { + var excursionDBClient = await excursionDB; + + await excursionDBClient.update( + 'excursionTemplates', + template, + where: "ID = ?", + whereArgs: [template['ID']], + ); + } + + // get the finished entries from db + Future>> getExcursionen() async { + var excursionDBClient = await excursionDB; + return await excursionDBClient.query('excursion'); + } + + // get the finished templates from db + Future>> getTemplates() async { + var excursionDBClient = await excursionDB; + return await excursionDBClient.query('excursionTemplates'); + } + + // deletes all finished entries from the db LOCALLY + Future deleteAllExcursionen() async { + var excursionDBClient = await excursionDB; + await excursionDBClient.delete('excursion'); + } + + // deletes all templates from the db LOCALLY + Future deleteAllTemplates() async { + var excursionDBClient = await excursionDB; + await excursionDBClient.delete('excursionTemplates'); + } + + // delete specific template + Future deleteTemplate(String id) async { + var excursionDBClient = await excursionDB; + await excursionDBClient.delete( + 'excursionTemplates', + where: 'ID = ?', + whereArgs: [id], + ); + } + +// delete specific excursion + Future deleteExcursion(String id) async { + var excursionDBClient = await excursionDB; + await excursionDBClient.delete( + 'excursion', + where: 'ID = ?', + whereArgs: [id], + ); + } +} diff --git a/lib/methods/db_helper.dart b/lib/methods/place_db_helper.dart similarity index 87% rename from lib/methods/db_helper.dart rename to lib/methods/place_db_helper.dart index bcd8681..d41d439 100644 --- a/lib/methods/db_helper.dart +++ b/lib/methods/place_db_helper.dart @@ -6,7 +6,7 @@ import 'package:path/path.dart'; // * Gives the complete functionality for the databases // ! functions may not be named complete correctly -class DBHelper { +class PlaceDBHelper { static Database? _placeDB; // checks if the databses are existing and creates them with the initPlaceDatabase function if not @@ -32,7 +32,7 @@ class DBHelper { await placeDB.execute( 'CREATE TABLE place (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum DATE, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8), Sent INTEGER DEFAULT 0)'); await placeDB.execute( - 'CREATE TABLE templates (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum DATE, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8))'); + 'CREATE TABLE placeTemplates (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum DATE, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8))'); await placeDB.execute( 'CREATE TABLE excursion (ID INTEGER PRIMARY KEY AUTOINCREMENT, Datum TEXT, Rudel TEXT, Teilnehmer TEXT, Jahr TEXT, Mjahr TEXT, Monat INTEGER, Saison TEXT, Dauer TEXT, BLjahr TEXT, BLand, TEXT, Lkr TEXT, BeiOrt TEXT, Wetter TEXT, Temperat TEXT, RegenVor TEXT, KmAuto TEXT, KmFuss TEXT, KmRad TEXT, KmTotal TEXT, KmAuProf TEXT, KmFuProz TEXT, KmRaProz TEXT, SpGut TEXT, SpSchlecht TEXT, SpurFund TEXT, SpurLang TEXT, SpurTiere Text, SpSicher TEXT, WelpenSp TEXT, WelpenAnz TEXT, WpSicher TEXT, LosungGes TEXT, LosunAnz TEXT, LosunGen TEXT, UrinAnz TEXT, UrinGen TEXT, OestrAnz TEXT, OestrGen TEXT, HaarAnz TEXT, HaarGen TEXT, LosungKm TEXT, GenetiKm TEXT, Hinweise TEXT, Bemerk TEXT, IntKomm TEXT, BimaNr TEXT, BimaName TEXT, BimaNutzer TEXT, BimaAGV TEXT, FallNum INTEGER, MHund TEXT, MLeine TEXT, LogDat TEXT)'); } @@ -80,7 +80,7 @@ class DBHelper { var placeDBClient = await placeDB; final existingCID = await placeDBClient.query( - 'templates', + 'placeTemplates', where: 'ID = ?', whereArgs: [templates['ID']], ); @@ -89,7 +89,7 @@ class DBHelper { } await placeDBClient.insert( - 'templates', + 'placeTemplates', templates, // conflictAlgorithm: ConflictAlgorithm.replace, ); @@ -100,7 +100,7 @@ class DBHelper { var placeDBClient = await placeDB; await placeDBClient.update( - 'templates', + 'placeTemplates', template, where: "ID = ?", whereArgs: [template['ID']], @@ -116,7 +116,7 @@ class DBHelper { // get the finished templates from db Future>> getTemplates() async { var placeDBClient = await placeDB; - return await placeDBClient.query('templates'); + return await placeDBClient.query('placeTemplates'); } // deletes all finished entries from the db LOCALLY @@ -128,14 +128,14 @@ class DBHelper { // deletes all templates from the db LOCALLY Future deleteAllTemplates() async { var placeDBClient = await placeDB; - await placeDBClient.delete('templates'); + await placeDBClient.delete('placeTemplates'); } // delete specific template Future deleteTemplate(String id) async { var placeDBClient = await placeDB; await placeDBClient.delete( - 'templates', + 'placeTemplates', where: 'ID = ?', whereArgs: [id], ); diff --git a/lib/screens/Excursion/excursion_main.dart b/lib/screens/Excursion/excursion_main.dart index 83aeac5..1f2aa4f 100644 --- a/lib/screens/Excursion/excursion_main.dart +++ b/lib/screens/Excursion/excursion_main.dart @@ -1,4 +1,5 @@ import 'package:animations/animations.dart'; +import 'package:fforte/enums/databases.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'; @@ -23,64 +24,64 @@ class _ExcursionMainState extends State { Map getTextFields() { Map rmap = { - // Step 1 - "LogDat": TextEditingController(), - "Rudel": TextEditingController(), - "Teilnehm": TextEditingController(), - "Jahr": TextEditingController(), - "Dauer": TextEditingController(), - "MHund": TextEditingController(), - "MLeine": TextEditingController(), - "BLand": TextEditingController(), - "Lkr": TextEditingController(), - "BeiOrt": TextEditingController(), - "BimaNr": TextEditingController(), - "BimaName": TextEditingController(), - "BimaNutzer": TextEditingController(), - "BimaAGV": TextEditingController(), + // Step 1 + "LogDat": TextEditingController(), + "Rudel": TextEditingController(), + "Teilnehm": TextEditingController(), + "Jahr": TextEditingController(), + "Dauer": TextEditingController(), + "MHund": TextEditingController(), + "MLeine": TextEditingController(), + "BLand": TextEditingController(), + "Lkr": TextEditingController(), + "BeiOrt": TextEditingController(), + "BimaNr": TextEditingController(), + "BimaName": TextEditingController(), + "BimaNutzer": TextEditingController(), + "BimaAGV": TextEditingController(), - // Step 2 - "Wetter": TextEditingController(), - "Temperat": TextEditingController(), - "RegenVor": TextEditingController(), - "KmAuto": TextEditingController(), - "KmFuss": TextEditingController(), - "KmRad": TextEditingController(), - "KmTotal": TextEditingController(), - "KmAuProz": TextEditingController(), - "KmFuProz": TextEditingController(), - "KmRaProz": TextEditingController(), + // Step 2 + "Wetter": TextEditingController(), + "Temperat": TextEditingController(), + "RegenVor": TextEditingController(), + "KmAuto": TextEditingController(), + "KmFuss": TextEditingController(), + "KmRad": TextEditingController(), + "KmTotal": TextEditingController(), + "KmAuProz": TextEditingController(), + "KmFuProz": TextEditingController(), + "KmRaProz": TextEditingController(), - // Spur maybe own step? - "SpGut": TextEditingController(), - "SpMittel": TextEditingController(), - "SpSchlecht": TextEditingController(), - "SpurFund": TextEditingController(), - "SpurLang": TextEditingController(), - "SpurTiere": TextEditingController(), - "SpSicher": TextEditingController(), - "WelpenSp": TextEditingController(), - "WelpenAnz": TextEditingController(), - "WpSicher": TextEditingController(), + // Spur maybe own step? + "SpGut": TextEditingController(), + "SpMittel": TextEditingController(), + "SpSchlecht": TextEditingController(), + "SpurFund": TextEditingController(), + "SpurLang": TextEditingController(), + "SpurTiere": TextEditingController(), + "SpSicher": TextEditingController(), + "WelpenSp": TextEditingController(), + "WelpenAnz": TextEditingController(), + "WpSicher": TextEditingController(), - "LosungGes": TextEditingController(), - "LosungAnz": TextEditingController(), - "LosungGen": TextEditingController(), - "UrinAnz": TextEditingController(), - "UrinGen": TextEditingController(), - "OestrAnz": TextEditingController(), - "OestrGen": TextEditingController(), - "HaarAnz": TextEditingController(), - "HaarGen": TextEditingController(), - "LosungKm": TextEditingController(), - "GenetiKm": TextEditingController(), - "Hinweise": TextEditingController(), + "LosungGes": TextEditingController(), + "LosungAnz": TextEditingController(), + "LosungGen": TextEditingController(), + "UrinAnz": TextEditingController(), + "UrinGen": TextEditingController(), + "OestrAnz": TextEditingController(), + "OestrGen": TextEditingController(), + "HaarAnz": TextEditingController(), + "HaarGen": TextEditingController(), + "LosungKm": TextEditingController(), + "GenetiKm": TextEditingController(), + "Hinweise": TextEditingController(), - // Step 3 - "Bemerk": TextEditingController(), - "IntKomm": TextEditingController(), - "FallNum": TextEditingController(), - }; + // Step 3 + "Bemerk": TextEditingController(), + "IntKomm": TextEditingController(), + "FallNum": TextEditingController(), + }; return rmap; } @@ -90,235 +91,265 @@ class _ExcursionMainState extends State { @override Widget build(BuildContext context) { List getSteps() => [ - Step( - title: Text(AppLocalizations.of(context)!.dateandtime), - content: Column( - children: [ - Datum( - initDatum: DateTime.now(), - onDateChanged: (date) { - getTextFields()["LogDat"]!.text = date.toString(); - }, - name: AppLocalizations.of(context)!.date, - ), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["Rudel"]!, - localization: AppLocalizations.of(context)!.rudel, - dbName: "Rudel", - required: false), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["Teilnehm"]!, - localization: AppLocalizations.of(context)!.teilnehmer, - dbName: "Teilnehm", - required: false, - ), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["Dauer"]!, - localization: AppLocalizations.of(context)!.dauer, - dbName: "Dauer", - required: false), - const SizedBox( - height: 10, - ), - HundULeine(onMHundChanged: (mHund, mLeine) { - getTextFields()["MHund"]!.text = mHund; - getTextFields()["MLeine"]!.text = mLeine; - - // print(mHund); - // print(mLeine); - }), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["BLand"]!, - localization: AppLocalizations.of(context)!.bland, - dbName: "BLand", - required: false), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["Lkr"]!, - localization: AppLocalizations.of(context)!.lkr, - dbName: "Lkr", - required: false), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["BeiOrt"]!, - localization: AppLocalizations.of(context)!.beiort, - dbName: "BeiOrt", - required: false), - const SizedBox( - height: 10, - ), - const Divider(), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["BimaNr"]!, - localization: AppLocalizations.of(context)!.bimaNr, - dbName: "BimaNr", - required: false), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["BimaName"]!, - localization: AppLocalizations.of(context)!.bimaName, - dbName: "BimaName", - required: false), - const SizedBox( - height: 10, - ), - BimaNutzer(onBimaNutzerChanged: (value) { - setState(() { - getTextFields()["BimaNutzer"]!.text = value; - }); - }), - const SizedBox( - height: 10, - ), - VarTextField( - textController: getTextFields()["BimaAGV"]!, - localization: AppLocalizations.of(context)!.bimaAGV, - dbName: "BimaAGV", - required: false) - ], - )), - Step( - title: const Text("step2"), - content: Column( - children: [ - VarTextField( - textController: getTextFields()["Wetter"]!, - localization: "Wetter", - dbName: "Wetter", - required: false), - const SizedBox(height: 10), - VarTextField( - textController: getTextFields()["Temperat"]!, - localization: "Temperatur", - dbName: "Temperat", - required: false), - const SizedBox(height: 10), - LetzterNiederschlag(controller: getTextFields()["RegenVor"]!), - const SizedBox(height: 20), - StreckeUSpurbedingungen( - kmAutoController: getTextFields()["KmAuto"]!, - kmFussController: getTextFields()["KmFuss"]!, - kmRadController: getTextFields()["KmRad"]!, - spGutController: getTextFields()["SpGut"]!, - spMittelController: getTextFields()["SpMittel"]!, - spSchlechtController: getTextFields()["SpSchlecht"]!, - ), - const SizedBox( - height: 20, - ), - const Divider(), - SpurGefunden( - spurFund: getTextFields()["SpurFund"]!, - spurLang: getTextFields()["SpurLang"]!, - spurTiere: getTextFields()["SpurTiere"]!, - spSicher: getTextFields()["SpSicher"]!, - welpenSp: getTextFields()["WelpenSp"]!, - welpenAnz: getTextFields()["WelpenAnz"]!, - wpSicher: getTextFields()["WpSicher"]!), - const SizedBox( - height: 20, - ), - Anzahlen( - losungAnz: getTextFields()["LosungAnz"]!, - losungGes: getTextFields()["LosungGes"]!, - losungGen: getTextFields()["LosungGen"]!, - urinAnz: getTextFields()["UrinAnz"]!, - urinGen: getTextFields()["UrinGen"]!, - oestrAnz: getTextFields()["OestrAnz"]!, - oestrGen: getTextFields()["OestrGen"]!, - haarAnz: getTextFields()["HaarAnz"]!, - haarGen: getTextFields()["HaarGen"]!, - ), - const SizedBox( - height: 20, - ), - Hinweise(), - ], + Step( + title: Text(AppLocalizations.of(context)!.dateandtime), + content: Column( + children: [ + Datum( + initDatum: DateTime.now(), + onDateChanged: (date) { + getTextFields()["LogDat"]!.text = date.toString(); + }, + name: AppLocalizations.of(context)!.date, ), - ), - - Step( - title: const Text("step3"), - content: Column( - children: [ - VarTextField(textController: getTextFields()["Bemerk"]!, - localization: "Bemerkungen", - dbName: "Bemerk", - required: false), - - const SizedBox(height: 20,), - VarTextField(textController: getTextFields()["IntKomm"]!, - localization: "Interne Kommunikation", - dbName: "IntKomm", required: false), - ], + const SizedBox( + height: 10, ), - ), - ]; + VarTextField( + textController: getTextFields()["Rudel"]!, + localization: AppLocalizations.of(context)!.rudel, + dbName: "Rudel", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["Teilnehm"]!, + localization: AppLocalizations.of(context)!.teilnehmer, + dbName: "Teilnehm", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["Dauer"]!, + localization: AppLocalizations.of(context)!.dauer, + dbName: "Dauer", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + HundULeine(onMHundChanged: (mHund, mLeine) { + getTextFields()["MHund"]!.text = mHund; + getTextFields()["MLeine"]!.text = mLeine; + + // print(mHund); + // print(mLeine); + }), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["BLand"]!, + localization: AppLocalizations.of(context)!.bland, + dbName: "BLand", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["Lkr"]!, + localization: AppLocalizations.of(context)!.lkr, + dbName: "Lkr", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["BeiOrt"]!, + localization: AppLocalizations.of(context)!.beiort, + dbName: "BeiOrt", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + const Divider(), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["BimaNr"]!, + localization: AppLocalizations.of(context)!.bimaNr, + dbName: "BimaNr", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["BimaName"]!, + localization: AppLocalizations.of(context)!.bimaName, + dbName: "BimaName", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox( + height: 10, + ), + BimaNutzer(onBimaNutzerChanged: (value) { + setState(() { + getTextFields()["BimaNutzer"]!.text = value; + }); + }), + const SizedBox( + height: 10, + ), + VarTextField( + textController: getTextFields()["BimaAGV"]!, + localization: AppLocalizations.of(context)!.bimaAGV, + dbName: "BimaAGV", + required: false, + dbDesignation: DatabasesEnum.excursion, + ) + ], + )), + Step( + title: const Text("step2"), + content: Column( + children: [ + VarTextField( + textController: getTextFields()["Wetter"]!, + localization: "Wetter", + dbName: "Wetter", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox(height: 10), + VarTextField( + textController: getTextFields()["Temperat"]!, + localization: "Temperatur", + dbName: "Temperat", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + const SizedBox(height: 10), + LetzterNiederschlag(controller: getTextFields()["RegenVor"]!), + const SizedBox(height: 20), + StreckeUSpurbedingungen( + kmAutoController: getTextFields()["KmAuto"]!, + kmFussController: getTextFields()["KmFuss"]!, + kmRadController: getTextFields()["KmRad"]!, + spGutController: getTextFields()["SpGut"]!, + spMittelController: getTextFields()["SpMittel"]!, + spSchlechtController: getTextFields()["SpSchlecht"]!, + ), + const SizedBox( + height: 20, + ), + const Divider(), + SpurGefunden( + spurFund: getTextFields()["SpurFund"]!, + spurLang: getTextFields()["SpurLang"]!, + spurTiere: getTextFields()["SpurTiere"]!, + spSicher: getTextFields()["SpSicher"]!, + welpenSp: getTextFields()["WelpenSp"]!, + welpenAnz: getTextFields()["WelpenAnz"]!, + wpSicher: getTextFields()["WpSicher"]!), + const SizedBox( + height: 20, + ), + Anzahlen( + losungAnz: getTextFields()["LosungAnz"]!, + losungGes: getTextFields()["LosungGes"]!, + losungGen: getTextFields()["LosungGen"]!, + urinAnz: getTextFields()["UrinAnz"]!, + urinGen: getTextFields()["UrinGen"]!, + oestrAnz: getTextFields()["OestrAnz"]!, + oestrGen: getTextFields()["OestrGen"]!, + haarAnz: getTextFields()["HaarAnz"]!, + haarGen: getTextFields()["HaarGen"]!, + ), + const SizedBox( + height: 20, + ), + const Divider(), + Hinweise( + hinweise: getTextFields()["Hinweise"]!, + ), + ], + ), + ), + + Step( + title: const Text("step3"), + content: Column( + children: [ + VarTextField(textController: getTextFields()["Bemerk"]!, + localization: "Bemerkungen", + dbName: "Bemerk", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + + const SizedBox(height: 20,), + VarTextField( + textController: getTextFields()["IntKomm"]!, + localization: "Interne Kommunikation", + dbName: "IntKomm", + required: false, + dbDesignation: DatabasesEnum.excursion, + ), + ], + ), + ), + ]; return Scaffold( - appBar: AppBar( - title: Text(AppLocalizations.of(context)!.excursion), - ), - body: PageTransitionSwitcher( - duration: const Duration(microseconds: 800), - transitionBuilder: (Widget child, Animation animation, - Animation secondaryAnimation) { - return SharedAxisTransition( - animation: animation, - secondaryAnimation: secondaryAnimation, - transitionType: SharedAxisTransitionType.vertical, - child: child, - ); + appBar: AppBar( + title: Text(AppLocalizations.of(context)!.excursion), + ), + body: PageTransitionSwitcher( + duration: const Duration(microseconds: 800), + transitionBuilder: (Widget child, Animation animation, + Animation secondaryAnimation) { + return SharedAxisTransition( + animation: animation, + secondaryAnimation: secondaryAnimation, + transitionType: SharedAxisTransitionType.vertical, + child: child, + ); + }, + child: Stepper( + key: ValueKey(currentStep), + steps: getSteps(), + currentStep: currentStep, + onStepTapped: (value) { + setState(() { + currentStep = value; + }); }, - child: Stepper( - key: ValueKey(currentStep), - steps: getSteps(), - currentStep: currentStep, - onStepTapped: (value) { - setState(() { - currentStep = value; - }); - }, - onStepContinue: () { - final isLastStep = currentStep == getSteps().length - 1; + onStepContinue: () { + final isLastStep = currentStep == getSteps().length - 1; - if (!isLastStep) { + if (!isLastStep) { setState(() { currentStep += 1; }); } - }, - onStepCancel: () { - if (currentStep == 0) { + }, + onStepCancel: () { + if (currentStep == 0) { Navigator.pop(context); } else { setState(() { currentStep -= 1; }); } - }, - ), - )); + }, + ), + )); } } diff --git a/lib/screens/Excursion/widgets/hinweise.dart b/lib/screens/Excursion/widgets/hinweise.dart index 1ee92ab..36b3f9e 100644 --- a/lib/screens/Excursion/widgets/hinweise.dart +++ b/lib/screens/Excursion/widgets/hinweise.dart @@ -1,18 +1,76 @@ +import 'package:fforte/enums/databases.dart'; +import 'package:fforte/screens/sharedWidgets/var_text_field.dart'; import 'package:flutter/material.dart'; class Hinweise extends StatefulWidget { - const Hinweise({super.key}); + final TextEditingController hinweise; + + const Hinweise({super.key, required this.hinweise}); @override State createState() => _HinweiseState(); } class _HinweiseState extends State { + // Vars for Checkboxes + bool liegestelleChecked = false; + bool kadaverChecked = false; + bool sichtungChecked = false; + bool heulenChecked = false; + bool sonstigesChecked = false; + + // for sonstiges textfield + TextEditingController sonstigesController = TextEditingController(); + + @override Widget build(BuildContext context) { - return SizedBox( - height: 30, - child: const Placeholder()); + return + Column( + children: [ + CheckboxListTile( + title: Text("Liegestelle"), + value: liegestelleChecked, + onChanged: (bool? value) { + setState(() => liegestelleChecked = value ?? false); + } + ), + + CheckboxListTile( + title: Text("Wildtierkadaver"), + value: kadaverChecked, + onChanged: (bool? value) { + setState(() => kadaverChecked = value ?? false); + } + ), + + CheckboxListTile( + title: Text("Sichtung"), + value: sichtungChecked, + onChanged: (bool? value) { + setState(() => sichtungChecked = value ?? false); + } + ), + + CheckboxListTile( + title: Text("Heulen"), + value: heulenChecked, + onChanged: (bool? value) { + setState(() => heulenChecked = value ?? false); + } + ), + CheckboxListTile( + title: Text("Sonstiges"), + value: liegestelleChecked, + onChanged: (bool? value) { + setState(() => sonstigesChecked = value ?? false); + } + ), + + if (sonstigesChecked) + VarTextField(textController: sonstigesController, localization: "Sonstiges", dbName: "HinweiseSonstiges", required: false, dbDesignation: DatabasesEnum.excursion,) + ], + ); } } diff --git a/lib/screens/addCam/add_cam_main.dart b/lib/screens/addCam/add_cam_main.dart index d996203..6f9fe47 100644 --- a/lib/screens/addCam/add_cam_main.dart +++ b/lib/screens/addCam/add_cam_main.dart @@ -1,8 +1,9 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'package:fforte/enums/databases.dart'; import 'package:fforte/screens/addCam/cam_widgets.dart'; -import 'package:fforte/methods/db_helper.dart'; +import 'package:fforte/methods/place_db_helper.dart'; import 'package:fforte/methods/http_request.dart'; import 'package:fforte/screens/sharedWidgets/datum.dart'; import 'package:fforte/screens/sharedWidgets/var_text_field.dart'; @@ -21,11 +22,11 @@ class AddCamMain extends StatefulWidget { final Map? existingData; const AddCamMain( - {super.key, - this.isTemplate = false, - this.existingData, - this.isFinished = false, - this.isSent = false}); + {super.key, + this.isTemplate = false, + this.existingData, + this.isFinished = false, + this.isSent = false}); @override State createState() => _AddCamMainState(); @@ -65,16 +66,16 @@ class _AddCamMainState extends State { String selectedPlatzung = ''; 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); + 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); DateTime? abbauDat; DateTime datum = DateTime.now(); @@ -83,40 +84,40 @@ class _AddCamMainState extends State { Map getPlace() { Map place = { - 'ID': widget.existingData?['ID'], - 'CID': cid.text, - 'Rudel': rudelC.text, - 'Datum': datum.toString().split(" ").first, - 'Adresse1': adresse1C.text, - 'Adresse2': adresse2C.text, - 'Adresse3': adresse3C.text, - 'BLand': bLandC.text, - 'Lkr': lkrC.text, - 'BeiOrt': beiOrtC.text, - 'OrtInfo': ortInfoC.text, - 'Status': selectedStatus, - 'FFTyp': ffTypC.text, - 'FotoFilm': selectedFotoFilm, - 'MEZ': selectedMEZ, - 'Platzung': selectedPlatzung, - 'KSchloNr': kSchloNrC.text, - 'KontDat': kontDat.toString().split(" ").first, - 'AbbauDat': abbauDat.toString().split(" ").first.replaceAll("null", ""), - 'Auftrag': auftragC.text, - 'KontAbsp': kontAbspC.text, - 'SonstBem': sonstBemC.text, - 'FKontakt1': fKontakt1C.text, - 'FKontakt2': fKontakt2C.text, - 'FKontakt3': fKontakt3C.text, - 'Standort': standortC.text, - 'KTage1': kTage1C.text, - 'KTage2': kTage2C.text, - 'ProtoAm': protoAm.toString().split(" ").first, - 'IntKomm': intKommC.text, - 'Betreuung': betreuungC.text, - 'DECLNG': currentPosition.longitude, - 'DECLAT': currentPosition.latitude, - }; + 'ID': widget.existingData?['ID'], + 'CID': cid.text, + 'Rudel': rudelC.text, + 'Datum': datum.toString().split(" ").first, + 'Adresse1': adresse1C.text, + 'Adresse2': adresse2C.text, + 'Adresse3': adresse3C.text, + 'BLand': bLandC.text, + 'Lkr': lkrC.text, + 'BeiOrt': beiOrtC.text, + 'OrtInfo': ortInfoC.text, + 'Status': selectedStatus, + 'FFTyp': ffTypC.text, + 'FotoFilm': selectedFotoFilm, + 'MEZ': selectedMEZ, + 'Platzung': selectedPlatzung, + 'KSchloNr': kSchloNrC.text, + 'KontDat': kontDat.toString().split(" ").first, + 'AbbauDat': abbauDat.toString().split(" ").first.replaceAll("null", ""), + 'Auftrag': auftragC.text, + 'KontAbsp': kontAbspC.text, + 'SonstBem': sonstBemC.text, + 'FKontakt1': fKontakt1C.text, + 'FKontakt2': fKontakt2C.text, + 'FKontakt3': fKontakt3C.text, + 'Standort': standortC.text, + 'KTage1': kTage1C.text, + 'KTage2': kTage2C.text, + 'ProtoAm': protoAm.toString().split(" ").first, + 'IntKomm': intKommC.text, + 'Betreuung': betreuungC.text, + 'DECLNG': currentPosition.longitude, + 'DECLAT': currentPosition.latitude, + }; return place; } @@ -209,174 +210,174 @@ class _AddCamMainState extends State { // Function to show the dialog where the user has to choose if he want to safe his values as a template Future showTemplateDialog(List emptyField) async { return showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) { - return AlertDialog( - title: Text(AppLocalizations.of(context)!.fieldEmpty), - content: SingleChildScrollView( - child: ListBody(children: [Text(emptyField.join("; "))]), - ), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text(AppLocalizations.of(context)!.cancel)), - TextButton( - onPressed: () { - saveTemplate(); - Navigator.pushNamedAndRemoveUntil( - context, '/home', (route) => false); - }, - child: Text(AppLocalizations.of(context)!.template)) - ], - ); - }); + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + title: Text(AppLocalizations.of(context)!.fieldEmpty), + content: SingleChildScrollView( + child: ListBody(children: [Text(emptyField.join("; "))]), + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text(AppLocalizations.of(context)!.cancel)), + TextButton( + onPressed: () { + saveTemplate(); + Navigator.pushNamedAndRemoveUntil( + context, '/home', (route) => false); + }, + child: Text(AppLocalizations.of(context)!.template)) + ], + ); + }); } Future _showServerErrorDialog() { bool isLoading = false; return showDialog( - context: context, - builder: (context) { - return StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - return AlertDialog( - title: Text(AppLocalizations.of(context)!.servererrortitle), - content: isLoading - ? const SizedBox( - height: 100, - child: Center(child: CircularProgressIndicator())) - : null, - actions: [ - if (!isLoading) - TextButton( - onPressed: () async { - setState(() => isLoading = true); - int errorCode = await _httpRequest(); - setState(() => isLoading = false); + context: context, + builder: (context) { + return StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return AlertDialog( + title: Text(AppLocalizations.of(context)!.servererrortitle), + content: isLoading + ? const SizedBox( + height: 100, + child: Center(child: CircularProgressIndicator())) + : null, + actions: [ + if (!isLoading) + TextButton( + onPressed: () async { + setState(() => isLoading = true); + int errorCode = await _httpRequest(); + setState(() => isLoading = false); - if (errorCode != 201 && context.mounted) { + if (errorCode != 201 && context.mounted) { _showServerErrorDialog(); } else { if (context.mounted) Navigator.pop(context); saveData(true); _showSuccessDialog(); } - }, - child: Text(AppLocalizations.of(context)!.sendagain)), - if (!isLoading) - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: Text(AppLocalizations.of(context)!.cancel)) - ], - ); - }, - ); - }); + }, + child: Text(AppLocalizations.of(context)!.sendagain)), + if (!isLoading) + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: Text(AppLocalizations.of(context)!.cancel)) + ], + ); + }, + ); + }); } Future showSaveOptionsDialog() async { bool isLoading = false; return showDialog( - context: context, - barrierDismissible: - false, // Verhindert das Schließen des Dialogs durch den Benutzer - builder: (BuildContext context) { - return StatefulBuilder( - builder: (context, setState) { - return AlertDialog( - title: isLoading - ? Text(AppLocalizations.of(context)!.loading) - : Text(AppLocalizations.of(context)!.savemethod), - content: isLoading - ? const SizedBox( - height: 100, - child: Center(child: CircularProgressIndicator())) - : null, - actions: [ - if (!isLoading) - TextButton( - onPressed: () async { - setState(() => isLoading = true); - saveTemplate(); - Navigator.pushNamedAndRemoveUntil( - context, '/home', (route) => false); - }, - child: Text(AppLocalizations.of(context)!.template)), - if (!isLoading) - TextButton( - onPressed: () async { - setState(() => isLoading = true); - int errorCode = await _httpRequest(); - setState(() => isLoading = false); + context: context, + barrierDismissible: + false, // Verhindert das Schließen des Dialogs durch den Benutzer + builder: (BuildContext context) { + return StatefulBuilder( + builder: (context, setState) { + return AlertDialog( + title: isLoading + ? Text(AppLocalizations.of(context)!.loading) + : Text(AppLocalizations.of(context)!.savemethod), + content: isLoading + ? const SizedBox( + height: 100, + child: Center(child: CircularProgressIndicator())) + : null, + actions: [ + if (!isLoading) + TextButton( + onPressed: () async { + setState(() => isLoading = true); + saveTemplate(); + Navigator.pushNamedAndRemoveUntil( + context, '/home', (route) => false); + }, + child: Text(AppLocalizations.of(context)!.template)), + if (!isLoading) + TextButton( + onPressed: () async { + setState(() => isLoading = true); + int errorCode = await _httpRequest(); + setState(() => isLoading = false); - if (errorCode != 201 || !context.mounted) { + if (errorCode != 201 || !context.mounted) { saveData(); _showServerErrorDialog(); } else { saveData(true); _showSuccessDialog(); } - }, - child: - Text(AppLocalizations.of(context)!.sendtoserver)), - if (!isLoading) - TextButton( - onPressed: () async { - setState(() => isLoading = true); - saveData(); - saveFile(); - setState(() => isLoading = false); - }, - child: Text(AppLocalizations.of(context)!.saveasfile)), - if (!isLoading) - TextButton( - onPressed: () { - saveData(); - Navigator.pushNamedAndRemoveUntil( - context, '/home', (route) => false); - }, - child: Text(AppLocalizations.of(context)!.justsave)), - if (!isLoading) - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: Text(AppLocalizations.of(context)!.cancel)), - ], - ); - }, - ); - }); + }, + child: + Text(AppLocalizations.of(context)!.sendtoserver)), + if (!isLoading) + TextButton( + onPressed: () async { + setState(() => isLoading = true); + saveData(); + saveFile(); + setState(() => isLoading = false); + }, + child: Text(AppLocalizations.of(context)!.saveasfile)), + if (!isLoading) + TextButton( + onPressed: () { + saveData(); + Navigator.pushNamedAndRemoveUntil( + context, '/home', (route) => false); + }, + child: Text(AppLocalizations.of(context)!.justsave)), + if (!isLoading) + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: Text(AppLocalizations.of(context)!.cancel)), + ], + ); + }, + ); + }); } Future _showSuccessDialog() async { return showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text(AppLocalizations.of(context)!.successful), - actions: [ -/* TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: Text(AppLocalizations.of(context)!.back)), */ - TextButton( - onPressed: () { - Navigator.pushNamedAndRemoveUntil( - context, '/home', (route) => false); - }, - child: Text(AppLocalizations.of(context)!.continueB)) - ], - ); - }); + context: context, + builder: (context) { + return AlertDialog( + title: Text(AppLocalizations.of(context)!.successful), + actions: [ + /* TextButton( +onPressed: () { +Navigator.pop(context); +}, +child: Text(AppLocalizations.of(context)!.back)), */ + TextButton( + onPressed: () { + Navigator.pushNamedAndRemoveUntil( + context, '/home', (route) => false); + }, + child: Text(AppLocalizations.of(context)!.continueB)) + ], + ); + }); } Future _httpRequest() async { @@ -402,7 +403,7 @@ class _AddCamMainState extends State { await prefs.setString('saveDir', selectedDirectory); File file = File( - '$selectedDirectory/${mounted ? AppLocalizations.of(context)!.justplace : const Text('')}-${standortC.text}.txt'); + '$selectedDirectory/${mounted ? AppLocalizations.of(context)!.justplace : const Text('')}-${standortC.text}.txt'); try { await file.writeAsString(jsonPlace); @@ -429,27 +430,27 @@ class _AddCamMainState extends State { List emptyFields = []; Map fields = { - AppLocalizations.of(context)!.camLink: cid, - AppLocalizations.of(context)!.rudel: rudelC, - AppLocalizations.of(context)!.adresse1: adresse1C, - AppLocalizations.of(context)!.bland: bLandC, - AppLocalizations.of(context)!.lkr: lkrC, - AppLocalizations.of(context)!.beiort: beiOrtC, - AppLocalizations.of(context)!.status: TextEditingController(text: selectedStatus), - AppLocalizations.of(context)!.fftyp: ffTypC, - "${AppLocalizations.of(context)!.foto} / ${AppLocalizations.of(context)!.filelocation}": TextEditingController(text: selectedFotoFilm), - AppLocalizations.of(context)!.zeiteinstellung: TextEditingController(text: selectedMEZ), - AppLocalizations.of(context)!.platzung: TextEditingController(text: selectedPlatzung), - AppLocalizations.of(context)!.ktage1: kTage1C, - AppLocalizations.of(context)!.ktage1: kTage2C, - AppLocalizations.of(context)!.location: standortC, - }; + AppLocalizations.of(context)!.camLink: cid, + AppLocalizations.of(context)!.rudel: rudelC, + AppLocalizations.of(context)!.adresse1: adresse1C, + AppLocalizations.of(context)!.bland: bLandC, + AppLocalizations.of(context)!.lkr: lkrC, + AppLocalizations.of(context)!.beiort: beiOrtC, + AppLocalizations.of(context)!.status: TextEditingController(text: selectedStatus), + AppLocalizations.of(context)!.fftyp: ffTypC, + "${AppLocalizations.of(context)!.foto} / ${AppLocalizations.of(context)!.filelocation}": TextEditingController(text: selectedFotoFilm), + AppLocalizations.of(context)!.zeiteinstellung: TextEditingController(text: selectedMEZ), + AppLocalizations.of(context)!.platzung: TextEditingController(text: selectedPlatzung), + AppLocalizations.of(context)!.ktage1: kTage1C, + AppLocalizations.of(context)!.ktage1: kTage2C, + AppLocalizations.of(context)!.location: standortC, + }; for (var entry in fields.entries) { - if (entry.value.text.isEmpty) { + if (entry.value.text.isEmpty) { emptyFields.add(entry.key); } - } + } empty = false; if (emptyFields.isNotEmpty) empty = true; @@ -460,7 +461,7 @@ class _AddCamMainState extends State { // If the user decides to safe his values as a template this function is called to save the values in the database // If the user already edits a template this template will be upadted otherwise a new one will be created void saveTemplate() async { - var placeDB = DBHelper(); + var placeDB = PlaceDBHelper(); Map templates = getPlace(); @@ -474,7 +475,7 @@ class _AddCamMainState extends State { // If the user has filled all needed values this function will be called to safe them in the database // * also creates a json string to send it to the server later void saveData([bool sent = false]) async { - var placeDB = DBHelper(); + var placeDB = PlaceDBHelper(); Map place = getPlace(); // Get the ID of the newly added or updated place @@ -495,137 +496,148 @@ class _AddCamMainState extends State { Widget build(BuildContext context) { // List with the steps. The steps itself will be "shown" later List getSteps() => [ - // First step - Step( - title: Text(AppLocalizations.of(context)!.firststep), - content: Column( + // First step + Step( + title: Text(AppLocalizations.of(context)!.firststep), + content: Column( + children: [ + Align( + alignment: Alignment.bottomLeft, + child: VarTextField( + required: true, + dbName: "Standort", + textController: standortC, + localization: AppLocalizations.of(context)!.altstort, + dbDesignation: DatabasesEnum.place, + ), + ), + const SizedBox( + height: 5, + ), + Align( + alignment: Alignment.bottomLeft, + child: Row( children: [ - Align( - alignment: Alignment.bottomLeft, - child: VarTextField( - required: true, - dbName: "Standort", - textController: standortC, - localization: AppLocalizations.of(context)!.altstort, - ), - ), - const SizedBox( - height: 5, - ), - Align( - alignment: Alignment.bottomLeft, - child: Row( - children: [ - Text(AppLocalizations.of(context)!.status), - const Text( - '*', - style: TextStyle(color: Colors.red), - ), - ], - )), - Status( - initialStatus: selectedStatus, - onStatusChanged: (status) { - setState(() { - selectedStatus = status; - }); - }, - ), - VarTextField( - textController: betreuungC, - localization: AppLocalizations.of(context)!.betreuung, - dbName: "Betreuung", - required: false), - const SizedBox( - height: 20, - ), - VarTextField( - textController: cid, - localization: AppLocalizations.of(context)!.camLink, - dbName: "CID", - required: true), - VarTextField( - textController: ffTypC, - localization: AppLocalizations.of(context)!.fftyp, - dbName: "FFTyp", - required: true), - const SizedBox( - height: 15, - ), - Align( - alignment: Alignment.bottomLeft, - child: Row( - children: [ - Text(AppLocalizations.of(context)!.zeiteinstellung), - const Text( - '*', - style: TextStyle(color: Colors.red), - ) - ], - )), - MEZ( - initialMEZ: selectedMEZ, - onMEZChanged: (mez) { - setState(() { - selectedMEZ = mez; - }); - }, - ), - const SizedBox( - height: 15, - ), - 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), - const SizedBox( - height: 15, + Text(AppLocalizations.of(context)!.status), + const Text( + '*', + style: TextStyle(color: Colors.red), ), ], )), - - // Second step - Step( - title: Text(AppLocalizations.of(context)!.secondstep), - content: Column( + Status( + initialStatus: selectedStatus, + onStatusChanged: (status) { + setState(() { + selectedStatus = status; + }); + }, + ), + VarTextField( + textController: betreuungC, + localization: AppLocalizations.of(context)!.betreuung, + dbName: "Betreuung", + required: false, + dbDesignation: DatabasesEnum.place, + ), + const SizedBox( + height: 20, + ), + VarTextField( + textController: cid, + localization: AppLocalizations.of(context)!.camLink, + dbName: "CID", + required: true, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: ffTypC, + localization: AppLocalizations.of(context)!.fftyp, + dbName: "FFTyp", + required: true, + dbDesignation: DatabasesEnum.place, + ), + const SizedBox( + height: 15, + ), + Align( + alignment: Alignment.bottomLeft, + child: Row( children: [ - Row( - children: [ - Column( - children: [ - Text(currentPosition.latitude.toString()), - Text(currentPosition.longitude.toString()), - ], - ), - const SizedBox( - width: 15, - ), - ElevatedButton( - onPressed: () async { - final result = await Navigator.of(context) - .push( - MaterialPageRoute(builder: (context) { - return Karte( - ortInfoC: ortInfoC, - beiOrtC: beiOrtC, - currentPosition: currentPosition, - onPositionChange: (updatedPosition) { - setState(() { - currentPosition = updatedPosition; - }); - }, - ); - })); - if (result != null) { + Text(AppLocalizations.of(context)!.zeiteinstellung), + const Text( + '*', + style: TextStyle(color: Colors.red), + ) + ], + )), + MEZ( + initialMEZ: selectedMEZ, + onMEZChanged: (mez) { + setState(() { + selectedMEZ = mez; + }); + }, + ), + const SizedBox( + height: 15, + ), + VarTextField( + textController: kSchloNrC, + localization: AppLocalizations.of(context)!.kschlonr, + dbName: "KSchloNr", + required: false, + dbDesignation: DatabasesEnum.place, + ), + const SizedBox( + height: 5, + ), + VarTextField( + textController: rudelC, + localization: AppLocalizations.of(context)!.rudel, + dbName: "Rudel", + required: true, + dbDesignation: DatabasesEnum.place, + ), + const SizedBox( + height: 15, + ), + ], + )), + + // Second step + Step( + title: Text(AppLocalizations.of(context)!.secondstep), + content: Column( + children: [ + Row( + children: [ + Column( + children: [ + Text(currentPosition.latitude.toString()), + Text(currentPosition.longitude.toString()), + ], + ), + const SizedBox( + width: 15, + ), + ElevatedButton( + onPressed: () async { + final result = await Navigator.of(context) + .push( + MaterialPageRoute(builder: (context) { + return Karte( + ortInfoC: ortInfoC, + beiOrtC: beiOrtC, + currentPosition: currentPosition, + onPositionChange: (updatedPosition) { + setState(() { + currentPosition = updatedPosition; + }); + }, + ); + })); + if (result != null) { setState(() { currentPosition = Position( latitude: result.latitude, @@ -641,229 +653,254 @@ class _AddCamMainState extends State { ); }); } - }, - child: Text(AppLocalizations.of(context)!.openMap)), - ], - ), - VarTextField( - textController: bLandC, - localization: AppLocalizations.of(context)!.bland, - dbName: "BLand", - required: true, - defaultValue: "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, - ), - Align( - alignment: Alignment.bottomLeft, - child: Row( - children: [ - Text(AppLocalizations.of(context)!.platzung), - const Text( - '*', - style: TextStyle(color: Colors.red), - ) - ], - )), - Platzung( - initialPlatzung: selectedPlatzung, - onPlatzungChanged: (platzung) { - setState(() { - selectedPlatzung = platzung; - }); - }, - ), + }, + child: Text(AppLocalizations.of(context)!.openMap)), + ], + ), + VarTextField( + textController: bLandC, + localization: AppLocalizations.of(context)!.bland, + dbName: "BLand", + required: true, + dbDesignation: DatabasesEnum.place, + defaultValue: "bLand", + ), + VarTextField( + textController: lkrC, + localization: AppLocalizations.of(context)!.lkr, + dbName: "Lkr", + required: true, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: beiOrtC, + localization: AppLocalizations.of(context)!.beiort, + dbName: "BeiOrt", + required: true, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: ortInfoC, + localization: AppLocalizations.of(context)!.ortinfo, + dbName: "OrtInfo", + required: false, + dbDesignation: DatabasesEnum.place, + ), + const SizedBox( + height: 15, + ), + Align( + alignment: Alignment.bottomLeft, + child: Row( + children: [ + Text(AppLocalizations.of(context)!.platzung), + const Text( + '*', + style: TextStyle(color: Colors.red), + ) ], )), - // Third step - Step( - title: Text(AppLocalizations.of(context)!.thirdstep), - content: Column( + Platzung( + initialPlatzung: selectedPlatzung, + onPlatzungChanged: (platzung) { + setState(() { + selectedPlatzung = platzung; + }); + }, + ), + ], + )), + // Third step + Step( + title: Text(AppLocalizations.of(context)!.thirdstep), + content: Column( + children: [ + Datum( + initDatum: datum, + onDateChanged: (value) { + datum = value; + }, + name: AppLocalizations.of(context)!.pickDate, + ), + KontDat( + initKontDat: kontDat, + onDateChanged: (value) { + setState(() { + kontDat = value; + }); + }, + ), + const SizedBox( + height: 20, + ), + Align( + alignment: Alignment.bottomLeft, + child: Row( children: [ - Datum( - initDatum: datum, - onDateChanged: (value) { - datum = value; - }, - name: AppLocalizations.of(context)!.pickDate, + Text(AppLocalizations.of(context)!.ktage), + const Text( + '*', + style: TextStyle(color: Colors.red), ), - KontDat( - initKontDat: kontDat, - onDateChanged: (value) { - setState(() { - kontDat = value; - }); - }, - ), - const SizedBox( - height: 20, - ), - Align( - alignment: Alignment.bottomLeft, - child: Row( - children: [ - Text(AppLocalizations.of(context)!.ktage), - const Text( - '*', - style: TextStyle(color: Colors.red), - ), - ], - ), - ), - - Row( - children: [ - Expanded( - child: Text( AppLocalizations.of(context)!.ktage1)), - - const SizedBox(width: 15,), - Expanded( - flex: 4, - child: VarTextField(otherDefault: "24", textController: kTage1C, localization: AppLocalizations.of(context)!.ktage1, dbName: "KTage1", required: true)) - ], - ), - - - Row( - children: [ - Expanded( - child: Text( AppLocalizations.of(context)!.ktage2)), - const SizedBox(width: 15,), - Expanded( - flex: 4, - child: VarTextField(otherDefault: "48", textController: kTage2C, localization: AppLocalizations.of(context)!.ktage2, dbName: "KTage2", required: true)) - ], - ), - - const SizedBox( - height: 20, - ), - Row( - children: [ - AbbauDat( - initAbbauDat: abbauDat, - onDateChanged: (value) { - abbauDat = value; - }, - ), - ], - ), - 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), ], - )), - // Fourth step - Step( - title: Text(AppLocalizations.of(context)!.fourthstep), - content: Column( - children: [ - VarTextField( - textController: adresse1C, - localization: AppLocalizations.of(context)!.adresse1, - dbName: "Adresse1", - required: true, - defaultValue: "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), - ], - )) - ]; + ), + ), + + Row( + children: [ + Expanded( + child: Text( AppLocalizations.of(context)!.ktage1)), + + const SizedBox(width: 15,), + Expanded( + flex: 4, + child: VarTextField(otherDefault: "24", textController: kTage1C, localization: AppLocalizations.of(context)!.ktage1, dbName: "KTage1", required: true, dbDesignation: DatabasesEnum.place,)) + ], + ), + + + Row( + children: [ + Expanded( + child: Text( AppLocalizations.of(context)!.ktage2)), + const SizedBox(width: 15,), + Expanded( + flex: 4, + child: VarTextField(otherDefault: "48", textController: kTage2C, localization: AppLocalizations.of(context)!.ktage2, dbName: "KTage2", required: true, dbDesignation: DatabasesEnum.place,)) + ], + ), + + const SizedBox( + height: 20, + ), + Row( + children: [ + AbbauDat( + initAbbauDat: abbauDat, + onDateChanged: (value) { + abbauDat = value; + }, + ), + ], + ), + const SizedBox( + height: 20, + ), + VarTextField( + textController: auftragC, + localization: AppLocalizations.of(context)!.auftrag, + dbName: "Auftrag", + required: false, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: kontAbspC, + localization: AppLocalizations.of(context)!.kontabsp, + dbName: "KontAbsp", + required: false, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: sonstBemC, + localization: + AppLocalizations.of(context)!.sonstbemerkungen, + dbName: "SonstBem", + dbDesignation: DatabasesEnum.place, + required: false), + ], + )), + // Fourth step + Step( + title: Text(AppLocalizations.of(context)!.fourthstep), + content: Column( + children: [ + VarTextField( + textController: adresse1C, + localization: AppLocalizations.of(context)!.adresse1, + dbName: "Adresse1", + dbDesignation: DatabasesEnum.place, + required: true, + defaultValue: "addresse1", + ), + VarTextField( + textController: adresse2C, + localization: AppLocalizations.of(context)!.adresse2, + dbName: "Adresse2", + required: false, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: adresse3C, + localization: AppLocalizations.of(context)!.adresse3, + dbName: "Adresse2", + required: false, + dbDesignation: DatabasesEnum.place, + ), + const SizedBox( + height: 15, + ), + VarTextField( + textController: fKontakt1C, + localization: AppLocalizations.of(context)!.fkontakt1, + dbName: "FKontakt1", + required: false, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: fKontakt2C, + localization: AppLocalizations.of(context)!.fkontakt2, + dbName: "FKontakt2", + required: false, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: fKontakt3C, + localization: AppLocalizations.of(context)!.fkontakt3, + dbName: "FKontakt3", + required: false, + dbDesignation: DatabasesEnum.place, + ), + VarTextField( + textController: intKommC, + localization: AppLocalizations.of(context)!.intkomm, + dbName: "IntKomm", + required: false, + dbDesignation: DatabasesEnum.place, + ), + ], + )) + ]; // Here the site is built with the steps from above return Scaffold( - appBar: AppBar(title: Text(AppLocalizations.of(context)!.addplace)), - body: PageTransitionSwitcher( - duration: const Duration(milliseconds: 800), - transitionBuilder: (Widget child, Animation animation, - Animation secondaryAnimation) { - return SharedAxisTransition( - animation: animation, - secondaryAnimation: secondaryAnimation, - transitionType: SharedAxisTransitionType.vertical, - child: child, - ); - }, - child: Stepper( - key: ValueKey(currentStep), - type: StepperType.vertical, - steps: getSteps(), + appBar: AppBar(title: Text(AppLocalizations.of(context)!.addplace)), + body: PageTransitionSwitcher( + duration: const Duration(milliseconds: 800), + transitionBuilder: (Widget child, Animation animation, + Animation secondaryAnimation) { + return SharedAxisTransition( + animation: animation, + secondaryAnimation: secondaryAnimation, + transitionType: SharedAxisTransitionType.vertical, + child: child, + ); + }, + child: Stepper( + key: ValueKey(currentStep), + type: StepperType.vertical, + steps: getSteps(), - // Functions that handle the navigation through the steps - currentStep: currentStep, - onStepTapped: (value) { - setState(() { - currentStep = value; - }); - }, - onStepContinue: () async { - final isLastStep = currentStep == getSteps().length - 1; + // Functions that handle the navigation through the steps + currentStep: currentStep, + onStepTapped: (value) { + setState(() { + currentStep = value; + }); + }, + onStepContinue: () async { + final isLastStep = currentStep == getSteps().length - 1; - if (!isLastStep) { + if (!isLastStep) { saveTemplate(); setState(() { currentStep += 1; @@ -881,15 +918,15 @@ class _AddCamMainState extends State { await showSaveOptionsDialog(); } } - }, - onStepCancel: () { - if (currentStep == 0) { + }, + onStepCancel: () { + if (currentStep == 0) { Navigator.pop(context); } else { setState(() { currentStep -= 1; }); } - }))); + }))); } } diff --git a/lib/screens/sharedWidgets/var_text_field.dart b/lib/screens/sharedWidgets/var_text_field.dart index 1d6c5bc..a09f553 100644 --- a/lib/screens/sharedWidgets/var_text_field.dart +++ b/lib/screens/sharedWidgets/var_text_field.dart @@ -1,4 +1,6 @@ -import 'package:fforte/methods/db_helper.dart'; +import 'package:fforte/enums/databases.dart'; +import 'package:fforte/methods/excursion_db_helper.dart'; +import 'package:fforte/methods/place_db_helper.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -6,19 +8,21 @@ import 'package:shared_preferences/shared_preferences.dart'; class VarTextField extends StatefulWidget { final TextEditingController textController; final String localization; + final DatabasesEnum dbDesignation; final String dbName; final String? defaultValue; final String? otherDefault; final bool required; const VarTextField( - {super.key, - required this.textController, - required this.localization, - required this.dbName, - required this.required, - this.defaultValue, - this.otherDefault}); + {super.key, + required this.textController, + required this.localization, + required this.dbName, + required this.required, + required this.dbDesignation, + this.defaultValue, + this.otherDefault}); @override State createState() => _VarTextFieldState(); @@ -43,9 +47,15 @@ class _VarTextFieldState extends State { } Future>> _loadData() async { - var places = await DBHelper().getPlace(); - var templates = await DBHelper().getTemplates(); - return [...places, ...templates]; + if (widget.dbDesignation == DatabasesEnum.excursion) { + var entries = await PlaceDBHelper().getPlace(); + var templatesEntries = await PlaceDBHelper().getTemplates(); + return [...entries, ...templatesEntries]; + } else { + var entries = await ExcursionDBHelper().getExcursionen(); + var templatesEntries = await ExcursionDBHelper().getTemplates(); + return [...entries, ...templatesEntries]; + } } void _loadPref() { @@ -63,35 +73,35 @@ class _VarTextFieldState extends State { return Row( children: [ Expanded( - flex: 5, - child: TextField( - controller: widget.textController, - keyboardType: TextInputType.multiline, - maxLines: null, - onChanged: (value) { - setState(() { - widget.textController.text = value; - }); - }, - decoration: InputDecoration( - hintText: widget.localization, - enabledBorder: widget.required - ? (widget.textController.text.isEmpty - ? const UnderlineInputBorder( - borderSide: BorderSide(color: Colors.red)) - : const UnderlineInputBorder( - borderSide: BorderSide(color: Colors.green))) - : const UnderlineInputBorder( - borderSide: BorderSide(color: Colors.grey)), - focusedBorder: widget.required - ? (widget.textController.text.isEmpty - ? const UnderlineInputBorder( - borderSide: BorderSide(color: Colors.red)) - : const UnderlineInputBorder( - borderSide: BorderSide(color: Colors.green))) - : const UnderlineInputBorder( - borderSide: BorderSide(color: Colors.grey))), - )), + flex: 5, + child: TextField( + controller: widget.textController, + keyboardType: TextInputType.multiline, + maxLines: null, + onChanged: (value) { + setState(() { + widget.textController.text = value; + }); + }, + decoration: InputDecoration( + hintText: widget.localization, + enabledBorder: widget.required + ? (widget.textController.text.isEmpty + ? const UnderlineInputBorder( + borderSide: BorderSide(color: Colors.red)) + : const UnderlineInputBorder( + borderSide: BorderSide(color: Colors.green))) + : const UnderlineInputBorder( + borderSide: BorderSide(color: Colors.grey)), + focusedBorder: widget.required + ? (widget.textController.text.isEmpty + ? const UnderlineInputBorder( + borderSide: BorderSide(color: Colors.red)) + : const UnderlineInputBorder( + borderSide: BorderSide(color: Colors.green))) + : const UnderlineInputBorder( + borderSide: BorderSide(color: Colors.grey))), + )), const Expanded( child: SizedBox( width: 15, @@ -102,10 +112,10 @@ class _VarTextFieldState extends State { child: Align( alignment: Alignment.bottomLeft, child: FutureBuilder>>( - future: dbVar, - builder: (BuildContext context, - AsyncSnapshot>> snapshot) { - if (snapshot.hasData) { + future: dbVar, + builder: (BuildContext context, + AsyncSnapshot>> snapshot) { + if (snapshot.hasData) { // Filtern der Daten, um sicherzustellen, dass keine 'null' Werte für den Schlüssel dbName vorhanden sind var filteredData = snapshot.data! .where((item) => @@ -136,8 +146,8 @@ class _VarTextFieldState extends State { } else { return const CircularProgressIndicator(); } - }, - ), + }, + ), ), ) ], diff --git a/lib/screens/viewCam/view_cams.dart b/lib/screens/viewCam/view_cams.dart index 53dc1ff..7ef703d 100644 --- a/lib/screens/viewCam/view_cams.dart +++ b/lib/screens/viewCam/view_cams.dart @@ -1,5 +1,5 @@ import 'package:fforte/screens/addCam/add_cam_main.dart'; -import 'package:fforte/methods/db_helper.dart'; +import 'package:fforte/methods/place_db_helper.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_map/flutter_map.dart'; @@ -24,8 +24,8 @@ class _ViewCamsState extends State { @override void initState() { super.initState(); - place = DBHelper().getPlace(); - templates = DBHelper().getTemplates(); + place = PlaceDBHelper().getPlace(); + templates = PlaceDBHelper().getTemplates(); } // functions to delete all entries LOCALLY @@ -44,10 +44,10 @@ class _ViewCamsState extends State { actions: [ TextButton( onPressed: () { - var placeDB = DBHelper(); + var placeDB = PlaceDBHelper(); placeDB.deleteAllPlaces(); setState(() { - place = DBHelper().getPlace(); + place = PlaceDBHelper().getPlace(); }); Navigator.of(context).pop(); @@ -64,9 +64,9 @@ class _ViewCamsState extends State { } void delSinglePlace(int id) async { - DBHelper().deletePlace(id.toString()); + PlaceDBHelper().deletePlace(id.toString()); setState(() { - place = DBHelper().getPlace(); + place = PlaceDBHelper().getPlace(); }); } @@ -85,10 +85,10 @@ class _ViewCamsState extends State { actions: [ TextButton( onPressed: () { - var placeDB = DBHelper(); + var placeDB = PlaceDBHelper(); placeDB.deleteAllTemplates(); setState(() { - templates = DBHelper().getTemplates(); + templates = PlaceDBHelper().getTemplates(); }); Navigator.of(context).pop(); }, diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index 1ef8427..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:fforte/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}