253 lines
10 KiB
Dart
253 lines
10 KiB
Dart
import 'package:fforte/addCam/add_cam_main.dart';
|
|
import 'package:fforte/other/db_helper.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
// * Site that shows all entries in the databases
|
|
|
|
class ViewCams extends StatefulWidget {
|
|
const ViewCams({super.key});
|
|
|
|
@override
|
|
State<ViewCams> createState() => _ViewCamsState();
|
|
}
|
|
|
|
class _ViewCamsState extends State<ViewCams> {
|
|
// var declaration
|
|
late Future<List<Map<String, dynamic>>> place;
|
|
late Future<List<Map<String, dynamic>>> templates;
|
|
|
|
// loads the entries
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
place = DBHelper().getPlace();
|
|
templates = DBHelper().getTemplates();
|
|
}
|
|
|
|
// 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 = DBHelper();
|
|
placeDB.deleteAllPlaces();
|
|
setState(() {
|
|
place = DBHelper().getPlace();
|
|
});
|
|
|
|
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 {
|
|
DBHelper().deletePlace(id.toString());
|
|
setState(() {
|
|
place = DBHelper().getPlace();
|
|
});
|
|
}
|
|
|
|
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 = DBHelper();
|
|
placeDB.deleteAllTemplates();
|
|
setState(() {
|
|
templates = DBHelper().getTemplates();
|
|
});
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text(AppLocalizations.of(context)!.deleteEverything)),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text(AppLocalizations.of(context)!.cancel))
|
|
],
|
|
);
|
|
});
|
|
}
|
|
|
|
// The widet tree with taps to differentiate between templates and finished entries
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DefaultTabController(
|
|
length: 2,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
bottom: TabBar(tabs: [
|
|
Tab(text: AppLocalizations.of(context)!.completed),
|
|
Tab(
|
|
text: AppLocalizations.of(context)!.uncompleted,
|
|
)
|
|
]),
|
|
title: Text(AppLocalizations.of(context)!.viewplacesappbar)),
|
|
body: TabBarView(
|
|
children: [
|
|
FutureBuilder<List<Map<String, dynamic>>>(
|
|
future: place,
|
|
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 Scaffold(
|
|
floatingActionButton: FloatingActionButton(
|
|
child: const Icon(Icons.delete),
|
|
onPressed: () {
|
|
delAllPlaces();
|
|
},
|
|
),
|
|
body: Column(
|
|
children: [
|
|
const SizedBox(
|
|
height: 10,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
AppLocalizations.of(context)!.placedata)),
|
|
Expanded(
|
|
flex: 2,
|
|
child:
|
|
Text(AppLocalizations.of(context)!.sent)),
|
|
],
|
|
),
|
|
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) {
|
|
delSinglePlace(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,
|
|
),
|
|
onTap: () async {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => AddCamMain(
|
|
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']}'),
|
|
);
|
|
}),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
})
|
|
],
|
|
)),
|
|
);
|
|
}
|
|
}
|