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