mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 08:24:05 +02:00
image from backend
This commit is contained in:
parent
10d0481742
commit
0b2b6f5a18
@ -23,6 +23,10 @@ class ProductController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Image productImage(int productId) {
|
||||
return server.productImage(productId);
|
||||
}
|
||||
|
||||
List<Product> get filteredProducts {
|
||||
if (query.trim().isEmpty) {
|
||||
return products;
|
||||
|
@ -47,6 +47,7 @@ class ProductListItem extends StatelessWidget {
|
||||
final int productId;
|
||||
final String name;
|
||||
final int price;
|
||||
final Image image;
|
||||
final ProductPage productPage;
|
||||
|
||||
final Product product;
|
||||
@ -56,6 +57,7 @@ class ProductListItem extends StatelessWidget {
|
||||
required this.productId,
|
||||
required this.name,
|
||||
required this.price,
|
||||
required this.image,
|
||||
required this.productPage,
|
||||
required this.product,
|
||||
});
|
||||
@ -87,7 +89,7 @@ class ProductListItem extends StatelessWidget {
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(10),
|
||||
bottomRight: Radius.circular(10)),
|
||||
child: ProductImage(name)),
|
||||
child: image),
|
||||
],
|
||||
)),
|
||||
);
|
||||
@ -146,7 +148,10 @@ class _AllProductsPageState extends State<AllProductsPage> {
|
||||
productId: products[idx].id,
|
||||
name: products[idx].name,
|
||||
price: products[idx].priceDkkCent,
|
||||
productPage: ProductPage(product: products[idx]),
|
||||
productPage: ProductPage(
|
||||
product: products[idx],
|
||||
image: productRepo.productImage(products[idx].id)),
|
||||
image: productRepo.productImage(products[idx].id),
|
||||
product: products[idx],
|
||||
),
|
||||
itemCount: products.length,
|
||||
|
@ -15,6 +15,7 @@ import 'package:provider/provider.dart';
|
||||
class CartItemView extends StatelessWidget {
|
||||
final CartControllerCache cartRepo;
|
||||
final int productId;
|
||||
final Image image;
|
||||
final String name;
|
||||
final int price;
|
||||
final int amount;
|
||||
@ -25,7 +26,8 @@ class CartItemView extends StatelessWidget {
|
||||
required this.productId,
|
||||
required this.name,
|
||||
required this.price,
|
||||
required this.amount});
|
||||
required this.amount,
|
||||
required this.image});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -87,14 +89,7 @@ class CartItemView extends StatelessWidget {
|
||||
IconButton(
|
||||
onPressed: () => removeCartItemDialog(context),
|
||||
icon: const Icon(Icons.delete_outline)),
|
||||
Image(
|
||||
width: 100,
|
||||
image: AssetImage("assets/products/$name.png"),
|
||||
errorBuilder: (_, __, ___) => const Image(
|
||||
image: AssetImage("assets/placeholder.png"),
|
||||
width: 100,
|
||||
),
|
||||
)
|
||||
image
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -147,6 +142,7 @@ class CartPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final productController = context.read<ProductController>();
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
@ -159,6 +155,7 @@ class CartPage extends StatelessWidget {
|
||||
cartRepo: cartRepo,
|
||||
productId: cart[idx].product.id,
|
||||
name: cart[idx].product.name,
|
||||
image: productController.productImage(cart[idx].product.id),
|
||||
price: cart[idx].product.priceDkkCent,
|
||||
amount: cart[idx].amount),
|
||||
itemCount: cart.length,
|
||||
|
@ -9,8 +9,9 @@ import 'package:provider/provider.dart';
|
||||
|
||||
class ProductPage extends StatelessWidget {
|
||||
final Product product;
|
||||
final Image image;
|
||||
|
||||
const ProductPage({super.key, required this.product});
|
||||
const ProductPage({super.key, required this.product, required this.image});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -54,13 +55,7 @@ class ProductPage extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Image(
|
||||
image: AssetImage("assets/products/${product.name}.png"),
|
||||
errorBuilder: (_, __, ___) => const Image(
|
||||
image: AssetImage("assets/placeholder.png")),
|
||||
height: 250,
|
||||
fit: BoxFit.fitHeight,
|
||||
),
|
||||
image,
|
||||
Text(
|
||||
product.name,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mobile/models/cart_item.dart';
|
||||
import 'package:mobile/models/product.dart';
|
||||
@ -189,4 +190,9 @@ class BackendServer implements Server {
|
||||
return Err(res["msg"]);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Image productImage(int productId) {
|
||||
return Image.network("$_apiUrl/products/image.png?product_id=$productId");
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile/models/cart_item.dart';
|
||||
import 'package:mobile/models/coordinate.dart';
|
||||
import 'package:mobile/models/product.dart';
|
||||
@ -146,4 +147,9 @@ class MockServer implements Server {
|
||||
return Ok(Receipt(
|
||||
timestamp: DateTime.now(), id: id, receiptItems: <ReceiptItem>[]));
|
||||
}
|
||||
|
||||
@override
|
||||
Image productImage(int productId) {
|
||||
return Image.asset("assets/placeholder.png");
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile/models/cart_item.dart';
|
||||
import 'package:mobile/models/product.dart';
|
||||
import 'package:mobile/models/receipt.dart';
|
||||
@ -28,4 +29,6 @@ abstract class Server {
|
||||
|
||||
Future<Result<List<ReceiptHeader>, String>> allReceipts(String token);
|
||||
Future<Result<Receipt, String>> oneReceipt(String token, int id);
|
||||
|
||||
Image productImage(int productId);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user