main #1

Open
fdenzer wants to merge 46 commits from mgl_crew/Mitgliederladen:main into main
5 changed files with 94 additions and 50 deletions
Showing only changes of commit 7388527c43 - Show all commits

View file

@ -3,13 +3,12 @@ import 'package:flutter/services.dart';
import 'sample_data.dart';
class ShowBasket extends StatelessWidget {
final int index;
final Basket basket;
final bool editable;
const ShowBasket(this.index, {this.editable = false, super.key});
const ShowBasket(this.basket, {this.editable = false, super.key});
@override
Widget build(BuildContext context) {
final List<Basket> basket = SampleData().transactions[index].basket!;
return Column(
children: [
Expanded(
@ -24,7 +23,7 @@ class ShowBasket extends StatelessWidget {
'Kosten:',
),
subtitle: Text(
'${SampleData().transactions[index].amount / 100}',
'${basket.price}',
),
trailing: editable
? Row(
@ -47,19 +46,19 @@ class ShowBasket extends StatelessWidget {
);
}
ListView getBasket(List<Basket> basket) {
ListView getBasket(Basket basket) {
return ListView.builder(
itemCount: basket.length,
itemCount: basket.purchases.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
leading: Text(
basket[index].products.category.icon,
basket.purchases.keys.elementAt(index).category.icon,
style: const TextStyle(fontSize: 24),
),
title: Text(basket[index].products.name),
title: Text(basket.purchases.keys.elementAt(index).name),
subtitle: Text(
'${basket[index].amount} ${basket[index].products.unit}'),
'${basket.purchases.values.elementAt(index)} ${basket.purchases.keys.elementAt(index).unit}'),
trailing: editable
? SizedBox(
width: 100,

View file

@ -43,7 +43,9 @@ class Finance extends StatelessWidget {
showBottomSheet(
context: context,
builder: (BuildContext context) {
return ShowBasket(index);
return ShowBasket(SampleData()
.transactions[index]
.basket!);
});
}
: null));
@ -68,8 +70,7 @@ class Finance extends StatelessWidget {
Text getSubtitle(Transaction transaction) {
String text = '${transaction.amount / 100}';
text += '';
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm")
.format(transaction.date);
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm").format(transaction.date);
if (transaction.description != null) {
(text += '\n${transaction.description}');
}
@ -98,7 +99,8 @@ class Finance extends StatelessWidget {
showBottomSheet(
context: context,
builder: (BuildContext context) {
return ShowBasket(index, editable: true);
return ShowBasket(SampleData().transactions[index].basket!,
editable: true);
});
},
);

View file

@ -1,3 +1,5 @@
import 'package:uuid/uuid.dart';
final DateTime now = DateTime.now();
enum TransaktionArt { monatlBeitrag, aufladung, einkauf, korrektur }
@ -15,7 +17,7 @@ class Transaction {
int amount;
TransaktionArt type;
DateTime date;
List<Basket>? basket;
Basket? basket;
String? description;
Transaction(
{required this.type,
@ -28,17 +30,31 @@ class Transaction {
class Product {
final int id = 0;
final String name;
final Unit unit;
final double price; //pro Kilogramm oder Stück
final Unit unit; //pro Kg oder Stück
final double price;
final double vat;
final Category category;
const Product(this.name, this.unit, this.price, this.vat, this.category);
}
class Basket {
Product products;
int amount;
Basket(this.products, this.amount);
Map<Product, int> purchases;
double price;
String guid;
Basket(this.purchases, this.price) : guid = const Uuid().v4();
void addItem(Product product, int quantity) {
if (purchases.containsKey(product)) {
purchases.update(
product, (existingQuantity) => existingQuantity + quantity);
} else {
purchases[product] = quantity;
}
}
void removeItem(Product product) {
purchases.remove(product);
}
}
class SampleData {
@ -63,39 +79,41 @@ class SampleData {
Product('Flaschenpfand', Unit.stueck, -0.15, 0, categories[3])
];
static List<Basket> basket = [
Basket(products[0], 20),
Basket(products[1], 2200),
Basket(products[2], 2),
Basket(products[3], 1),
Basket(products[4], 1),
Basket(products[5], 2),
Basket(products[6], 222),
Basket(products[0], 20),
Basket(products[1], 2200),
Basket(products[2], 2),
Basket(products[3], 1),
Basket(products[4], 1),
Basket(products[5], 2),
Basket(products[6], 222)
];
//such a basket can not exist later. It is for testing purposes
// when scrolling through a long basket
static Basket basket = Basket({
products[0]: 20,
products[1]: 2200,
products[2]: 2,
products[3]: 1,
products[4]: 1,
products[5]: 2,
products[6]: 222,
products[0]: 20,
products[1]: 2200,
products[2]: 2,
products[3]: 1,
products[4]: 1,
products[5]: 2,
products[6]: 222
}, 27.9);
static List<Basket> basket2 = [
Basket(products[0], 22),
Basket(products[1], 2241),
Basket(products[3], 2),
Basket(products[4], 4),
Basket(products[6], 2),
Basket(products[7], 5)
];
static Basket basket2 = Basket({
products[0]: 22,
products[1]: 2241,
products[3]: 2,
products[4]: 4,
products[6]: 2,
products[7]: 5,
}, 34);
static List<Basket> basket3 = [
Basket(products[0], -2),
Basket(products[1], 21),
Basket(products[3], -4),
Basket(products[4], 1),
Basket(products[6], 5)
];
static Basket basket3 = Basket({
products[0]: 2,
products[1]: 21,
products[3]: 4,
products[4]: 1,
products[6]: 5,
}, -1);
List<Transaction> transactions = [
Transaction(

View file

@ -41,6 +41,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.17.1"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.3"
cupertino_icons:
dependency: "direct main"
description:
@ -184,6 +192,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.1"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
uuid:
dependency: "direct main"
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
vector_math:
dependency: transitive
description:

View file

@ -36,6 +36,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
intl: ^0.18.1
uuid: ^3.0.7
dev_dependencies:
flutter_test: