diff --git a/mobile/assets/Letmælk.png b/mobile/assets/Letmælk.png deleted file mode 100644 index 63967cc..0000000 Binary files a/mobile/assets/Letmælk.png and /dev/null differ diff --git a/mobile/assets/Minimælk.png b/mobile/assets/Minimælk.png deleted file mode 100644 index 63967cc..0000000 Binary files a/mobile/assets/Minimælk.png and /dev/null differ diff --git a/mobile/assets/boykisser.png b/mobile/assets/boykisser.png deleted file mode 100644 index 63967cc..0000000 Binary files a/mobile/assets/boykisser.png and /dev/null differ diff --git a/mobile/assets/placeholder.png b/mobile/assets/placeholder.png new file mode 100644 index 0000000..f25801e Binary files /dev/null and b/mobile/assets/placeholder.png differ diff --git a/mobile/assets/products/Basmati Ris.png b/mobile/assets/products/Basmati Ris.png new file mode 100644 index 0000000..227cc1e Binary files /dev/null and b/mobile/assets/products/Basmati Ris.png differ diff --git a/mobile/assets/Frilands Øko Supermælk.png b/mobile/assets/products/Frilands Øko Supermælk.png similarity index 100% rename from mobile/assets/Frilands Øko Supermælk.png rename to mobile/assets/products/Frilands Øko Supermælk.png diff --git a/mobile/assets/products/Harboe Cola.png b/mobile/assets/products/Harboe Cola.png new file mode 100644 index 0000000..1d68242 Binary files /dev/null and b/mobile/assets/products/Harboe Cola.png differ diff --git a/mobile/assets/products/Haribo Mix1.png b/mobile/assets/products/Haribo Mix1.png new file mode 100644 index 0000000..ab2f0af Binary files /dev/null and b/mobile/assets/products/Haribo Mix1.png differ diff --git a/mobile/assets/products/Jägermeister 750 ml.png b/mobile/assets/products/Jägermeister 750 ml.png new file mode 100644 index 0000000..9f91027 Binary files /dev/null and b/mobile/assets/products/Jägermeister 750 ml.png differ diff --git a/mobile/assets/products/Letmælk.png b/mobile/assets/products/Letmælk.png new file mode 100644 index 0000000..85ded39 Binary files /dev/null and b/mobile/assets/products/Letmælk.png differ diff --git a/mobile/assets/products/Minimælk.png b/mobile/assets/products/Minimælk.png new file mode 100644 index 0000000..6239ffe Binary files /dev/null and b/mobile/assets/products/Minimælk.png differ diff --git a/mobile/assets/products/Monster Energi Drik.png b/mobile/assets/products/Monster Energi Drik.png new file mode 100644 index 0000000..ef08ff8 Binary files /dev/null and b/mobile/assets/products/Monster Energi Drik.png differ diff --git a/mobile/assets/products/Protein Chokoladedrik.png b/mobile/assets/products/Protein Chokoladedrik.png new file mode 100644 index 0000000..043c429 Binary files /dev/null and b/mobile/assets/products/Protein Chokoladedrik.png differ diff --git a/mobile/assets/products/Rød Cecil.png b/mobile/assets/products/Rød Cecil.png new file mode 100644 index 0000000..8088a7e Binary files /dev/null and b/mobile/assets/products/Rød Cecil.png differ diff --git a/mobile/assets/products/Smør.png b/mobile/assets/products/Smør.png new file mode 100644 index 0000000..dc5329d Binary files /dev/null and b/mobile/assets/products/Smør.png differ diff --git a/mobile/assets/products/Spaghetti.png b/mobile/assets/products/Spaghetti.png new file mode 100644 index 0000000..f04291c Binary files /dev/null and b/mobile/assets/products/Spaghetti.png differ diff --git a/mobile/assets/products/Æbler 1 kg.png b/mobile/assets/products/Æbler 1 kg.png new file mode 100644 index 0000000..f4ae183 Binary files /dev/null and b/mobile/assets/products/Æbler 1 kg.png differ diff --git a/mobile/assets/products/Øko Agurk.png b/mobile/assets/products/Øko Agurk.png new file mode 100644 index 0000000..46fe35d Binary files /dev/null and b/mobile/assets/products/Øko Agurk.png differ diff --git a/mobile/assets/products/Øko Gulerødder 1 kg.png b/mobile/assets/products/Øko Gulerødder 1 kg.png new file mode 100644 index 0000000..6b031ab Binary files /dev/null and b/mobile/assets/products/Øko Gulerødder 1 kg.png differ diff --git a/mobile/lib/pages/all_products_page.dart b/mobile/lib/pages/all_products_page.dart index 0e0d5ca..2c5ff47 100644 --- a/mobile/lib/pages/all_products_page.dart +++ b/mobile/lib/pages/all_products_page.dart @@ -4,17 +4,59 @@ import 'package:mobile/widgets/sized_card.dart'; import 'package:provider/provider.dart'; import 'product_page.dart'; +class ProductImage extends StatefulWidget { + final String productName; + + const ProductImage(this.productName, {super.key}); + + @override + State createState() { + return _ProductImageState(); + } +} + +class _ProductImageState extends State { + late ImageProvider image; + + @override + void initState() { + image = Image.asset( + "assets/products/${widget.productName}.png", + ).image; + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Ink.image( + image: image, + onImageError: (_, __) { + setState(() { + image = Image.asset("assets/placeholder.png").image; + }); + }, + fit: BoxFit.contain, + width: 100, + ); + } +} + class ProductListItem extends StatelessWidget { + final int productId; final String name; final int price; - final String imagePath; final ProductPage productPage; - const ProductListItem( - {super.key, - required this.name, - required this.price, - required this.imagePath, - required this.productPage}); + + final Product product; + + const ProductListItem({ + super.key, + required this.productId, + required this.name, + required this.price, + required this.productPage, + required this.product, + }); @override Widget build(BuildContext context) { @@ -43,11 +85,7 @@ class ProductListItem extends StatelessWidget { borderRadius: const BorderRadius.only( topRight: Radius.circular(10), bottomRight: Radius.circular(10)), - child: Ink.image( - image: const AssetImage("assets/boykisser.png"), - fit: BoxFit.contain, - width: 100, - )) + child: ProductImage(name)), ], )), ); @@ -87,10 +125,11 @@ class AllProductsPage extends StatelessWidget { return ListView.builder( shrinkWrap: true, itemBuilder: (_, idx) => ProductListItem( + productId: products[idx].id, name: products[idx].name, price: products[idx].price, - imagePath: "assets/${products[idx].name}.png", productPage: ProductPage(product: products[idx]), + product: products[idx], ), itemCount: products.length, ); diff --git a/mobile/lib/pages/cart_page.dart b/mobile/lib/pages/cart_page.dart index 1773877..a7bdcf8 100644 --- a/mobile/lib/pages/cart_page.dart +++ b/mobile/lib/pages/cart_page.dart @@ -15,7 +15,6 @@ class CartItemView extends StatelessWidget { final int productId; final String name; final int price; - final String imagePath; final int amount; const CartItemView( @@ -24,7 +23,6 @@ class CartItemView extends StatelessWidget { required this.productId, required this.name, required this.price, - required this.imagePath, required this.amount}); @override @@ -87,7 +85,14 @@ class CartItemView extends StatelessWidget { IconButton( onPressed: () => removeCartItemDialog(context), icon: const Icon(Icons.delete_outline)), - Image(width: 100, image: AssetImage(imagePath)) + Image( + width: 100, + image: AssetImage("assets/products/$name.png"), + errorBuilder: (_, __, ___) => const Image( + image: AssetImage("assets/placeholder.png"), + width: 100, + ), + ) ], ), ); @@ -154,7 +159,6 @@ class CartPage extends StatelessWidget { productId: cart[idx].product.id, name: cart[idx].product.name, price: cart[idx].product.price, - imagePath: "assets/boykisser.png", amount: cart[idx].amount), itemCount: cart.length, ); diff --git a/mobile/lib/pages/product_page.dart b/mobile/lib/pages/product_page.dart index 6100d07..8d7fea2 100644 --- a/mobile/lib/pages/product_page.dart +++ b/mobile/lib/pages/product_page.dart @@ -54,8 +54,10 @@ class ProductPage extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - const Image( - image: AssetImage("assets/boykisser.png"), + Image( + image: AssetImage("assets/products/${product.name}.png"), + errorBuilder: (_, __, ___) => const Image( + image: AssetImage("assets/placeholder.png")), height: 250, fit: BoxFit.fitHeight, ), diff --git a/mobile/lib/repos/product.dart b/mobile/lib/repos/product.dart index ad958cd..d041412 100644 --- a/mobile/lib/repos/product.dart +++ b/mobile/lib/repos/product.dart @@ -79,7 +79,6 @@ class ProductRepo extends ChangeNotifier { price: 20, description: ""), Product(id: _nextId++, name: "Spaghetti", price: 10, description: ""), - Product(id: _nextId++, name: "Æbler 1 kg", price: 20, description: ""), Product(id: _nextId++, name: "Rød Cecil", price: 60, description: ""), Product( id: _nextId++, @@ -111,11 +110,12 @@ class Product { final Coordinate? location; final String? barcode; - Product( - {required this.id, - required this.name, - required this.price, - required this.description, - this.location, - this.barcode}); + Product({ + required this.id, + required this.name, + required this.price, + required this.description, + this.location, + this.barcode, + }); } diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index b3dc7ad..d167d21 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -56,6 +56,7 @@ dev_dependencies: flutter: assets: - assets/ + - assets/products/ - google_fonts/ # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in