Files
fforte/lib/screens/viewEntries/view_cams.dart
Nico dfbfc8153f fixed saveFile
time

time

this time for real
2025-05-20 22:34:41 +02:00

411 lines
17 KiB
Dart

import 'package:fforte/enums/databases.dart';
import 'package:fforte/interfaces/i_db.dart';
import 'package:fforte/methods/excursion_db_helper.dart';
import 'package:fforte/screens/addCam/add_cam_main.dart';
import 'package:fforte/methods/place_db_helper.dart';
import 'package:fforte/screens/excursion/excursion_main.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_templates.dart';
import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:latlong2/latlong.dart';
// * Site that shows all entries in the databases
class ViewEntries extends StatefulWidget {
final DatabasesEnum dbType;
const ViewEntries({super.key, required this.dbType});
@override
State<ViewEntries> createState() => _ViewEntriesState();
}
class _ViewEntriesState extends State<ViewEntries> {
// var declaration
List<Map<String, dynamic>> mainEntries = [];
List<Map<String, dynamic>> templates = [];
List<Marker> marker = [];
// loads the entries
@override
void initState() {
super.initState();
reloadAllEntries();
}
Future<void> reloadAllEntries() async {
IDb? db;
if (widget.dbType == DatabasesEnum.place) {
db = PlaceDBHelper();
} else if (widget.dbType == DatabasesEnum.excursion) {
db = ExcursionDBHelper();
}
mainEntries = await db!.getAllMainEntries();
templates = await db.getAllTemplates();
if (widget.dbType == DatabasesEnum.place) {
for (var element in mainEntries) {
marker.add(
Marker(
width: 80.0,
height: 80.0,
point: LatLng(
double.parse(element['DECLAT'].toString()),
double.parse(element['DECLNG'].toString()),
),
child: Column(
children: [
const Icon(Icons.location_on, color: Colors.red),
Text(
"ID: ${element['ID'].toString()}",
style: const TextStyle(color: Colors.black),
),
],
),
),
);
}
}
setState(() {});
}
// The widet tree with taps to differentiate between templates and finished entries
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: widget.dbType == DatabasesEnum.place ? 3 : 2,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(text: AppLocalizations.of(context)!.completed),
Tab(text: AppLocalizations.of(context)!.uncompleted),
if (widget.dbType == DatabasesEnum.place)
Tab(text: AppLocalizations.of(context)!.map),
],
),
title: widget.dbType == DatabasesEnum.place ? Text(AppLocalizations.of(context)!.viewplacesappbar) : Text(AppLocalizations.of(context)!.viewExcursionen) ,
),
body: TabBarView(
children: [
Tab(
child: Scaffold(
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.delete),
onPressed: () {
ViewEntriesDialogHelper.deleteAllMainEntries(
context,
widget.dbType,
);
},
),
body: Column(
children: [
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const SizedBox(width: 10),
if (widget.dbType == DatabasesEnum.place)
Text(
style: const TextStyle(
decoration: TextDecoration.underline,
),
AppLocalizations.of(context)!.placedata,
),
if (widget.dbType == DatabasesEnum.excursion)
Text(
style: const TextStyle(
decoration: TextDecoration.underline,
),
AppLocalizations.of(context)!.excursionData,
),
],
),
Row(
children: [
Text(
style: const TextStyle(
decoration: TextDecoration.underline,
),
AppLocalizations.of(context)!.sent,
),
const SizedBox(width: 10),
],
),
],
),
const SizedBox(height: 15),
Expanded(
child: ListView.builder(
itemCount: mainEntries.length,
itemBuilder: (context, index) {
return Slidable(
startActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (context) {
DeleteMainEntries.deleteSingle(
widget.dbType,
mainEntries[index]['ID'.toString()],
);
setState(() {
reloadAllEntries();
});
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
icon: Icons.delete,
label:
AppLocalizations.of(context)!.justdelete,
),
],
),
child: ListTile(
title: Text('Standort ${index + 1}'),
subtitle: Text(
'ID: ${mainEntries[index]['ID']} DATUM: ${widget.dbType == DatabasesEnum.place ? mainEntries[index]['Datum'] : mainEntries[index]["LogDat"]}',
),
trailing: Checkbox(
value:
mainEntries[index]['Sent'] == 0
? false
: true,
onChanged: null,
),
onTap: () async {
if (widget.dbType == DatabasesEnum.place) {
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) => AddCamMain(
isSent:
mainEntries[index]['Sent'] == 1
? true
: false,
existingData: mainEntries[index],
),
),
);
} else if (widget.dbType ==
DatabasesEnum.excursion) {
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) => ExcursionMain(
isSent:
mainEntries[index]['Sent'] == 1
? true
: false,
existingData: mainEntries[index],
),
),
);
}
},
),
);
},
),
),
],
),
),
),
Tab(
child: Scaffold(
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.delete),
onPressed: () {
ViewEntriesDialogHelper.deleteAllTemplates(
context,
widget.dbType,
);
},
),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: templates.length,
itemBuilder: (context, index) {
return Slidable(
startActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (context) {
DeleteTemplates.deleteSingle(
widget.dbType,
templates[index]['ID'].toString(),
);
setState(() {
reloadAllEntries();
});
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
icon: Icons.delete,
label:
AppLocalizations.of(context)!.justdelete,
),
],
),
child: ListTile(
onTap: () {
if (widget.dbType == DatabasesEnum.place) {
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) => AddCamMain(
isTemplate: true,
existingData: templates[index],
),
),
);
} else if (widget.dbType ==
DatabasesEnum.excursion) {
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) => ExcursionMain(
isTemplate: true,
existingData: templates[index],
),
),
);
}
// Navigator.push(
// context,
// MaterialPageRoute(
// builder:
// (context) => AddCamMain(
// isTemplate: true,
// existingData: templates[index],
// ),
// ),
// );
},
title: Text('Place ${index + 1}'),
subtitle: Text(
'ID: ${templates[index]['CID']} DATUM: ${templates[index]['Datum']} RUDEL: ${templates[index]['Rudel']} STATUS: ${templates[index]['Status']}',
),
),
);
},
),
),
],
),
),
),
if (widget.dbType == DatabasesEnum.place)
Tab(
child: FlutterMap(
options: MapOptions(
initialCenter:
marker.isEmpty
? const LatLng(50, 10)
: marker.first.point,
interactionOptions: const InteractionOptions(
flags:
InteractiveFlag.pinchZoom |
InteractiveFlag.drag |
InteractiveFlag.pinchMove,
),
),
children: [
TileLayer(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
),
MarkerLayer(markers: marker),
],
),
// ),
// child: FutureBuilder(
// future: mainEntries,
// builder: (context, snapshot) {
// if (snapshot.connectionState == ConnectionState.waiting) {
// return const CircularProgressIndicator();
// } else if (snapshot.hasError) {
// return Text("Error ${snapshot.error}");
// } else {
// if (snapshot.data != null) {
// markers =
// snapshot.data!.map((e) {
// return Marker(
// width: 80.0,
// height: 80.0,
// point: LatLng(
// double.parse(e['DECLAT'].toString()),
// double.parse(e['DECLNG'].toString()),
// ),
// child: Column(
// children: [
// const Icon(
// Icons.location_on,
// color: Colors.red,
// ),
// Text(
// "ID: ${e['ID'].toString()}",
// style: const TextStyle(color: Colors.black),
// ),
// ],
// ),
// );
// }).toList();
// }
// return FlutterMap(
// options: MapOptions(
// initialCenter:
// markers.isEmpty
// ? const LatLng(50, 10)
// : markers.first.point,
// interactionOptions: const InteractionOptions(
// flags:
// InteractiveFlag.pinchZoom |
// InteractiveFlag.drag |
// InteractiveFlag.pinchMove,
// ),
// ),
// children: [
// TileLayer(
// urlTemplate:
// 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
// userAgentPackageName: 'com.example.app',
// ),
// MarkerLayer(markers: markers),
// ],
// );
// } // REMOVE
// }, // REMOVE
// ), // REMOVE
),
],
),
),
);
}
}