begin cleanup of view_cams and begin of making it usable with exursion and place
time refactoring refactoring again
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
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/helper/view_entries_dialog_helper.dart';
|
||||
import 'package:fforte/screens/sharedMethods/delete_main_entries.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
@@ -8,7 +13,8 @@ import 'package:latlong2/latlong.dart';
|
||||
// * Site that shows all entries in the databases
|
||||
|
||||
class ViewCams extends StatefulWidget {
|
||||
const ViewCams({super.key});
|
||||
final DatabasesEnum dbType;
|
||||
const ViewCams({super.key, required this.dbType});
|
||||
|
||||
@override
|
||||
State<ViewCams> createState() => _ViewCamsState();
|
||||
@@ -16,91 +22,23 @@ class ViewCams extends StatefulWidget {
|
||||
|
||||
class _ViewCamsState extends State<ViewCams> {
|
||||
// var declaration
|
||||
late Future<List<Map<String, dynamic>>> place;
|
||||
late Future<List<Map<String, dynamic>>> mainEntries;
|
||||
late Future<List<Map<String, dynamic>>> templates;
|
||||
late List<Marker> markers;
|
||||
|
||||
// loads the entries
|
||||
@override
|
||||
void initState() {
|
||||
IDb? db;
|
||||
super.initState();
|
||||
place = PlaceDBHelper().getAllMainEntries();
|
||||
templates = PlaceDBHelper().getAllTemplates();
|
||||
}
|
||||
if (widget.dbType == DatabasesEnum.place) {
|
||||
db = PlaceDBHelper();
|
||||
} else if (widget.dbType == DatabasesEnum.excursion) {
|
||||
db = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
// functions to delete all entries LOCALLY
|
||||
void delAllPlaces() async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(AppLocalizations.of(context)!.deleteEverything),
|
||||
content: SingleChildScrollView(
|
||||
child: ListBody(children: <Widget>[
|
||||
Text(AppLocalizations.of(context)!.deleteEverythingContent)
|
||||
]),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
var placeDB = PlaceDBHelper();
|
||||
placeDB.deleteAllMainEntries();
|
||||
setState(() {
|
||||
place = PlaceDBHelper().getAllMainEntries();
|
||||
});
|
||||
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.deleteEverything)),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.cancel))
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void delSinglePlace(int id) async {
|
||||
PlaceDBHelper().deleteMainEntryById(id.toString());
|
||||
setState(() {
|
||||
place = PlaceDBHelper().getAllMainEntries();
|
||||
});
|
||||
}
|
||||
|
||||
void delAllTemplates() async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(AppLocalizations.of(context)!.deleteEverything),
|
||||
content: SingleChildScrollView(
|
||||
child: ListBody(children: <Widget>[
|
||||
Text(AppLocalizations.of(context)!.deleteEverythingContent)
|
||||
]),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
var placeDB = PlaceDBHelper();
|
||||
placeDB.deleteAllTemplates();
|
||||
setState(() {
|
||||
templates = PlaceDBHelper().getAllTemplates();
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.deleteEverything)),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.cancel))
|
||||
],
|
||||
);
|
||||
});
|
||||
mainEntries = db!.getAllMainEntries();
|
||||
templates = db.getAllTemplates();
|
||||
}
|
||||
|
||||
// The widet tree with taps to differentiate between templates and finished entries
|
||||
@@ -109,41 +47,43 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
return DefaultTabController(
|
||||
length: 3,
|
||||
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,
|
||||
),
|
||||
]),
|
||||
title: Text(AppLocalizations.of(context)!.viewplacesappbar)),
|
||||
body: TabBarView(
|
||||
children: [
|
||||
FutureBuilder<List<Map<String, dynamic>>>(
|
||||
future: place,
|
||||
appBar: AppBar(
|
||||
bottom: TabBar(
|
||||
tabs: [
|
||||
Tab(text: AppLocalizations.of(context)!.completed),
|
||||
Tab(text: AppLocalizations.of(context)!.uncompleted),
|
||||
Tab(text: AppLocalizations.of(context)!.map),
|
||||
],
|
||||
),
|
||||
title: Text(AppLocalizations.of(context)!.viewplacesappbar),
|
||||
),
|
||||
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!);
|
||||
List<Map<String, dynamic>> placeList = List.of(
|
||||
snapshot.data!,
|
||||
);
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
delAllPlaces();
|
||||
ViewEntriesDialogHelper.deleteAllMainEntries(
|
||||
context,
|
||||
widget.dbType,
|
||||
);
|
||||
},
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -171,119 +111,145 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
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(
|
||||
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) {
|
||||
delSinglePlace(
|
||||
place['ID'.toString()]);
|
||||
DeleteMainEntries.deleteSingle(
|
||||
widget.dbType,
|
||||
place['ID'.toString()],
|
||||
);
|
||||
},
|
||||
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,
|
||||
label:
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
)!.justdelete,
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () async {
|
||||
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,
|
||||
isFinished: true,
|
||||
existingData: place,
|
||||
)));
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
))
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) => AddCamMain(
|
||||
isSent:
|
||||
place['Sent'] == 1
|
||||
? true
|
||||
: false,
|
||||
isFinished: true,
|
||||
existingData: place,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
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: () {
|
||||
delAllTemplates();
|
||||
},
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
Map<String, dynamic> templates =
|
||||
snapshot.data![index];
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
AddCamMain(
|
||||
isTemplate: true,
|
||||
isFinished: false,
|
||||
existingData: templates,
|
||||
)));
|
||||
},
|
||||
title: Text('Place ${index + 1}'),
|
||||
subtitle: Text(
|
||||
'ID: ${templates['CID']} DATUM: ${templates['Datum']} RUDEL: ${templates['Rudel']} STATUS: ${templates['Status']}'),
|
||||
),
|
||||
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 ListTile(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) => AddCamMain(
|
||||
isTemplate: true,
|
||||
isFinished: false,
|
||||
existingData: templates,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}),
|
||||
FutureBuilder(
|
||||
future: place,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const CircularProgressIndicator();
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("Error ${snapshot.error}");
|
||||
} else {
|
||||
markers = snapshot.data!.map((e) {
|
||||
return Marker(
|
||||
},
|
||||
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 {
|
||||
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())),
|
||||
point: LatLng(
|
||||
double.parse(e['DECLAT'].toString()),
|
||||
double.parse(e['DECLNG'].toString()),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(
|
||||
@@ -293,31 +259,40 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
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)
|
||||
]);
|
||||
}
|
||||
})
|
||||
],
|
||||
)),
|
||||
);
|
||||
}).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),
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user