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`: Clone this repository to your local machine using Git or directly from `Android Studio`:
```bash ```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. Alternatively, open the repository URL in `Android Studio` to clone it directly.

View File

@ -10,6 +10,7 @@ class AppWriteTankModel {
String? imageFileName; String? imageFileName;
String? imageFileUrl; String? imageFileUrl;
int? mnIndexCount; int? mnIndexCount;
String? szSummePreis;
AppWriteTankModel({ AppWriteTankModel({
required this.documentId, required this.documentId,
@ -22,7 +23,9 @@ class AppWriteTankModel {
this.imageFileId, this.imageFileId,
this.imageFileName, this.imageFileName,
this.imageFileUrl, 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) { factory AppWriteTankModel.fromMap(Map<String, dynamic> map) {
return AppWriteTankModel( return AppWriteTankModel(

View File

@ -12,10 +12,14 @@ import '../login/login_view.dart';
class TanklistController extends GetxController { class TanklistController extends GetxController {
final _dataBox = GetStorage('MyUserStorage'); final _dataBox = GetStorage('MyUserStorage');
final isloadingList = false.obs; final isloadingList = false.obs;
final tankList = <AppWriteTankModel>[].obs; final rxTankListAlles = <AppWriteTankModel>[].obs;
final rxTankListActualYear = <AppWriteTankModel>[].obs;
final szRxUserId = 'NoUser'.obs; final szRxUserId = 'NoUser'.obs;
//AppWrite API-REST get Data //AppWrite API-REST get Data
final AppwriteRepository _authRepository = AppwriteRepository(); final AppwriteRepository _authRepository = AppwriteRepository();
final szRxYear = DateTime.now().year.obs.toString().obs;
final szRxSummeYearLiter = '0.0'.obs;
final szRxSummePrice = '0.0'.obs;
@override @override
void onInit() { void onInit() {
@ -45,16 +49,32 @@ class TanklistController extends GetxController {
message = 'Leere Liste keine Daten vorhanden'; message = 'Leere Liste keine Daten vorhanden';
return; return;
} }
tankList.clear(); rxTankListAlles.clear();
var data = tankListData.toMap(); var data = tankListData.toMap();
List d = data['documents'].toList(); List d = data['documents'].toList();
tankList.value = rxTankListAlles.value =
d.map((e) => AppWriteTankModel.fromMap(e['data'])).toList(); 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 dateA = DateTime.parse(a.date);
final DateTime dateB = DateTime.parse(b.date); final DateTime dateB = DateTime.parse(b.date);
return dateB.compareTo(dateA); 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'; message = 'Liste wurde erfolgreich geladen';
}).catchError((error) { }).catchError((error) {
isErrorByLoading = true; isErrorByLoading = true;

View File

@ -15,6 +15,7 @@ class TanklistPage extends GetView<TanklistController> {
child: SafeArea( child: SafeArea(
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
shadowColor: Colors.grey,
title: Text('Tankstops'), title: Text('Tankstops'),
centerTitle: true, centerTitle: true,
//backgroundColor: Colors.grey.shade600, //backgroundColor: Colors.grey.shade600,
@ -51,38 +52,69 @@ class TanklistPage extends GetView<TanklistController> {
body: Obx(() => tankListCtrl.isloadingList.value == false body: Obx(() => tankListCtrl.isloadingList.value == false
? Padding( ? Padding(
padding: EdgeInsetsGeometry.only(left: 25, right: 25), padding: EdgeInsetsGeometry.only(left: 25, right: 25),
child: ListView.builder( child: Column(
padding: EdgeInsets.only(top: 8, bottom: 8), children: [
physics: const BouncingScrollPhysics(), SizedBox(
itemBuilder: ((BuildContext context, int index) { child: Column(
var item = tankListCtrl.tankList[index]; children: [
return Column( Text(tankListCtrl.szRxYear.value, style: TextStyle(fontSize: 25, color: Colors.orange)),
children: [ Row(
Container( mainAxisAlignment: MainAxisAlignment.spaceAround,
decoration: BoxDecoration( children: [
boxShadow: [ Column(
BoxShadow( children: [
color: Colors.blue.withValues( Text('Jahresverbrauch', style: TextStyle(fontSize: 14)),
alpha: 0.35, Text( tankListCtrl.szRxSummeYearLiter.value, style: TextStyle(fontSize: 20, color: Colors.orange)),
), // Die Farbe des Schattens ],
spreadRadius: ),
1, // Wie weit sich der Schatten ausbreitet Column(
blurRadius: children: [
1, // Wie stark der Schatten verschwommen ist Text('Jahressumme', style: TextStyle(fontSize: 14)),
offset: const Offset( Text(tankListCtrl.szRxSummePrice.value, style: TextStyle(fontSize: 20, color: Colors.orange)),
0, ],
3,
), // Der Versatz des Schattens (x, y)
), ),
], ],
), ),
child: MyListTileItem(listItem: item), ],
), ),
SizedBox(height: 15), ),
], Divider(color: Colors.grey.shade200, height: 0.0,),
); Expanded(
}), child: ListView.builder(
itemCount: tankListCtrl.tankList.length, padding: EdgeInsets.only(top: 8, bottom: 8),
physics: const BouncingScrollPhysics(),
itemBuilder: ((BuildContext context, int index) {
var item = tankListCtrl.rxTankListActualYear[index];
return Column(
children: [
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.blue.withValues(
alpha: 0.35,
), // Die Farbe des Schattens
spreadRadius:
1, // Wie weit sich der Schatten ausbreitet
blurRadius:
1, // Wie stark der Schatten verschwommen ist
offset: const Offset(
0,
3,
), // Der Versatz des Schattens (x, y)
),
],
),
child: MyListTileItem(listItem: item),
),
SizedBox(height: 15),
],
);
}),
itemCount: tankListCtrl.rxTankListActualYear.length,
),
),
],
), ),
) )
: Center( : Center(

View File

@ -15,9 +15,6 @@ class MyListTileItem extends StatelessWidget {
Widget _myListItem(BuildContext context) { Widget _myListItem(BuildContext context) {
var textColor = Colors.orange.shade400; var textColor = Colors.orange.shade400;
var summePrice =
(double.parse(listItem.liters) * double.parse(listItem.pricePerLiter))
.toStringAsFixed(2);
return Padding( return Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Column( child: Column(
@ -75,7 +72,7 @@ class MyListTileItem extends StatelessWidget {
children: [ children: [
Icon(Icons.price_change), Icon(Icons.price_change),
SizedBox(width: 10), 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), 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/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
import './extensions/http_overrides.dart'; import './extensions/http_overrides.dart';
/// A utility class for initializing the Flutter application. /// A utility class for initializing the Flutter application.