fixed delete in view_app. Also some other things but i forgot everything

This commit is contained in:
Nico
2025-05-12 19:30:33 +02:00
parent ecafe2df02
commit 97691f3453
6 changed files with 120 additions and 71 deletions

View File

@@ -43,16 +43,16 @@ class PlaceDBHelper implements IDb{
@override @override
Future<int> addMainEntry(Map<String, String> place) async { Future<int> addMainEntry(Map<String, String> place) async {
var placeDBClient = await dB; var placeDBClient = await dB;
final existingID = await placeDBClient.query( // final existingID = await placeDBClient.query(
'place', // 'place',
where: 'ID = ?', // where: 'ID = ?',
whereArgs: [place['ID']], // whereArgs: [place['ID']],
); // );
//
if (existingID.isNotEmpty) { // if (existingID.isNotEmpty) {
updateMainEntry(place); // updateMainEntry(place);
return existingID.first['ID'] as int; // Return existing ID // return existingID.first['ID'] as int; // Return existing ID
} // }
int id = await placeDBClient.insert( int id = await placeDBClient.insert(
'place', 'place',

View File

@@ -23,7 +23,6 @@ import 'widgets/status.dart';
class AddCamMain extends StatefulWidget { class AddCamMain extends StatefulWidget {
final bool isTemplate; final bool isTemplate;
final bool isFinished;
final bool isSent; final bool isSent;
final Map<String, dynamic>? existingData; final Map<String, dynamic>? existingData;
@@ -31,7 +30,6 @@ class AddCamMain extends StatefulWidget {
super.key, super.key,
this.isTemplate = false, this.isTemplate = false,
this.existingData, this.existingData,
this.isFinished = false,
this.isSent = false, this.isSent = false,
}); });
@@ -148,6 +146,8 @@ class _AddCamMainState extends State<AddCamMain> {
// select initial werte // select initial werte
rmap["MEZ"]!["controller"]!.text = selectedMEZ; rmap["MEZ"]!["controller"]!.text = selectedMEZ;
rmap["Status"]!["controller"]!.text = selectedStatus; rmap["Status"]!["controller"]!.text = selectedStatus;
rmap["DECLAT"]!["controller"]!.text = currentPosition.latitude.toString();
rmap["DECLNG"]!["controller"]!.text = currentPosition.longitude.toString();
// If a template is edited this fills in the existing values // If a template is edited this fills in the existing values
if (widget.existingData?.isNotEmpty ?? false) { if (widget.existingData?.isNotEmpty ?? false) {
@@ -286,8 +286,8 @@ class _AddCamMainState extends State<AddCamMain> {
children: [ children: [
Column( Column(
children: [ children: [
Text(currentPosition.latitude.toString()), Text(rmap["DECLAT"]!["controller"]!.text),
Text(currentPosition.longitude.toString()), Text(rmap["DECLNG"]!["controller"]!.text),
], ],
), ),
const SizedBox(width: 15), const SizedBox(width: 15),

View File

@@ -4,6 +4,19 @@ import 'package:fforte/methods/excursion_db_helper.dart';
import 'package:fforte/methods/place_db_helper.dart'; import 'package:fforte/methods/place_db_helper.dart';
class DeleteTemplates { class DeleteTemplates {
static void deleteSingle(DatabasesEnum dbType, String id) {
IDb? db;
if (dbType == DatabasesEnum.place) {
db = PlaceDBHelper();
} else if (dbType == DatabasesEnum.excursion) {
db = ExcursionDBHelper();
}
db!.deleteTemplateById(id);
}
static void deleteAll(DatabasesEnum dbType) { static void deleteAll(DatabasesEnum dbType) {
IDb? db; IDb? db;

View File

@@ -19,10 +19,10 @@ class SaveMainEntryMethod {
placeDB = ExcursionDBHelper(); placeDB = ExcursionDBHelper();
} }
int entryId; if (isTemplate) placeDB!.deleteTemplateById(entryData["ID"]!);
// Get the ID of the newly added or updated place int entryId;
if (entryData["ID"] == "") { if (isTemplate || entryData["ID"] == "") {
entryData.remove("ID"); entryData.remove("ID");
entryId = await placeDB!.addMainEntry(entryData); entryId = await placeDB!.addMainEntry(entryData);
} else { } else {

View File

@@ -14,6 +14,9 @@ void saveTemplate(Map<String, String> templateData, DatabasesEnum dbType,
return; return;
} }
templateData.remove("Sent");
templateData.remove("ID");
if (update) { if (update) {
await dbHelper.updateTemplate(templateData); await dbHelper.updateTemplate(templateData);
} else { } else {

View File

@@ -5,6 +5,7 @@ import 'package:fforte/screens/addCam/add_cam_main.dart';
import 'package:fforte/methods/place_db_helper.dart'; import 'package:fforte/methods/place_db_helper.dart';
import 'package:fforte/screens/helper/view_entries_dialog_helper.dart'; import 'package:fforte/screens/helper/view_entries_dialog_helper.dart';
import 'package:fforte/screens/sharedMethods/delete_main_entries.dart'; import 'package:fforte/screens/sharedMethods/delete_main_entries.dart';
import 'package:fforte/screens/sharedMethods/delete_templates.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart'; import 'package:fforte/l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
@@ -25,11 +26,11 @@ class _ViewCamsState extends State<ViewCams> {
late Future<List<Map<String, dynamic>>> mainEntries; late Future<List<Map<String, dynamic>>> mainEntries;
late Future<List<Map<String, dynamic>>> templates; late Future<List<Map<String, dynamic>>> templates;
late List<Marker> markers; late List<Marker> markers;
IDb? db;
// loads the entries // loads the entries
@override @override
void initState() { void initState() {
IDb? db;
super.initState(); super.initState();
if (widget.dbType == DatabasesEnum.place) { if (widget.dbType == DatabasesEnum.place) {
db = PlaceDBHelper(); db = PlaceDBHelper();
@@ -37,8 +38,12 @@ class _ViewCamsState extends State<ViewCams> {
db = ExcursionDBHelper(); db = ExcursionDBHelper();
} }
reloadAllEntries();
}
Future<void> reloadAllEntries() async {
mainEntries = db!.getAllMainEntries(); mainEntries = db!.getAllMainEntries();
templates = db.getAllTemplates(); templates = db!.getAllTemplates();
} }
// The widet tree with taps to differentiate between templates and finished entries // The widet tree with taps to differentiate between templates and finished entries
@@ -89,24 +94,24 @@ class _ViewCamsState extends State<ViewCams> {
children: [ children: [
Row( Row(
children: [ children: [
const SizedBox( const SizedBox(width: 10),
width: 10,
),
Text( Text(
style: const TextStyle( style: const TextStyle(
decoration: TextDecoration.underline), decoration: TextDecoration.underline,
AppLocalizations.of(context)!.placedata), ),
AppLocalizations.of(context)!.placedata,
),
], ],
), ),
Row( Row(
children: [ children: [
Text( Text(
style: const TextStyle( style: const TextStyle(
decoration: TextDecoration.underline), decoration: TextDecoration.underline,
AppLocalizations.of(context)!.sent),
const SizedBox(
width: 10,
), ),
AppLocalizations.of(context)!.sent,
),
const SizedBox(width: 10),
], ],
), ),
], ],
@@ -128,6 +133,9 @@ class _ViewCamsState extends State<ViewCams> {
widget.dbType, widget.dbType,
place['ID'.toString()], place['ID'.toString()],
); );
setState(() {
reloadAllEntries();
});
}, },
backgroundColor: Colors.red, backgroundColor: Colors.red,
foregroundColor: Colors.white, foregroundColor: Colors.white,
@@ -158,7 +166,6 @@ class _ViewCamsState extends State<ViewCams> {
place['Sent'] == 1 place['Sent'] == 1
? true ? true
: false, : false,
isFinished: true,
existingData: place, existingData: place,
), ),
), ),
@@ -203,7 +210,31 @@ class _ViewCamsState extends State<ViewCams> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
Map<String, dynamic> templates = Map<String, dynamic> templates =
snapshot.data![index]; snapshot.data![index];
return ListTile( return Slidable(
startActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (context) {
DeleteTemplates.deleteSingle(
widget.dbType,
templates['ID'].toString(),
);
setState(() {
reloadAllEntries();
});
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
icon: Icons.delete,
label:
AppLocalizations.of(
context,
)!.justdelete,
),
],
),
child: ListTile(
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,
@@ -211,7 +242,6 @@ class _ViewCamsState extends State<ViewCams> {
builder: builder:
(context) => AddCamMain( (context) => AddCamMain(
isTemplate: true, isTemplate: true,
isFinished: false,
existingData: templates, existingData: templates,
), ),
), ),
@@ -221,6 +251,7 @@ class _ViewCamsState extends State<ViewCams> {
subtitle: Text( subtitle: Text(
'ID: ${templates['CID']} DATUM: ${templates['Datum']} RUDEL: ${templates['Rudel']} STATUS: ${templates['Status']}', 'ID: ${templates['CID']} DATUM: ${templates['Datum']} RUDEL: ${templates['Rudel']} STATUS: ${templates['Status']}',
), ),
),
); );
}, },
), ),
@@ -241,6 +272,7 @@ class _ViewCamsState extends State<ViewCams> {
} else if (snapshot.hasError) { } else if (snapshot.hasError) {
return Text("Error ${snapshot.error}"); return Text("Error ${snapshot.error}");
} else { } else {
if (snapshot.data != null) {
markers = markers =
snapshot.data!.map((e) { snapshot.data!.map((e) {
return Marker( return Marker(
@@ -264,6 +296,7 @@ class _ViewCamsState extends State<ViewCams> {
), ),
); );
}).toList(); }).toList();
}
return FlutterMap( return FlutterMap(
options: MapOptions( options: MapOptions(
initialCenter: initialCenter: