mirror of
				https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
				synced 2025-10-31 23:47:01 +01:00 
			
		
		
		
	add more products
This commit is contained in:
		
							parent
							
								
									a5502810cd
								
							
						
					
					
						commit
						9bdbaa85e1
					
				| @ -45,7 +45,7 @@ class ProductListItem extends StatelessWidget { | |||||||
|                       topRight: Radius.circular(10), |                       topRight: Radius.circular(10), | ||||||
|                       bottomRight: Radius.circular(10)), |                       bottomRight: Radius.circular(10)), | ||||||
|                   child: Ink.image( |                   child: Ink.image( | ||||||
|                     image: AssetImage(imagePath), |                     image: const AssetImage("assets/boykisser.png"), | ||||||
|                     fit: BoxFit.contain, |                     fit: BoxFit.contain, | ||||||
|                     width: 100, |                     width: 100, | ||||||
|                   )) |                   )) | ||||||
| @ -76,7 +76,8 @@ class AllProductsPage extends StatelessWidget { | |||||||
|                 ), |                 ), | ||||||
|               ], |               ], | ||||||
|             ), |             ), | ||||||
|             Consumer<ProductRepo>(builder: (_, productRepo, __) { |             Expanded( | ||||||
|  |               child: Consumer<ProductRepo>(builder: (_, productRepo, __) { | ||||||
|                 final products = productRepo.allProducts(); |                 final products = productRepo.allProducts(); | ||||||
|                 return ListView.builder( |                 return ListView.builder( | ||||||
|                   shrinkWrap: true, |                   shrinkWrap: true, | ||||||
| @ -89,6 +90,7 @@ class AllProductsPage extends StatelessWidget { | |||||||
|                   itemCount: products.length, |                   itemCount: products.length, | ||||||
|                 ); |                 ); | ||||||
|               }), |               }), | ||||||
|  |             ), | ||||||
|           ]), |           ]), | ||||||
|         ), |         ), | ||||||
|       ], |       ], | ||||||
|  | |||||||
| @ -148,7 +148,7 @@ class CartPage extends StatelessWidget { | |||||||
|                     productId: cart[idx].product.id, |                     productId: cart[idx].product.id, | ||||||
|                     name: cart[idx].product.name, |                     name: cart[idx].product.name, | ||||||
|                     price: cart[idx].product.price, |                     price: cart[idx].product.price, | ||||||
|                     imagePath: "assets/${cart[idx].product.name}.png", |                     imagePath: "assets/boykisser.png", | ||||||
|                     amount: cart[idx].amount), |                     amount: cart[idx].amount), | ||||||
|                 itemCount: cart.length, |                 itemCount: cart.length, | ||||||
|               ); |               ); | ||||||
|  | |||||||
| @ -52,8 +52,8 @@ class ProductPage extends StatelessWidget { | |||||||
|                 child: Column( |                 child: Column( | ||||||
|                   crossAxisAlignment: CrossAxisAlignment.stretch, |                   crossAxisAlignment: CrossAxisAlignment.stretch, | ||||||
|                   children: [ |                   children: [ | ||||||
|                     Image( |                     const Image( | ||||||
|                       image: AssetImage("assets/${product.name}.png"), |                       image: AssetImage("assets/boykisser.png"), | ||||||
|                       height: 250, |                       height: 250, | ||||||
|                       fit: BoxFit.fitHeight, |                       fit: BoxFit.fitHeight, | ||||||
|                     ), |                     ), | ||||||
|  | |||||||
| @ -1,32 +1,68 @@ | |||||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||||
| 
 | 
 | ||||||
| class ProductRepo extends ChangeNotifier { | class ProductRepo extends ChangeNotifier { | ||||||
|   final List<Product> _products = [ |   int _nextId = 0; | ||||||
|  |   List<Product> products = []; | ||||||
|  |   ProductRepo() { | ||||||
|  |     _addAllProducts(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   int getNextId() { | ||||||
|  |     return _nextId++; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   List<Product> allProducts() { | ||||||
|  |     return products; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   void changePrice(int idx, int price) { | ||||||
|  |     products[idx].price = price; | ||||||
|  |     notifyListeners(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   void _addAllProducts() { | ||||||
|  |     products = [ | ||||||
|       Product( |       Product( | ||||||
|         id: 0, |           id: _nextId++, | ||||||
|           name: "Minimælk", |           name: "Minimælk", | ||||||
|           price: 12, |           price: 12, | ||||||
|           description: "Konventionel minimælk med fedtprocent på 0,4%"), |           description: "Konventionel minimælk med fedtprocent på 0,4%"), | ||||||
|       Product( |       Product( | ||||||
|         id: 1, |           id: _nextId++, | ||||||
|           name: "Letmælk", |           name: "Letmælk", | ||||||
|           price: 13, |           price: 13, | ||||||
|           description: "Konventionel letmælk med fedtprocent på 1,5%"), |           description: "Konventionel letmælk med fedtprocent på 1,5%"), | ||||||
|       Product( |       Product( | ||||||
|         id: 2, |           id: _nextId++, | ||||||
|           name: "Frilands Øko Supermælk", |           name: "Frilands Øko Supermælk", | ||||||
|           price: 20, |           price: 20, | ||||||
|           description: |           description: | ||||||
|             "Økologisk mælk af frilandskøer med fedtprocent på 3,5%. Ikke homogeniseret eller pasteuriseret. Skaber store muskler og styrker knoglerne 💪") |               "Økologisk mælk af frilandskøer med fedtprocent på 3,5%. Ikke homogeniseret eller pasteuriseret. Skaber store muskler og styrker knoglerne 💪"), | ||||||
|  |       Product( | ||||||
|  |           id: _nextId++, | ||||||
|  |           name: "Øko Gulerødder 1 kg", | ||||||
|  |           price: 10, | ||||||
|  |           description: ""), | ||||||
|  |       Product(id: _nextId++, name: "Øko Agurk", price: 10, description: ""), | ||||||
|  |       Product(id: _nextId++, name: "Æbler 1 kg", price: 10, description: ""), | ||||||
|  |       Product(id: _nextId++, name: "Basmati Ris", price: 20, description: ""), | ||||||
|  |       Product(id: _nextId++, name: "Haribo Mix", price: 30, description: ""), | ||||||
|  |       Product(id: _nextId++, name: "Smør", price: 30, description: ""), | ||||||
|  |       Product(id: _nextId++, name: "Harboe Cola", price: 5, description: ""), | ||||||
|  |       Product( | ||||||
|  |           id: _nextId++, | ||||||
|  |           name: "Monster Energi Drik", | ||||||
|  |           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++, | ||||||
|  |           name: "Jägermeister 750 ml", | ||||||
|  |           price: 60, | ||||||
|  |           description: ""), | ||||||
|     ]; |     ]; | ||||||
| 
 |  | ||||||
|   List<Product> allProducts() { |  | ||||||
|     return _products; |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   void changePrice(int idx, int price) { |  | ||||||
|     _products[idx].price = price; |  | ||||||
|     notifyListeners(); |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user