mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-28 08:44:06 +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:flutter/material.dart';
|
||||||
|
import 'package:mobile/repos/add_to_cart_state.dart';
|
||||||
import 'package:mobile/repos/cart.dart';
|
import 'package:mobile/repos/cart.dart';
|
||||||
import 'package:mobile/repos/paying_state.dart';
|
import 'package:mobile/repos/paying_state.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
import 'package:mobile/repos/product.dart';
|
||||||
@ -23,6 +24,7 @@ class MyApp extends StatelessWidget {
|
|||||||
ChangeNotifierProvider(create: (_) => CartRepo()),
|
ChangeNotifierProvider(create: (_) => CartRepo()),
|
||||||
ChangeNotifierProvider(create: (_) => ReceiptRepo()),
|
ChangeNotifierProvider(create: (_) => ReceiptRepo()),
|
||||||
ChangeNotifierProvider(create: (_) => PayingStateRepo()),
|
ChangeNotifierProvider(create: (_) => PayingStateRepo()),
|
||||||
|
ChangeNotifierProvider(create: (_) => AddToCartStateRepo()),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
title: 'Fresh Plaza',
|
title: 'Fresh Plaza',
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/repos/add_to_cart_state.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/widgets/primary_button.dart';
|
import 'package:mobile/widgets/primary_button.dart';
|
||||||
@ -11,6 +12,8 @@ class ProductPage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final AddToCartStateRepo addToCartStateRepo =
|
||||||
|
context.watch<AddToCartStateRepo>();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Card(
|
body: Card(
|
||||||
margin: const EdgeInsets.all(10),
|
margin: const EdgeInsets.all(10),
|
||||||
@ -70,14 +73,23 @@ class ProductPage extends StatelessWidget {
|
|||||||
onPressed: () {}, child: const Text("Find i butik")),
|
onPressed: () {}, child: const Text("Find i butik")),
|
||||||
PrimaryButton(
|
PrimaryButton(
|
||||||
onPressed: () {
|
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);
|
cartRepo.addToCart(product);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
},
|
},
|
||||||
child: const Text("Tilføj til indkøbskurv")),
|
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