From e1825fe86f68828ab4e5f892e581bb616d7a9a4b Mon Sep 17 00:00:00 2001 From: efrilm Date: Sun, 3 Aug 2025 01:00:33 +0700 Subject: [PATCH] feat: product image and printer type --- lib/data/dataoutputs/print_dataoutputs.dart | 82 +++++++++---------- .../response/product_response_model.dart | 20 +++++ lib/presentation/home/widgets/order_menu.dart | 7 +- .../home/widgets/product_card.dart | 6 +- .../dialogs/detail_product_dialog.dart | 6 +- .../setting/dialogs/form_product_dialog.dart | 74 ++++++++--------- .../setting/widgets/menu_product_item.dart | 6 +- 7 files changed, 108 insertions(+), 93 deletions(-) diff --git a/lib/data/dataoutputs/print_dataoutputs.dart b/lib/data/dataoutputs/print_dataoutputs.dart index ad4be8d..613a338 100644 --- a/lib/data/dataoutputs/print_dataoutputs.dart +++ b/lib/data/dataoutputs/print_dataoutputs.dart @@ -991,27 +991,27 @@ class PrintDataoutputs { : '--------------------------------', styles: const PosStyles(bold: false, align: PosAlign.center)); bytes += generator.feed(1); - // final kitchenProducts = - // products.where((p) => p.product.printerType == 'kitchen'); - // for (final product in kitchenProducts) { - // bytes += generator.text('${product.quantity} x ${product.product.name}', - // styles: const PosStyles( - // align: PosAlign.left, - // bold: false, - // height: PosTextSize.size2, - // width: PosTextSize.size1, - // )); - // if (product.notes.isNotEmpty) { - // bytes += generator.text(' Notes: ${product.notes}', - // styles: const PosStyles( - // align: PosAlign.left, - // bold: false, - // height: PosTextSize.size1, - // width: PosTextSize.size1, - // fontType: PosFontType.fontA, - // )); - // } - // } + final kitchenProducts = + products.where((p) => p.product.printerType == 'kitchen'); + for (final product in kitchenProducts) { + bytes += generator.text('${product.quantity} x ${product.product.name}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size2, + width: PosTextSize.size1, + )); + if (product.notes.isNotEmpty) { + bytes += generator.text(' Notes: ${product.notes}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size1, + width: PosTextSize.size1, + fontType: PosFontType.fontA, + )); + } + } bytes += generator.feed(1); bytes += generator.text( @@ -1105,26 +1105,26 @@ class PrintDataoutputs { : '--------------------------------', styles: const PosStyles(bold: false, align: PosAlign.center)); bytes += generator.feed(1); - // final barProducts = products.where((p) => p.product.printerType == 'bar'); - // for (final product in barProducts) { - // bytes += generator.text('${product.quantity} x ${product.product.name}', - // styles: const PosStyles( - // align: PosAlign.left, - // bold: false, - // height: PosTextSize.size2, - // width: PosTextSize.size1, - // )); - // if (product.notes.isNotEmpty) { - // bytes += generator.text(' Notes: ${product.notes}', - // styles: const PosStyles( - // align: PosAlign.left, - // bold: false, - // height: PosTextSize.size1, - // width: PosTextSize.size1, - // fontType: PosFontType.fontA, - // )); - // } - // } + final barProducts = products.where((p) => p.product.printerType == 'bar'); + for (final product in barProducts) { + bytes += generator.text('${product.quantity} x ${product.product.name}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size2, + width: PosTextSize.size1, + )); + if (product.notes.isNotEmpty) { + bytes += generator.text(' Notes: ${product.notes}', + styles: const PosStyles( + align: PosAlign.left, + bold: false, + height: PosTextSize.size1, + width: PosTextSize.size1, + fontType: PosFontType.fontA, + )); + } + } bytes += generator.feed(1); bytes += generator.text( diff --git a/lib/data/models/response/product_response_model.dart b/lib/data/models/response/product_response_model.dart index b8527b3..7063c7a 100644 --- a/lib/data/models/response/product_response_model.dart +++ b/lib/data/models/response/product_response_model.dart @@ -78,6 +78,8 @@ class Product { final int? price; final int? cost; final String? businessType; + final String? imageUrl; + final String? printerType; final Map? metadata; final bool? isActive; final DateTime? createdAt; @@ -94,6 +96,8 @@ class Product { this.price, this.cost, this.businessType, + this.imageUrl, + this.printerType, this.metadata, this.isActive, this.createdAt, @@ -115,6 +119,8 @@ class Product { price: json["price"], cost: json["cost"], businessType: json["business_type"], + imageUrl: json["image_url"], + printerType: json["printer_type"], metadata: json["metadata"] ?? {}, isActive: json["is_active"], createdAt: json["created_at"] == null @@ -144,6 +150,8 @@ class Product { price: json["price"], cost: json["cost"], businessType: json["business_type"], + imageUrl: json["image_url"], + printerType: json["printer_type"], metadata: json["metadata"] ?? {}, isActive: json["is_active"], createdAt: json["created_at"] == null @@ -168,6 +176,8 @@ class Product { "price": price, "cost": cost, "business_type": businessType, + "image_url": imageUrl, + "printer_type": printerType, "metadata": metadata, "is_active": isActive, "created_at": createdAt?.toIso8601String(), @@ -187,6 +197,8 @@ class Product { "price": price, "cost": cost, "business_type": businessType, + "image_url": imageUrl, + "printer_type": printerType, "metadata": metadata, "is_active": isActive, "created_at": createdAt?.toIso8601String(), @@ -209,6 +221,8 @@ class Product { other.price == price && other.cost == cost && other.businessType == businessType && + other.imageUrl == imageUrl && + other.printerType == printerType && other.metadata == metadata && other.isActive == isActive && other.createdAt == createdAt && @@ -237,6 +251,8 @@ class Product { price.hashCode ^ cost.hashCode ^ businessType.hashCode ^ + imageUrl.hashCode ^ + printerType.hashCode ^ metadata.hashCode ^ isActive.hashCode ^ createdAt.hashCode ^ @@ -254,6 +270,8 @@ class Product { int? price, int? cost, String? businessType, + String? imageUrl, + String? printerType, Map? metadata, bool? isActive, DateTime? createdAt, @@ -270,6 +288,8 @@ class Product { price: price ?? this.price, cost: cost ?? this.cost, businessType: businessType ?? this.businessType, + imageUrl: imageUrl ?? this.imageUrl, + printerType: printerType ?? this.printerType, metadata: metadata ?? this.metadata, isActive: isActive ?? this.isActive, createdAt: createdAt ?? this.createdAt, diff --git a/lib/presentation/home/widgets/order_menu.dart b/lib/presentation/home/widgets/order_menu.dart index d7e2e0e..e0bea91 100644 --- a/lib/presentation/home/widgets/order_menu.dart +++ b/lib/presentation/home/widgets/order_menu.dart @@ -59,9 +59,10 @@ class _OrderMenuState extends State { // color: AppColors.primary, // ), CachedNetworkImage( - imageUrl: widget.data.product.name!.contains('http') - ? widget.data.product.name! - : '${Variables.baseUrl}/${widget.data.product.name}', + imageUrl: (widget.data.product.imageUrl ?? '') + .contains('http') + ? widget.data.product.imageUrl! + : '${Variables.baseUrl}/${widget.data.product.imageUrl}', width: 50.0, height: 50.0, fit: BoxFit.cover, diff --git a/lib/presentation/home/widgets/product_card.dart b/lib/presentation/home/widgets/product_card.dart index 4298aab..8c88a9d 100644 --- a/lib/presentation/home/widgets/product_card.dart +++ b/lib/presentation/home/widgets/product_card.dart @@ -42,9 +42,9 @@ class ProductCard extends StatelessWidget { ClipRRect( borderRadius: BorderRadius.all(Radius.circular(8.0)), child: CachedNetworkImage( - imageUrl: data.name!.contains('http') - ? data.name! - : '${Variables.baseUrl}/${data.name}', + imageUrl: (data.imageUrl ?? "").contains('http') + ? data.imageUrl! + : '${Variables.baseUrl}/${data.imageUrl}', fit: BoxFit.cover, width: double.infinity, height: 120, diff --git a/lib/presentation/setting/dialogs/detail_product_dialog.dart b/lib/presentation/setting/dialogs/detail_product_dialog.dart index 4b96426..3a9ced6 100644 --- a/lib/presentation/setting/dialogs/detail_product_dialog.dart +++ b/lib/presentation/setting/dialogs/detail_product_dialog.dart @@ -28,9 +28,9 @@ class DetailProductDialog extends StatelessWidget { ClipRRect( borderRadius: BorderRadius.circular(12), child: CachedNetworkImage( - imageUrl: product.name!.contains('http') - ? product.name! - : '${Variables.baseUrl}/${product.name}', + imageUrl: (product.imageUrl ?? "").contains('http') + ? product.imageUrl! + : '${Variables.baseUrl}/${product.imageUrl}', fit: BoxFit.cover, width: 120, height: 120, diff --git a/lib/presentation/setting/dialogs/form_product_dialog.dart b/lib/presentation/setting/dialogs/form_product_dialog.dart index 779376b..1550d72 100644 --- a/lib/presentation/setting/dialogs/form_product_dialog.dart +++ b/lib/presentation/setting/dialogs/form_product_dialog.dart @@ -296,23 +296,20 @@ class _FormProductDialogState extends State { return; } - // log("isBestSeller: $isBestSeller"); - // final String name = nameController!.text; - // final int stock = - // stockController!.text.toIntegerFromText; + log("isBestSeller: $isBestSeller"); + final String name = nameController!.text; + final int stock = + stockController!.text.toIntegerFromText; - // final Product product = widget.product!.copyWith( - // name: name, - // price: priceValue.toString(), - // stock: stock, - // categoryId: selectCategory!.id!, - // isFavorite: isBestSeller ? 1 : 0, - // printerType: printType, - // ); + final Product product = widget.product!.copyWith( + name: name, + price: priceValue, + printerType: printType, + ); - // context.read().add( - // UpdateProductEvent.updateProduct( - // product, imageFile)); + context.read().add( + UpdateProductEvent.updateProduct( + product, imageFile)); }, label: 'Ubah Produk', ); @@ -354,33 +351,30 @@ class _FormProductDialogState extends State { orElse: () { return Button.filled( onPressed: () { - // if (selectCategory == null) { - // ScaffoldMessenger.of(context).showSnackBar( - // const SnackBar( - // content: Text('Please select a category'), - // backgroundColor: Colors.red, - // ), - // ); - // return; - // } + if (selectCategory == null) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Please select a category'), + backgroundColor: Colors.red, + ), + ); + return; + } - // log("isBestSeller: $isBestSeller"); - // final String name = nameController!.text; + log("isBestSeller: $isBestSeller"); + final String name = nameController!.text; - // final int stock = - // stockController!.text.toIntegerFromText; - // final Product product = Product( - // name: name, - // price: priceValue.toString(), - // stock: stock, - // categoryId: selectCategory!.id!, - // isFavorite: isBestSeller ? 1 : 0, - // image: imageFile!.path, - // printerType: printType, - // ); - // context.read().add( - // AddProductEvent.addProduct( - // product, imageFile!)); + final int stock = + stockController!.text.toIntegerFromText; + final Product product = Product( + name: name, + price: priceValue, + imageUrl: imageFile!.path, + printerType: printType, + ); + context.read().add( + AddProductEvent.addProduct( + product, imageFile!)); }, label: 'Simpan Produk', ); diff --git a/lib/presentation/setting/widgets/menu_product_item.dart b/lib/presentation/setting/widgets/menu_product_item.dart index 2092f99..3543c09 100644 --- a/lib/presentation/setting/widgets/menu_product_item.dart +++ b/lib/presentation/setting/widgets/menu_product_item.dart @@ -36,9 +36,9 @@ class MenuProductItem extends StatelessWidget { child: ClipRRect( borderRadius: BorderRadius.circular(12), child: CachedNetworkImage( - imageUrl: data.name!.contains('http') - ? data.name! - : '${Variables.baseUrl}/${data.name}', + imageUrl: (data.imageUrl ?? '').contains('http') + ? data.imageUrl! + : '${Variables.baseUrl}/${data.imageUrl}', fit: BoxFit.cover, errorWidget: (context, url, error) => Container( width: double.infinity,