mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +02:00
feedback when adding to cart
This commit is contained in:
parent
9451187c97
commit
3113e771e0
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile/repos/add_to_cart_state.dart';
|
||||
import 'package:mobile/repos/cart.dart';
|
||||
import 'package:mobile/repos/paying_state.dart';
|
||||
import 'package:mobile/repos/product.dart';
|
||||
@ -23,6 +24,7 @@ class MyApp extends StatelessWidget {
|
||||
ChangeNotifierProvider(create: (_) => CartRepo()),
|
||||
ChangeNotifierProvider(create: (_) => ReceiptRepo()),
|
||||
ChangeNotifierProvider(create: (_) => PayingStateRepo()),
|
||||
ChangeNotifierProvider(create: (_) => AddToCartStateRepo()),
|
||||
],
|
||||
child: MaterialApp(
|
||||
title: 'Fresh Plaza',
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile/repos/add_to_cart_state.dart';
|
||||
import 'package:mobile/repos/cart.dart';
|
||||
import 'package:mobile/repos/product.dart';
|
||||
import 'package:mobile/widgets/primary_button.dart';
|
||||
@ -11,6 +12,8 @@ class ProductPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AddToCartStateRepo addToCartStateRepo =
|
||||
context.watch<AddToCartStateRepo>();
|
||||
return Scaffold(
|
||||
body: Card(
|
||||
margin: const EdgeInsets.all(10),
|
||||
@ -70,14 +73,23 @@ class ProductPage extends StatelessWidget {
|
||||
onPressed: () {}, child: const Text("Find i butik")),
|
||||
PrimaryButton(
|
||||
onPressed: () {
|
||||
var cartRepo = context.read<CartRepo>();
|
||||
final snackBarDuration = const Duration(seconds: 2);
|
||||
addToCartStateRepo.notify(snackBarDuration);
|
||||
final snackBar = SnackBar(
|
||||
content: Text(
|
||||
'Tilføjet ${addToCartStateRepo.currentAmount} ${product.name} til kurven'),
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
ScaffoldMessenger.of(context).removeCurrentSnackBar();
|
||||
final cartRepo = context.read<CartRepo>();
|
||||
cartRepo.addToCart(product);
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
},
|
||||
child: const Text("Tilføj til indkøbskurv")),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
|
15
mobile/lib/repos/add_to_cart_state.dart
Normal file
15
mobile/lib/repos/add_to_cart_state.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AddToCartStateRepo extends ChangeNotifier {
|
||||
int currentAmount = 0;
|
||||
Timer resetTimer = Timer(const Duration(), () {});
|
||||
|
||||
void notify(Duration displayDuration) {
|
||||
resetTimer.cancel();
|
||||
currentAmount++;
|
||||
notifyListeners();
|
||||
resetTimer = Timer(displayDuration, () => currentAmount = 0);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user