fixed a lot of things after i broke everything. Just the card is not implemented again yet

time
This commit is contained in:
Nico
2025-05-12 23:09:28 +02:00
parent 97691f3453
commit 74b4648e73
18 changed files with 599 additions and 479 deletions

View File

@@ -13,51 +13,55 @@ import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:latlong2/latlong.dart';
// * Site that shows all entries in the databases
class ViewCams extends StatefulWidget {
class ViewEntries extends StatefulWidget {
final DatabasesEnum dbType;
const ViewCams({super.key, required this.dbType});
const ViewEntries({super.key, required this.dbType});
@override
State<ViewCams> createState() => _ViewCamsState();
State<ViewEntries> createState() => _ViewEntriesState();
}
class _ViewCamsState extends State<ViewCams> {
class _ViewEntriesState extends State<ViewEntries> {
// var declaration
late Future<List<Map<String, dynamic>>> mainEntries;
late Future<List<Map<String, dynamic>>> templates;
List<Map<String, dynamic>> mainEntries = [];
List<Map<String, dynamic>> templates = [];
late List<Marker> markers;
IDb? db;
// 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();
}
reloadAllEntries();
}
mainEntries = await db!.getAllMainEntries();
templates = await db.getAllTemplates();
Future<void> reloadAllEntries() async {
mainEntries = db!.getAllMainEntries();
templates = db!.getAllTemplates();
setState(() {});
}
// The widet tree with taps to differentiate between templates and finished entries
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
length: 2,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(text: AppLocalizations.of(context)!.completed),
Tab(text: AppLocalizations.of(context)!.uncompleted),
Tab(text: AppLocalizations.of(context)!.map),
// Tab(text: AppLocalizations.of(context)!.map),
],
),
title: Text(AppLocalizations.of(context)!.viewplacesappbar),
@@ -65,264 +69,267 @@ class _ViewCamsState extends State<ViewCams> {
body: TabBarView(
children: [
Tab(
child: FutureBuilder<List<Map<String, dynamic>>>(
future: mainEntries,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
List<Map<String, dynamic>> placeList = List.of(
snapshot.data!,
// child: FutureBuilder<List<Map<String, dynamic>>>(
// future: mainEntries,
// builder: (context, snapshot) {
// if (snapshot.connectionState == ConnectionState.waiting) {
// return const CircularProgressIndicator();
// } else if (snapshot.hasError) {
// return Text('Error: ${snapshot.error}');
// } else {
// List<Map<String, dynamic>> placeList = List.of(
// snapshot.data!,
// );
// return
child: Scaffold(
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.delete),
onPressed: () {
ViewEntriesDialogHelper.deleteAllMainEntries(
context,
widget.dbType,
);
return 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),
Text(
style: const TextStyle(
decoration: TextDecoration.underline,
),
AppLocalizations.of(context)!.placedata,
),
],
),
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: placeList.length,
itemBuilder: (context, index) {
Map<String, dynamic> place =
snapshot.data![index];
return Slidable(
startActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (context) {
DeleteMainEntries.deleteSingle(
widget.dbType,
place['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: ${place['ID']} DATUM: ${place['Datum']}',
),
trailing: Checkbox(
value: place['Sent'] == 0 ? false : true,
onChanged: null,
),
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) => AddCamMain(
isSent:
place['Sent'] == 1
? true
: false,
existingData: place,
),
),
);
},
),
);
},
),
),
],
),
);
}
},
),
),
Tab(
child: FutureBuilder<List<Map<String, dynamic>>>(
future: templates,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.delete),
onPressed: () {
ViewEntriesDialogHelper.deleteAllTemplates(
context,
widget.dbType,
);
},
),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
Map<String, dynamic> templates =
snapshot.data![index];
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: () {
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) => AddCamMain(
isTemplate: true,
existingData: templates,
),
),
);
},
title: Text('Place ${index + 1}'),
subtitle: Text(
'ID: ${templates['CID']} DATUM: ${templates['Datum']} RUDEL: ${templates['Rudel']} STATUS: ${templates['Status']}',
),
),
);
},
),
),
],
),
);
}
},
),
),
Tab(
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,
),
),
},
),
body: Column(
children: [
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TileLayer(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
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,
),
// TODO localization
AppLocalizations.of(context)!.homePageTitle,
),
],
),
Row(
children: [
Text(
style: const TextStyle(
decoration: TextDecoration.underline,
),
AppLocalizations.of(context)!.sent,
),
const SizedBox(width: 10),
],
),
MarkerLayer(markers: markers),
],
);
}
},
),
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: ${mainEntries[index]['Datum']}',
),
trailing: Checkbox(
value: mainEntries[index]['Sent'] == 0 ? false : true,
onChanged: null,
),
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) => AddCamMain(
isSent:
mainEntries[index]['Sent'] == 1
? true
: false,
existingData: mainEntries[index],
),
),
);
},
),
);
},
),
),
],
),
),
// } // REMOVE
// }, // REMOVE
// ), // REMOVE
),
Tab(
// child: FutureBuilder<List<Map<String, dynamic>>>(
// future: templates,
// builder: (context, snapshot) {
// if (snapshot.connectionState == ConnectionState.waiting) {
// return const CircularProgressIndicator();
// } else if (snapshot.hasError) {
// return Text('Error: ${snapshot.error}');
// } else {
// return Scaffold(
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: () {
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']}',
),
),
);
},
),
),
],
),
),
// } // REMOVE
// }, // REMOVE
// ), // REMOVE
),
// Tab(
// 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
// ),
],
),
),