forked from mgl_crew/Mitgliederladen
product categories and other improvements
This commit is contained in:
parent
000f141b5a
commit
df255d71b8
5 changed files with 80 additions and 116 deletions
|
@ -2,11 +2,6 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'sample_data.dart';
|
import 'sample_data.dart';
|
||||||
|
|
||||||
/* todo:
|
|
||||||
- individuelle Icons je nach Kategorie
|
|
||||||
- editing
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ShowBasket extends StatelessWidget {
|
class ShowBasket extends StatelessWidget {
|
||||||
final int index;
|
final int index;
|
||||||
final bool editable;
|
final bool editable;
|
||||||
|
@ -37,7 +32,7 @@ class ShowBasket extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
backgroundColor: Colors.redAccent.shade100,
|
backgroundColor: Colors.redAccent.shade100,
|
||||||
child: const Icon(Icons.delete),
|
child: const Icon(Icons.remove_shopping_cart),
|
||||||
onPressed: () {}),
|
onPressed: () {}),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 10,
|
width: 10,
|
||||||
|
@ -54,12 +49,14 @@ class ShowBasket extends StatelessWidget {
|
||||||
|
|
||||||
ListView getBasket(List<Basket> basket) {
|
ListView getBasket(List<Basket> basket) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: null,
|
itemCount: basket.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index < basket.length) {
|
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: getLeading(basket[index].products.category),
|
leading: Text(
|
||||||
|
basket[index].products.category.icon,
|
||||||
|
style: const TextStyle(fontSize: 24),
|
||||||
|
),
|
||||||
title: Text(basket[index].products.name),
|
title: Text(basket[index].products.name),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${basket[index].amount} ${basket[index].products.unit}'),
|
'${basket[index].amount} ${basket[index].products.unit}'),
|
||||||
|
@ -74,30 +71,7 @@ class ShowBasket extends StatelessWidget {
|
||||||
)
|
)
|
||||||
: null),
|
: null),
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getLeading(Category category) {
|
|
||||||
switch (category) {
|
|
||||||
case Category.obstUndGemuese:
|
|
||||||
return const Text("🍒");
|
|
||||||
case Category.brotCerealienUndAufstriche:
|
|
||||||
return const Text(
|
|
||||||
'🍞',
|
|
||||||
style: TextStyle(fontSize: 24),
|
|
||||||
);
|
|
||||||
case Category.drogerieUndHaushalt:
|
|
||||||
case Category.getraenke:
|
|
||||||
case Category.kochenUndBacken:
|
|
||||||
case Category.pfand:
|
|
||||||
case Category.suessesUndKnabbereien:
|
|
||||||
case Category.oeleSossenUndGewuerze:
|
|
||||||
default:
|
|
||||||
return const Icon(Icons.error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'sample_data.dart';
|
||||||
/*
|
/*
|
||||||
todo:
|
todo:
|
||||||
- Einkauf und Settings
|
- Einkauf und Settings
|
||||||
|
- edit + Zeitspanne
|
||||||
- farbliche Hervorhebungen
|
- farbliche Hervorhebungen
|
||||||
- semanticLabels, Screenreader
|
- semanticLabels, Screenreader
|
||||||
- monatliche Aufladung: ausstehende Beträge
|
- monatliche Aufladung: ausstehende Beträge
|
||||||
|
@ -37,14 +38,13 @@ class Finance extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: ListView.builder(
|
||||||
itemCount: null,
|
itemCount: SampleData().transactions.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index < SampleData().transactions.length) {
|
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: getIcon(SampleData().transactions[index].type),
|
leading: getIcon(SampleData().transactions[index].type),
|
||||||
title: Text(
|
title:
|
||||||
gettitle(SampleData().transactions[index].type)),
|
Text(gettitle(SampleData().transactions[index].type)),
|
||||||
subtitle: getSubtitle(SampleData().transactions[index]),
|
subtitle: getSubtitle(SampleData().transactions[index]),
|
||||||
trailing: getTrailing(context, index),
|
trailing: getTrailing(context, index),
|
||||||
onTap: (SampleData().transactions[index].basket != null)
|
onTap: (SampleData().transactions[index].basket != null)
|
||||||
|
@ -56,9 +56,6 @@ class Finance extends StatelessWidget {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
: null));
|
: null));
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,30 +101,15 @@ class Finance extends StatelessWidget {
|
||||||
|
|
||||||
getTrailing(BuildContext context, int index) {
|
getTrailing(BuildContext context, int index) {
|
||||||
if (SampleData().transactions[index].type == TransaktionArt.einkauf) {
|
if (SampleData().transactions[index].type == TransaktionArt.einkauf) {
|
||||||
return PopupMenuButton(
|
return IconButton(
|
||||||
onSelected: (value) {
|
icon: const Icon(Icons.manage_history),
|
||||||
if (value == 'edit') {
|
onPressed: () {
|
||||||
showBottomSheet(
|
showBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return ShowBasket(index, editable: true);
|
return ShowBasket(index, editable: true);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
|
||||||
const PopupMenuItem<String>(
|
|
||||||
value: 'edit',
|
|
||||||
child: ListTile(
|
|
||||||
leading: Icon(Icons.manage_history),
|
|
||||||
title: Text('Warenkorb bearbeiten')),
|
|
||||||
),
|
|
||||||
const PopupMenuItem<String>(
|
|
||||||
value: 'delete',
|
|
||||||
child: ListTile(
|
|
||||||
leading: Icon(Icons.remove_shopping_cart),
|
|
||||||
title: Text('Einkauf stornieren')),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -79,7 +79,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: <Widget>[
|
body: <Widget>[
|
||||||
Shopping(),
|
//Shopping(),
|
||||||
|
const Shopping(),
|
||||||
const Finance(),
|
const Finance(),
|
||||||
ListView(children: const <Widget>[
|
ListView(children: const <Widget>[
|
||||||
ListTile(
|
ListTile(
|
||||||
|
|
|
@ -4,15 +4,10 @@ enum TransaktionArt { monatlBeitrag, aufladung, einkauf, korrektur }
|
||||||
|
|
||||||
enum Unit { stueck, menge }
|
enum Unit { stueck, menge }
|
||||||
|
|
||||||
enum Category {
|
class Category {
|
||||||
obstUndGemuese,
|
final String name;
|
||||||
brotCerealienUndAufstriche,
|
final String icon;
|
||||||
getraenke,
|
const Category({required this.name, required this.icon});
|
||||||
drogerieUndHaushalt,
|
|
||||||
kochenUndBacken,
|
|
||||||
oeleSossenUndGewuerze,
|
|
||||||
suessesUndKnabbereien,
|
|
||||||
pfand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Transaction {
|
class Transaction {
|
||||||
|
@ -47,15 +42,25 @@ class Basket {
|
||||||
}
|
}
|
||||||
|
|
||||||
class SampleData {
|
class SampleData {
|
||||||
static const List<Product> products = [
|
static const List<Category> categories = [
|
||||||
Product('Apfel', Unit.stueck, 0.23, 7, Category.obstUndGemuese),
|
Category(name: 'Obst und Gemüse', icon: '🍒'),
|
||||||
Product('Mehl', Unit.menge, 0.003, 19, Category.kochenUndBacken),
|
Category(name: 'Kochen und Backen', icon: '🍝'),
|
||||||
Product('Brot', Unit.stueck, 1.23, 7, Category.brotCerealienUndAufstriche),
|
Category(name: 'Brot, Cerealien & Aufstriche', icon: '🍞'),
|
||||||
Product('Milch', Unit.stueck, 2.23, 3, Category.getraenke),
|
Category(name: 'Getränke und Pfand', icon: '🫖'),
|
||||||
Product('Zahnpasta', Unit.stueck, 0.23, 7, Category.drogerieUndHaushalt),
|
Category(name: 'Drogerie und Haushalt', icon: '🧼'),
|
||||||
Product('Pfeffer', Unit.stueck, 0.23, 7, Category.oeleSossenUndGewuerze),
|
Category(name: 'Öl, Soßen und Gewürze', icon: '🫚'),
|
||||||
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien),
|
Category(name: 'Süßes und Knabbereien', icon: '🍪')
|
||||||
Product('Flaschenpfand', Unit.stueck, -0.15, 0, Category.pfand)
|
];
|
||||||
|
|
||||||
|
static List<Product> products = [
|
||||||
|
Product('Apfel', Unit.stueck, 0.23, 7, categories[0]),
|
||||||
|
Product('Mehl', Unit.menge, 0.003, 19, categories[1]),
|
||||||
|
Product('Brot', Unit.stueck, 1.23, 7, categories[2]),
|
||||||
|
Product('Milch', Unit.stueck, 2.23, 3, categories[3]),
|
||||||
|
Product('Zahnpasta', Unit.stueck, 0.23, 7, categories[4]),
|
||||||
|
Product('Pfeffer', Unit.stueck, 0.23, 7, categories[5]),
|
||||||
|
Product('Schokolade', Unit.menge, 0.23, 7, categories[6]),
|
||||||
|
Product('Flaschenpfand', Unit.stueck, -0.15, 0, categories[3])
|
||||||
];
|
];
|
||||||
|
|
||||||
static List<Basket> basket = [
|
static List<Basket> basket = [
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mitgliederladen/sample_data.dart';
|
||||||
|
|
||||||
class Shopping extends StatelessWidget {
|
class Shopping extends StatelessWidget {
|
||||||
Shopping({super.key});
|
const Shopping({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -13,22 +14,23 @@ class Shopping extends StatelessWidget {
|
||||||
body: GridView.builder(
|
body: GridView.builder(
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: 2),
|
crossAxisCount: 2),
|
||||||
|
itemCount: SampleData.categories.length,
|
||||||
itemBuilder: ((context, index) {
|
itemBuilder: ((context, index) {
|
||||||
return Card(
|
return Card(
|
||||||
child: Column(children: [
|
child: Column(children: [
|
||||||
const Expanded(
|
Expanded(
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
child: Text(
|
child: Text(
|
||||||
'🍒',
|
SampleData.categories[index].icon,
|
||||||
style: TextStyle(fontSize: 400),
|
style: const TextStyle(fontSize: 400),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Obst und Gemüse',
|
SampleData.categories[index].name,
|
||||||
style: Theme.of(context).textTheme.labelLarge,
|
style: Theme.of(context).textTheme.labelLarge,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue