mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +02:00
finish shopping page
This commit is contained in:
parent
9b74452b94
commit
d62f8bd29e
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile/pages/finish_shopping_page.dart';
|
||||
import 'package:mobile/repos/cart.dart';
|
||||
import 'package:mobile/widgets/primary_button.dart';
|
||||
import 'package:mobile/widgets/primary_card.dart';
|
||||
@ -144,7 +145,14 @@ class CartPage extends StatelessWidget {
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
child: PrimaryButton(
|
||||
onPressed: () {}, child: const Text("Afslut indkøb")),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
FinishShoppingPage()));
|
||||
},
|
||||
child: const Text("Afslut indkøb")),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
95
mobile/lib/pages/finish_shopping_page.dart
Normal file
95
mobile/lib/pages/finish_shopping_page.dart
Normal file
@ -0,0 +1,95 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile/repos/cart.dart';
|
||||
import 'package:mobile/widgets/primary_button.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 {
|
||||
const FinishShoppingPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final CartRepo cartRepo = context.read<CartRepo>();
|
||||
final cart = cartRepo.allCartItems();
|
||||
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back)),
|
||||
Container(
|
||||
margin: const EdgeInsets.all(20),
|
||||
child: Expanded(
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (_, idx) => ReceiptItem(
|
||||
pricePerAmount: cart[idx].product.price,
|
||||
name: cart[idx].product.name,
|
||||
amount: cart[idx].amount),
|
||||
itemCount: cart.length)),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.all(20),
|
||||
child: Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
"Total:",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text("${cartRepo.totalPrice()} kr"),
|
||||
],
|
||||
)),
|
||||
),
|
||||
Center(
|
||||
child:
|
||||
PrimaryButton(onPressed: () {}, child: const Text("Betal")))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -119,6 +119,11 @@ class CartRepo extends ChangeNotifier {
|
||||
totalItemsInCart() {
|
||||
return cart.fold<int>(0, (prev, cartItem) => prev + cartItem.amount);
|
||||
}
|
||||
|
||||
totalPrice() {
|
||||
return cart.fold<int>(
|
||||
0, (prev, cartItem) => prev + cartItem.amount * cartItem.product.price);
|
||||
}
|
||||
}
|
||||
|
||||
class CartItem {
|
||||
|
Loading…
x
Reference in New Issue
Block a user