mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-28 00:34:06 +02:00
receipts page
This commit is contained in:
parent
d62f8bd29e
commit
14bbfb7326
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile/repos/cart.dart';
|
import 'package:mobile/repos/cart.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
import 'package:mobile/repos/product.dart';
|
||||||
|
import 'package:mobile/repos/receipt.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'pages/landing_page.dart';
|
import 'pages/landing_page.dart';
|
||||||
import 'package:mobile/repos/bottom_navigation_bar.dart';
|
import 'package:mobile/repos/bottom_navigation_bar.dart';
|
||||||
@ -19,6 +20,7 @@ class MyApp extends StatelessWidget {
|
|||||||
ChangeNotifierProvider(create: (_) => BottomNavigationBarRepo()),
|
ChangeNotifierProvider(create: (_) => BottomNavigationBarRepo()),
|
||||||
ChangeNotifierProvider(create: (_) => ProductRepo()),
|
ChangeNotifierProvider(create: (_) => ProductRepo()),
|
||||||
ChangeNotifierProvider(create: (_) => CartRepo()),
|
ChangeNotifierProvider(create: (_) => CartRepo()),
|
||||||
|
ChangeNotifierProvider(create: (_) => ReceiptRepo()),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
title: 'Fresh Plaza',
|
title: 'Fresh Plaza',
|
||||||
|
@ -19,14 +19,9 @@ class ProductListItem extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return PrimaryCard(
|
return PrimaryCard(
|
||||||
child: ElevatedButton(
|
child: InkWell(
|
||||||
style: ButtonStyle(
|
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||||
backgroundColor: WidgetStateProperty.all(Colors.transparent),
|
onTap: () {
|
||||||
elevation: WidgetStateProperty.all(0),
|
|
||||||
shape: WidgetStateProperty.all(const RoundedRectangleBorder()),
|
|
||||||
padding: WidgetStateProperty.all(EdgeInsets.zero),
|
|
||||||
splashFactory: NoSplash.splashFactory),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.push(MaterialPageRoute(builder: (context) => productPage));
|
.push(MaterialPageRoute(builder: (context) => productPage));
|
||||||
},
|
},
|
||||||
@ -49,7 +44,7 @@ class ProductListItem extends StatelessWidget {
|
|||||||
borderRadius: const BorderRadius.only(
|
borderRadius: const BorderRadius.only(
|
||||||
topRight: Radius.circular(10),
|
topRight: Radius.circular(10),
|
||||||
bottomRight: Radius.circular(10)),
|
bottomRight: Radius.circular(10)),
|
||||||
child: Image(
|
child: Ink.image(
|
||||||
image: AssetImage(imagePath),
|
image: AssetImage(imagePath),
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
width: 100,
|
width: 100,
|
||||||
|
53
mobile/lib/pages/all_receipts_page.dart
Normal file
53
mobile/lib/pages/all_receipts_page.dart
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/repos/receipt.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class ReceiptsListItem extends StatelessWidget {
|
||||||
|
final String dateFormatted;
|
||||||
|
final int totalPrice;
|
||||||
|
const ReceiptsListItem(
|
||||||
|
{super.key, required this.dateFormatted, required this.totalPrice});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Card(
|
||||||
|
child: InkWell(
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||||
|
onTap: () {},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [Text(dateFormatted), Text("$totalPrice kr")],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AllReceiptsPage extends StatelessWidget {
|
||||||
|
const AllReceiptsPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Expanded(child: Consumer<ReceiptRepo>(
|
||||||
|
builder: (_, cartRepo, __) {
|
||||||
|
final allReceipts = cartRepo.allReceipts();
|
||||||
|
return ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemBuilder: (_, idx) {
|
||||||
|
return ReceiptsListItem(
|
||||||
|
dateFormatted: allReceipts[idx].dateFormatted(),
|
||||||
|
totalPrice: allReceipts[idx].totalPrice());
|
||||||
|
},
|
||||||
|
itemCount: allReceipts.length,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -150,7 +150,7 @@ class CartPage extends StatelessWidget {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
FinishShoppingPage()));
|
const FinishShoppingPage()));
|
||||||
},
|
},
|
||||||
child: const Text("Afslut indkøb")),
|
child: const Text("Afslut indkøb")),
|
||||||
),
|
),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile/pages/all_products_page.dart';
|
import 'package:mobile/pages/all_products_page.dart';
|
||||||
import 'package:mobile/pages/cart_page.dart';
|
import 'package:mobile/pages/cart_page.dart';
|
||||||
import 'package:mobile/pages/receipts_page.dart';
|
import 'package:mobile/pages/all_receipts_page.dart';
|
||||||
import 'package:mobile/repos/bottom_navigation_bar.dart';
|
import 'package:mobile/repos/bottom_navigation_bar.dart';
|
||||||
import 'package:mobile/repos/cart.dart';
|
import 'package:mobile/repos/cart.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -10,7 +10,7 @@ class Dashboard extends StatelessWidget {
|
|||||||
final List<StatelessWidget> pages = [
|
final List<StatelessWidget> pages = [
|
||||||
const AllProductsPage(),
|
const AllProductsPage(),
|
||||||
const CartPage(),
|
const CartPage(),
|
||||||
const ReceiptsPage(),
|
const AllReceiptsPage(),
|
||||||
];
|
];
|
||||||
|
|
||||||
Dashboard({super.key});
|
Dashboard({super.key});
|
||||||
@ -48,17 +48,3 @@ class Dashboard extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Consumer<ProductRepo>(builder: (_, productRepo, __) {
|
|
||||||
// final products = productRepo.allProducts();
|
|
||||||
// return ListView.builder(
|
|
||||||
// shrinkWrap: true,
|
|
||||||
// itemBuilder: (_, idx) => ProductListItem(
|
|
||||||
// name: products[idx].name,
|
|
||||||
// price: products[idx].price,
|
|
||||||
// imagePath: "assets/${products[idx].name}.png",
|
|
||||||
// productPage: ProductPage(product: products[idx]),
|
|
||||||
// ),
|
|
||||||
// itemCount: products.length,
|
|
||||||
// );
|
|
||||||
// })
|
|
||||||
|
@ -1,48 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile/repos/cart.dart';
|
import 'package:mobile/repos/cart.dart';
|
||||||
import 'package:mobile/widgets/primary_button.dart';
|
import 'package:mobile/widgets/primary_button.dart';
|
||||||
|
import 'package:mobile/widgets/receipt_item.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class ReceiptItem extends StatelessWidget {
|
|
||||||
final int pricePerAmount;
|
|
||||||
final String name;
|
|
||||||
final int amount;
|
|
||||||
|
|
||||||
const ReceiptItem(
|
|
||||||
{super.key,
|
|
||||||
required this.pricePerAmount,
|
|
||||||
required this.name,
|
|
||||||
required this.amount});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(name),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 60,
|
|
||||||
child: Text(
|
|
||||||
"$amount stk",
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
)),
|
|
||||||
SizedBox(
|
|
||||||
width: 60,
|
|
||||||
child: Text(
|
|
||||||
"${pricePerAmount * amount} kr",
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FinishShoppingPage extends StatelessWidget {
|
class FinishShoppingPage extends StatelessWidget {
|
||||||
const FinishShoppingPage({super.key});
|
const FinishShoppingPage({super.key});
|
||||||
|
|
||||||
@ -65,7 +26,7 @@ class FinishShoppingPage extends StatelessWidget {
|
|||||||
child: Expanded(
|
child: Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemBuilder: (_, idx) => ReceiptItem(
|
itemBuilder: (_, idx) => ReceiptItemView(
|
||||||
pricePerAmount: cart[idx].product.price,
|
pricePerAmount: cart[idx].product.price,
|
||||||
name: cart[idx].product.name,
|
name: cart[idx].product.name,
|
||||||
amount: cart[idx].amount),
|
amount: cart[idx].amount),
|
||||||
|
@ -12,76 +12,74 @@ class ProductPage extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Container(
|
body: Card(
|
||||||
margin: const EdgeInsets.all(10),
|
margin: const EdgeInsets.all(10),
|
||||||
decoration: BoxDecoration(
|
child: Container(
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||||
color: const Color(0xFFFFFFFF),
|
child: Column(children: [
|
||||||
border: Border.all(color: const Color(0xFF666666)),
|
Row(
|
||||||
),
|
children: [
|
||||||
child: Column(children: [
|
Row(
|
||||||
Row(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
const BackButton(),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
const BackButton(),
|
children: [
|
||||||
Column(
|
Text(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
product.name,
|
||||||
children: [
|
style: const TextStyle(
|
||||||
Text(
|
fontSize: 20,
|
||||||
product.name,
|
),
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
),
|
),
|
||||||
),
|
Text(
|
||||||
Text(
|
"${product.price} kr",
|
||||||
"${product.price} kr",
|
style: const TextStyle(
|
||||||
style: const TextStyle(
|
fontSize: 16,
|
||||||
fontSize: 16,
|
),
|
||||||
),
|
)
|
||||||
)
|
])
|
||||||
])
|
],
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(20),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
Image(
|
|
||||||
image: AssetImage("assets/${product.name}.png"),
|
|
||||||
height: 250,
|
|
||||||
fit: BoxFit.fitHeight,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
product.name,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
"${product.price} kr",
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 20, bottom: 20),
|
|
||||||
child: Text(product.description),
|
|
||||||
),
|
|
||||||
PrimaryButton(
|
|
||||||
onPressed: () {}, child: const Text("Find i butik")),
|
|
||||||
PrimaryButton(
|
|
||||||
onPressed: () {
|
|
||||||
var cartRepo = context.read<CartRepo>();
|
|
||||||
cartRepo.addToCart(product);
|
|
||||||
},
|
|
||||||
child: const Text("Tilføj til indkøbskurv")),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
Expanded(
|
||||||
]),
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Image(
|
||||||
|
image: AssetImage("assets/${product.name}.png"),
|
||||||
|
height: 250,
|
||||||
|
fit: BoxFit.fitHeight,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
product.name,
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"${product.price} kr",
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 20, bottom: 20),
|
||||||
|
child: Text(product.description),
|
||||||
|
),
|
||||||
|
PrimaryButton(
|
||||||
|
onPressed: () {}, child: const Text("Find i butik")),
|
||||||
|
PrimaryButton(
|
||||||
|
onPressed: () {
|
||||||
|
var cartRepo = context.read<CartRepo>();
|
||||||
|
cartRepo.addToCart(product);
|
||||||
|
},
|
||||||
|
child: const Text("Tilføj til indkøbskurv")),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class ReceiptsPage extends StatelessWidget {
|
|
||||||
const ReceiptsPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const Row();
|
|
||||||
}
|
|
||||||
}
|
|
94
mobile/lib/repos/receipt.dart
Normal file
94
mobile/lib/repos/receipt.dart
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/repos/product.dart';
|
||||||
|
|
||||||
|
class ReceiptRepo extends ChangeNotifier {
|
||||||
|
final List<Receipt> receipts = [
|
||||||
|
Receipt(
|
||||||
|
id: 0,
|
||||||
|
date: DateTime.fromMillisecondsSinceEpoch(1730031200000),
|
||||||
|
receiptItems: [
|
||||||
|
ReceiptItem(
|
||||||
|
product: Product(
|
||||||
|
id: 1,
|
||||||
|
name: "Letmælk",
|
||||||
|
price: 13,
|
||||||
|
description: "Konventionel minimælk med fedtprocent på 0,4%"),
|
||||||
|
amount: 1),
|
||||||
|
ReceiptItem(
|
||||||
|
product: Product(
|
||||||
|
id: 0,
|
||||||
|
name: "Minimælk",
|
||||||
|
price: 12,
|
||||||
|
description: "Konventionel minimælk med fedtprocent på 0,4%"),
|
||||||
|
amount: 3),
|
||||||
|
]),
|
||||||
|
Receipt(id: 1, date: DateTime.now(), receiptItems: [
|
||||||
|
ReceiptItem(
|
||||||
|
product: Product(
|
||||||
|
id: 1,
|
||||||
|
name: "Letmælk",
|
||||||
|
price: 13,
|
||||||
|
description: "Konventionel minimælk med fedtprocent på 0,4%"),
|
||||||
|
amount: 3),
|
||||||
|
ReceiptItem(
|
||||||
|
product: Product(
|
||||||
|
id: 0,
|
||||||
|
name: "Minimælk",
|
||||||
|
price: 12,
|
||||||
|
description: "Konventionel minimælk med fedtprocent på 0,4%"),
|
||||||
|
amount: 1),
|
||||||
|
])
|
||||||
|
];
|
||||||
|
|
||||||
|
List<Receipt> allReceipts() {
|
||||||
|
return receipts;
|
||||||
|
}
|
||||||
|
|
||||||
|
Receipt? receiptWithId(int id) {
|
||||||
|
for (var i = 0; i < receipts.length; i++) {
|
||||||
|
if (receipts[i].id == id) {
|
||||||
|
return receipts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Receipt {
|
||||||
|
final int id;
|
||||||
|
final DateTime date;
|
||||||
|
final List<ReceiptItem> receiptItems;
|
||||||
|
|
||||||
|
Receipt({required this.date, required this.receiptItems, required this.id});
|
||||||
|
|
||||||
|
ReceiptItem? withProductId(int productId) {
|
||||||
|
for (var i = 0; i < receiptItems.length; i++) {
|
||||||
|
if (receiptItems[i].product.id == productId) {
|
||||||
|
return receiptItems[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalPrice() {
|
||||||
|
var result = 0;
|
||||||
|
for (var i = 0; i < receiptItems.length; i++) {
|
||||||
|
result += receiptItems[i].totalPrice();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String dateFormatted() {
|
||||||
|
return "${date.day}-${date.month}-${date.year}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReceiptItem {
|
||||||
|
final Product product;
|
||||||
|
final int amount;
|
||||||
|
ReceiptItem({required this.product, required this.amount});
|
||||||
|
|
||||||
|
int totalPrice() {
|
||||||
|
return product.price * amount;
|
||||||
|
}
|
||||||
|
}
|
41
mobile/lib/widgets/receipt_item.dart
Normal file
41
mobile/lib/widgets/receipt_item.dart
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ReceiptItemView extends StatelessWidget {
|
||||||
|
final int pricePerAmount;
|
||||||
|
final String name;
|
||||||
|
final int amount;
|
||||||
|
|
||||||
|
const ReceiptItemView(
|
||||||
|
{super.key,
|
||||||
|
required this.pricePerAmount,
|
||||||
|
required this.name,
|
||||||
|
required this.amount});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(name),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 60,
|
||||||
|
child: Text(
|
||||||
|
"$amount stk",
|
||||||
|
textAlign: TextAlign.end,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
)),
|
||||||
|
SizedBox(
|
||||||
|
width: 60,
|
||||||
|
child: Text(
|
||||||
|
"${pricePerAmount * amount} kr",
|
||||||
|
textAlign: TextAlign.end,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user