add more products

This commit is contained in:
Mikkel Troels Kongsted 2025-02-05 11:15:33 +01:00
parent a5502810cd
commit 9bdbaa85e1
4 changed files with 75 additions and 37 deletions

View File

@ -45,7 +45,7 @@ class ProductListItem extends StatelessWidget {
topRight: Radius.circular(10),
bottomRight: Radius.circular(10)),
child: Ink.image(
image: AssetImage(imagePath),
image: const AssetImage("assets/boykisser.png"),
fit: BoxFit.contain,
width: 100,
))
@ -76,19 +76,21 @@ class AllProductsPage extends StatelessWidget {
),
],
),
Consumer<ProductRepo>(builder: (_, productRepo, __) {
final products = productRepo.allProducts();
return ListView.builder(
shrinkWrap: true,
itemBuilder: (_, idx) => ProductListItem(
name: products[idx].name,
price: products[idx].price,
imagePath: "assets/${products[idx].name}.png",
productPage: ProductPage(product: products[idx]),
),
itemCount: products.length,
);
}),
Expanded(
child: Consumer<ProductRepo>(builder: (_, productRepo, __) {
final products = productRepo.allProducts();
return ListView.builder(
shrinkWrap: true,
itemBuilder: (_, idx) => ProductListItem(
name: products[idx].name,
price: products[idx].price,
imagePath: "assets/${products[idx].name}.png",
productPage: ProductPage(product: products[idx]),
),
itemCount: products.length,
);
}),
),
]),
),
],

View File

@ -148,7 +148,7 @@ class CartPage extends StatelessWidget {
productId: cart[idx].product.id,
name: cart[idx].product.name,
price: cart[idx].product.price,
imagePath: "assets/${cart[idx].product.name}.png",
imagePath: "assets/boykisser.png",
amount: cart[idx].amount),
itemCount: cart.length,
);

View File

@ -52,8 +52,8 @@ class ProductPage extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image(
image: AssetImage("assets/${product.name}.png"),
const Image(
image: AssetImage("assets/boykisser.png"),
height: 250,
fit: BoxFit.fitHeight,
),

View File

@ -1,33 +1,69 @@
import 'package:flutter/material.dart';
class ProductRepo extends ChangeNotifier {
final List<Product> _products = [
Product(
id: 0,
name: "Minimælk",
price: 12,
description: "Konventionel minimælk med fedtprocent på 0,4%"),
Product(
id: 1,
name: "Letmælk",
price: 13,
description: "Konventionel letmælk med fedtprocent på 1,5%"),
Product(
id: 2,
name: "Frilands Øko Supermælk",
price: 20,
description:
"Økologisk mælk af frilandskøer med fedtprocent på 3,5%. Ikke homogeniseret eller pasteuriseret. Skaber store muskler og styrker knoglerne 💪")
];
int _nextId = 0;
List<Product> products = [];
ProductRepo() {
_addAllProducts();
}
int getNextId() {
return _nextId++;
}
List<Product> allProducts() {
return _products;
return products;
}
void changePrice(int idx, int price) {
_products[idx].price = price;
products[idx].price = price;
notifyListeners();
}
void _addAllProducts() {
products = [
Product(
id: _nextId++,
name: "Minimælk",
price: 12,
description: "Konventionel minimælk med fedtprocent på 0,4%"),
Product(
id: _nextId++,
name: "Letmælk",
price: 13,
description: "Konventionel letmælk med fedtprocent på 1,5%"),
Product(
id: _nextId++,
name: "Frilands Øko Supermælk",
price: 20,
description:
"Ø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: ""),
];
}
}
class Product {