add edit and delete
This commit is contained in:
@@ -36,7 +36,7 @@ class TanklistController extends GetxController {
|
||||
@override
|
||||
void onClose() {}
|
||||
|
||||
void getTankList() async {
|
||||
Future<void> getTankList() async {
|
||||
isloadingList(true);
|
||||
bool isErrorByLoading = false;
|
||||
String message = '';
|
||||
@@ -45,8 +45,14 @@ class TanklistController extends GetxController {
|
||||
.listTankStops(szRxUserId.value)
|
||||
.then((tankListData) {
|
||||
if (tankListData.documents.isEmpty) {
|
||||
isErrorByLoading = true;
|
||||
isErrorByLoading = false;
|
||||
message = 'Leere Liste keine Daten vorhanden';
|
||||
isloadingList(false);
|
||||
rxTankListAlles.clear();
|
||||
rxTankListActualYear.clear();
|
||||
szRxSummeYearLiter('0.0');
|
||||
szRxSummePrice('0.0');
|
||||
update();
|
||||
return;
|
||||
}
|
||||
rxTankListAlles.clear();
|
||||
@@ -64,6 +70,7 @@ class TanklistController extends GetxController {
|
||||
rxTankListActualYear.value = rxTankListAlles
|
||||
.where((tank) => tank.date.startsWith(szRxYear.value))
|
||||
.toList();
|
||||
// rxTankListActualYear.value = rxTankListAlles;
|
||||
//Summe Liter aktuelles Jahr*********
|
||||
szRxSummeYearLiter(
|
||||
rxTankListActualYear.fold<double>(0.0, (previousValue, element) {
|
||||
@@ -72,10 +79,11 @@ class TanklistController extends GetxController {
|
||||
//Summe Preis aktuelles Jahr*********
|
||||
szRxSummePrice(
|
||||
rxTankListActualYear.fold<double>(0.0, (previousValue, element) {
|
||||
return previousValue + (double.tryParse(element.szSummePreis!) ?? 0.0);
|
||||
return previousValue +
|
||||
(double.tryParse(element.szSummePreis!) ?? 0.0);
|
||||
}).toStringAsFixed(2));
|
||||
|
||||
message = 'Liste wurde erfolgreich geladen';
|
||||
isErrorByLoading = false;
|
||||
}).catchError((error) {
|
||||
isErrorByLoading = true;
|
||||
if (error is AppwriteException) {
|
||||
@@ -94,21 +102,20 @@ class TanklistController extends GetxController {
|
||||
}
|
||||
}
|
||||
String title = isErrorByLoading ? 'Fehler' : 'Erfolg';
|
||||
Get.snackbar(
|
||||
title,
|
||||
message,
|
||||
backgroundColor: isErrorByLoading ? Colors.red : Colors.green,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
duration: const Duration(seconds: 4),
|
||||
);
|
||||
print('$title: $message');
|
||||
update();
|
||||
}
|
||||
|
||||
void goToUpdatePage() {
|
||||
void goToUpdatePage(AppWriteTankModel item) {
|
||||
var map = item.toMap();
|
||||
print('Go to Update Page with data: $map');
|
||||
// Go to Update Page
|
||||
Get.offAndToNamed(TankPage.namedRoute,
|
||||
arguments: {'from': 'Update', 'data': map});
|
||||
}
|
||||
|
||||
void goToInputPage() {
|
||||
Get.offAndToNamed(TankPage.namedRoute);
|
||||
Get.offAndToNamed(TankPage.namedRoute, arguments: {'from': 'Input'});
|
||||
}
|
||||
|
||||
void logoutSessionAndGoToLoginPage() async {
|
||||
@@ -127,4 +134,30 @@ class TanklistController extends GetxController {
|
||||
void goToChartView() {
|
||||
Get.offAndToNamed(GraphPage.namedRoute);
|
||||
}
|
||||
|
||||
void deleteTankStop(String documentId) async {
|
||||
bool isErrorByLoading = false;
|
||||
String message = '';
|
||||
try {
|
||||
await _authRepository.deleteTankStop(documentId).then((response) async {
|
||||
await getTankList();
|
||||
message = 'Tankstopp wurde erfolgreich gelöscht';
|
||||
}).catchError((error) {
|
||||
isErrorByLoading = true;
|
||||
if (error is AppwriteException) {
|
||||
message = error.message!;
|
||||
} else {
|
||||
message = 'Uuups da ist was schief gelaufen';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
isErrorByLoading = true;
|
||||
message = 'Fehler beim Löschen des Tankstopps';
|
||||
print('Error deleting tank stop: $e');
|
||||
}
|
||||
String title = isErrorByLoading ? 'Fehler' : 'Erfolg';
|
||||
print('$title: $message');
|
||||
}
|
||||
|
||||
void goToGasView() {}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,13 @@ class TanklistPage extends GetView<TanklistController> {
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.add_chart, color: Colors.grey.shade300),
|
||||
onPressed: () async {
|
||||
// Handle go to Chart View
|
||||
tankListCtrl.goToGasView();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.local_gas_station_sharp, color: Colors.grey.shade300),
|
||||
onPressed: () async {
|
||||
// Handle go to Chart View
|
||||
tankListCtrl.goToChartView();
|
||||
@@ -57,20 +64,30 @@ class TanklistPage extends GetView<TanklistController> {
|
||||
SizedBox(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(tankListCtrl.szRxYear.value, style: TextStyle(fontSize: 25, color: Colors.orange)),
|
||||
Text(tankListCtrl.szRxYear.value,
|
||||
style: TextStyle(
|
||||
fontSize: 25, color: Colors.orange)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Text('Jahresverbrauch', style: TextStyle(fontSize: 14)),
|
||||
Text( tankListCtrl.szRxSummeYearLiter.value, style: TextStyle(fontSize: 20, color: Colors.orange)),
|
||||
Text('Jahresverbrauch',
|
||||
style: TextStyle(fontSize: 14)),
|
||||
Text(tankListCtrl.szRxSummeYearLiter.value,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: Colors.orange)),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Text('Jahressumme', style: TextStyle(fontSize: 14)),
|
||||
Text(tankListCtrl.szRxSummePrice.value, style: TextStyle(fontSize: 20, color: Colors.orange)),
|
||||
Text('Jahressumme',
|
||||
style: TextStyle(fontSize: 14)),
|
||||
Text(tankListCtrl.szRxSummePrice.value,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: Colors.orange)),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -78,9 +95,12 @@ class TanklistPage extends GetView<TanklistController> {
|
||||
],
|
||||
),
|
||||
),
|
||||
Divider(color: Colors.grey.shade200, height: 0.0,),
|
||||
Divider(
|
||||
color: Colors.grey.shade200,
|
||||
height: 0.0,
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
child: tankListCtrl.rxTankListActualYear.isNotEmpty ? ListView.builder(
|
||||
padding: EdgeInsets.only(top: 8, bottom: 8),
|
||||
physics: const BouncingScrollPhysics(),
|
||||
itemBuilder: ((BuildContext context, int index) {
|
||||
@@ -105,14 +125,27 @@ class TanklistPage extends GetView<TanklistController> {
|
||||
),
|
||||
],
|
||||
),
|
||||
child: MyListTileItem(listItem: item),
|
||||
child: MyListTileItem(
|
||||
listItem: item,
|
||||
onPressedEdit: () {
|
||||
tankListCtrl.goToUpdatePage(item);
|
||||
},
|
||||
onPressedDelete: () {
|
||||
tankListCtrl.deleteTankStop(item.documentId);
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
],
|
||||
);
|
||||
}),
|
||||
itemCount: tankListCtrl.rxTankListActualYear.length,
|
||||
),
|
||||
):Expanded(child: Center(
|
||||
child: Text('Keine Einträge für das aktuelle Jahr vorhanden',
|
||||
style: TextStyle(
|
||||
fontSize: 18, color: Colors.grey.shade600)),
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../data/models/tank_model.dart';
|
||||
|
||||
|
||||
class MyListTileItem extends StatelessWidget {
|
||||
const MyListTileItem({super.key, required this.listItem});
|
||||
const MyListTileItem(
|
||||
{super.key, required this.listItem, required this.onPressedEdit, required this.onPressedDelete});
|
||||
|
||||
final AppWriteTankModel listItem;
|
||||
final void Function()? onPressedEdit;
|
||||
final void Function()? onPressedDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -72,7 +74,8 @@ class MyListTileItem extends StatelessWidget {
|
||||
children: [
|
||||
Icon(Icons.price_change),
|
||||
SizedBox(width: 10),
|
||||
Text('${listItem.szSummePreis} €', style: TextStyle(color: textColor, fontSize: 25)),
|
||||
Text('${listItem.szSummePreis} €',
|
||||
style: TextStyle(color: textColor, fontSize: 25)),
|
||||
],
|
||||
),
|
||||
Divider(thickness: 1, color: Colors.black),
|
||||
@@ -89,6 +92,38 @@ class MyListTileItem extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
Divider(thickness: 1, color: Colors.black),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
onPressed: onPressedEdit,
|
||||
label: Text(
|
||||
'Edit',
|
||||
style: TextStyle(color: Colors.grey.shade200),
|
||||
),
|
||||
icon: const Icon(Icons.edit),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color.fromARGB(255, 3, 71, 128),
|
||||
foregroundColor: Colors.grey.shade200,
|
||||
shadowColor: Colors.white,
|
||||
),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: onPressedDelete,
|
||||
label: Text(
|
||||
'Delete',
|
||||
style: TextStyle(color: Colors.grey.shade200),
|
||||
),
|
||||
icon: const Icon(Icons.delete),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color.fromARGB(255, 128, 3, 45),
|
||||
foregroundColor: Colors.grey.shade200,
|
||||
shadowColor: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user