add ListView Summs Liter Price per Year

This commit is contained in:
atseirjo 2025-08-25 14:22:10 +02:00
parent c183d84a86
commit 085a7648f3
6 changed files with 92 additions and 39 deletions

View File

@ -14,7 +14,7 @@ This guide will help you quickly set up, customize, and build your Flutter app.
Clone this repository to your local machine using Git or directly from `Android Studio`:
```bash
git clone https://github.com/appwrite/starter-for-flutter
git clone https://gitea.joshihomeserver.ipv64.net/josiadmin/MyNewAppWriteTankApp.git
```
Alternatively, open the repository URL in `Android Studio` to clone it directly.

View File

@ -10,6 +10,7 @@ class AppWriteTankModel {
String? imageFileName;
String? imageFileUrl;
int? mnIndexCount;
String? szSummePreis;
AppWriteTankModel({
required this.documentId,
@ -22,7 +23,9 @@ class AppWriteTankModel {
this.imageFileId,
this.imageFileName,
this.imageFileUrl,
});
}):szSummePreis = (double.tryParse(liters) != null && double.tryParse(pricePerLiter) != null)
? (double.parse(liters) * double.parse(pricePerLiter)).toStringAsFixed(2)
: null;
factory AppWriteTankModel.fromMap(Map<String, dynamic> map) {
return AppWriteTankModel(

View File

@ -12,10 +12,14 @@ import '../login/login_view.dart';
class TanklistController extends GetxController {
final _dataBox = GetStorage('MyUserStorage');
final isloadingList = false.obs;
final tankList = <AppWriteTankModel>[].obs;
final rxTankListAlles = <AppWriteTankModel>[].obs;
final rxTankListActualYear = <AppWriteTankModel>[].obs;
final szRxUserId = 'NoUser'.obs;
//AppWrite API-REST get Data
final AppwriteRepository _authRepository = AppwriteRepository();
final szRxYear = DateTime.now().year.obs.toString().obs;
final szRxSummeYearLiter = '0.0'.obs;
final szRxSummePrice = '0.0'.obs;
@override
void onInit() {
@ -45,16 +49,32 @@ class TanklistController extends GetxController {
message = 'Leere Liste keine Daten vorhanden';
return;
}
tankList.clear();
rxTankListAlles.clear();
var data = tankListData.toMap();
List d = data['documents'].toList();
tankList.value =
rxTankListAlles.value =
d.map((e) => AppWriteTankModel.fromMap(e['data'])).toList();
tankList.sort((a, b) {
rxTankListAlles.sort((a, b) {
final DateTime dateA = DateTime.parse(a.date);
final DateTime dateB = DateTime.parse(b.date);
return dateB.compareTo(dateA);
});
//Tank List per Actual year**********
rxTankListActualYear.clear();
rxTankListActualYear.value = rxTankListAlles
.where((tank) => tank.date.startsWith(szRxYear.value))
.toList();
//Summe Liter aktuelles Jahr*********
szRxSummeYearLiter(
rxTankListActualYear.fold<double>(0.0, (previousValue, element) {
return previousValue + (double.tryParse(element.liters) ?? 0.0);
}).toStringAsFixed(2));
//Summe Preis aktuelles Jahr*********
szRxSummePrice(
rxTankListActualYear.fold<double>(0.0, (previousValue, element) {
return previousValue + (double.tryParse(element.szSummePreis!) ?? 0.0);
}).toStringAsFixed(2));
message = 'Liste wurde erfolgreich geladen';
}).catchError((error) {
isErrorByLoading = true;

View File

@ -15,6 +15,7 @@ class TanklistPage extends GetView<TanklistController> {
child: SafeArea(
child: Scaffold(
appBar: AppBar(
shadowColor: Colors.grey,
title: Text('Tankstops'),
centerTitle: true,
//backgroundColor: Colors.grey.shade600,
@ -51,11 +52,39 @@ class TanklistPage extends GetView<TanklistController> {
body: Obx(() => tankListCtrl.isloadingList.value == false
? Padding(
padding: EdgeInsetsGeometry.only(left: 25, right: 25),
child: Column(
children: [
SizedBox(
child: Column(
children: [
Text(tankListCtrl.szRxYear.value, style: TextStyle(fontSize: 25, color: Colors.orange)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
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)),
],
),
],
),
],
),
),
Divider(color: Colors.grey.shade200, height: 0.0,),
Expanded(
child: ListView.builder(
padding: EdgeInsets.only(top: 8, bottom: 8),
physics: const BouncingScrollPhysics(),
itemBuilder: ((BuildContext context, int index) {
var item = tankListCtrl.tankList[index];
var item = tankListCtrl.rxTankListActualYear[index];
return Column(
children: [
Container(
@ -82,7 +111,10 @@ class TanklistPage extends GetView<TanklistController> {
],
);
}),
itemCount: tankListCtrl.tankList.length,
itemCount: tankListCtrl.rxTankListActualYear.length,
),
),
],
),
)
: Center(

View File

@ -15,9 +15,6 @@ class MyListTileItem extends StatelessWidget {
Widget _myListItem(BuildContext context) {
var textColor = Colors.orange.shade400;
var summePrice =
(double.parse(listItem.liters) * double.parse(listItem.pricePerLiter))
.toStringAsFixed(2);
return Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
@ -75,7 +72,7 @@ class MyListTileItem extends StatelessWidget {
children: [
Icon(Icons.price_change),
SizedBox(width: 10),
Text('$summePrice', style: TextStyle(color: textColor, fontSize: 25)),
Text('${listItem.szSummePreis}', style: TextStyle(color: textColor, fontSize: 25)),
],
),
Divider(thickness: 1, color: Colors.black),

View File

@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:window_manager/window_manager.dart';
import './extensions/http_overrides.dart';
/// A utility class for initializing the Flutter application.