Compare commits
No commits in common. "bd02f389e533360883799f230de1c90957ab70dc" and "6599e6fe7c9b2414cfc63782e226bf7d52cf424b" have entirely different histories.
bd02f389e5
...
6599e6fe7c
@ -70,7 +70,7 @@ Future<void> onPrint(
|
|||||||
.toList();
|
.toList();
|
||||||
final printValue = await PrintDataoutputs.instance.printKitchen(
|
final printValue = await PrintDataoutputs.instance.printKitchen(
|
||||||
productByPrinter,
|
productByPrinter,
|
||||||
order.tableNumber ?? "",
|
order.tableNumber!,
|
||||||
order.orderNumber ?? "",
|
order.orderNumber ?? "",
|
||||||
authData.user?.name ?? "",
|
authData.user?.name ?? "",
|
||||||
order.metadata?['customer_name'] ?? "",
|
order.metadata?['customer_name'] ?? "",
|
||||||
|
|||||||
@ -56,7 +56,7 @@ class ProductRemoteDatasource {
|
|||||||
log("Dio error: ${e.message}");
|
log("Dio error: ${e.message}");
|
||||||
return Left(e.response?.data['message'] ?? 'Gagal mengambil produk');
|
return Left(e.response?.data['message'] ?? 'Gagal mengambil produk');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("Unexpected error: $e", name: "productRemoteDatasource");
|
log("Unexpected error: $e");
|
||||||
return const Left('Unexpected error occurred');
|
return const Left('Unexpected error occurred');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,6 @@
|
|||||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
int? parseInt(dynamic value) {
|
|
||||||
if (value == null) return null;
|
|
||||||
if (value is int) return value;
|
|
||||||
if (value is double) return value.toInt();
|
|
||||||
if (value is String) return int.tryParse(value);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProductResponseModel {
|
class ProductResponseModel {
|
||||||
final bool? success;
|
final bool? success;
|
||||||
final ProductData? data;
|
final ProductData? data;
|
||||||
@ -59,10 +51,10 @@ class ProductData {
|
|||||||
? []
|
? []
|
||||||
: List<Product>.from(
|
: List<Product>.from(
|
||||||
json["products"].map((x) => Product.fromMap(x))),
|
json["products"].map((x) => Product.fromMap(x))),
|
||||||
totalCount: parseInt(json["total_count"]),
|
totalCount: json["total_count"],
|
||||||
page: parseInt(json["page"]),
|
page: json["page"],
|
||||||
limit: parseInt(json["limit"]),
|
limit: json["limit"],
|
||||||
totalPages: parseInt(json["total_pages"]),
|
totalPages: json["total_pages"],
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> toMap() => {
|
Map<String, dynamic> toMap() => {
|
||||||
@ -124,8 +116,8 @@ class Product {
|
|||||||
sku: json["sku"],
|
sku: json["sku"],
|
||||||
name: json["name"],
|
name: json["name"],
|
||||||
description: json["description"],
|
description: json["description"],
|
||||||
price: parseInt(json["price"]),
|
price: json["price"],
|
||||||
cost: parseInt(json["cost"]),
|
cost: json["cost"],
|
||||||
businessType: json["business_type"],
|
businessType: json["business_type"],
|
||||||
imageUrl: json["image_url"],
|
imageUrl: json["image_url"],
|
||||||
printerType: json["printer_type"],
|
printerType: json["printer_type"],
|
||||||
@ -145,7 +137,7 @@ class Product {
|
|||||||
|
|
||||||
factory Product.fromOrderMap(Map<String, dynamic> json) => Product(
|
factory Product.fromOrderMap(Map<String, dynamic> json) => Product(
|
||||||
id: json["id_product"],
|
id: json["id_product"],
|
||||||
price: parseInt(json["price"]),
|
price: json["price"],
|
||||||
);
|
);
|
||||||
|
|
||||||
factory Product.fromLocalMap(Map<String, dynamic> json) => Product(
|
factory Product.fromLocalMap(Map<String, dynamic> json) => Product(
|
||||||
@ -155,8 +147,8 @@ class Product {
|
|||||||
sku: json["sku"],
|
sku: json["sku"],
|
||||||
name: json["name"],
|
name: json["name"],
|
||||||
description: json["description"],
|
description: json["description"],
|
||||||
price: parseInt(json["price"]),
|
price: json["price"],
|
||||||
cost: parseInt(json["cost"]),
|
cost: json["cost"],
|
||||||
businessType: json["business_type"],
|
businessType: json["business_type"],
|
||||||
imageUrl: json["image_url"],
|
imageUrl: json["image_url"],
|
||||||
printerType: json["printer_type"],
|
printerType: json["printer_type"],
|
||||||
@ -215,6 +207,96 @@ class Product {
|
|||||||
? []
|
? []
|
||||||
: List<dynamic>.from(variants!.map((x) => x.toMap())),
|
: List<dynamic>.from(variants!.map((x) => x.toMap())),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(covariant Product other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other.id == id &&
|
||||||
|
other.organizationId == organizationId &&
|
||||||
|
other.categoryId == categoryId &&
|
||||||
|
other.sku == sku &&
|
||||||
|
other.name == name &&
|
||||||
|
other.description == description &&
|
||||||
|
other.price == price &&
|
||||||
|
other.cost == cost &&
|
||||||
|
other.businessType == businessType &&
|
||||||
|
other.imageUrl == imageUrl &&
|
||||||
|
other.printerType == printerType &&
|
||||||
|
other.metadata == metadata &&
|
||||||
|
other.isActive == isActive &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.updatedAt == updatedAt &&
|
||||||
|
_listEquals(other.variants, variants);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _listEquals(List<ProductVariant>? a, List<ProductVariant>? b) {
|
||||||
|
if (a == null && b == null) return true;
|
||||||
|
if (a == null || b == null) return false;
|
||||||
|
if (a.length != b.length) return false;
|
||||||
|
for (int i = 0; i < a.length; i++) {
|
||||||
|
if (a[i] != b[i]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return id.hashCode ^
|
||||||
|
organizationId.hashCode ^
|
||||||
|
categoryId.hashCode ^
|
||||||
|
sku.hashCode ^
|
||||||
|
name.hashCode ^
|
||||||
|
description.hashCode ^
|
||||||
|
price.hashCode ^
|
||||||
|
cost.hashCode ^
|
||||||
|
businessType.hashCode ^
|
||||||
|
imageUrl.hashCode ^
|
||||||
|
printerType.hashCode ^
|
||||||
|
metadata.hashCode ^
|
||||||
|
isActive.hashCode ^
|
||||||
|
createdAt.hashCode ^
|
||||||
|
updatedAt.hashCode ^
|
||||||
|
variants.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Product copyWith({
|
||||||
|
String? id,
|
||||||
|
String? organizationId,
|
||||||
|
String? categoryId,
|
||||||
|
String? sku,
|
||||||
|
String? name,
|
||||||
|
String? description,
|
||||||
|
int? price,
|
||||||
|
int? cost,
|
||||||
|
String? businessType,
|
||||||
|
String? imageUrl,
|
||||||
|
String? printerType,
|
||||||
|
Map<String, dynamic>? metadata,
|
||||||
|
bool? isActive,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
List<ProductVariant>? variants,
|
||||||
|
}) {
|
||||||
|
return Product(
|
||||||
|
id: id ?? this.id,
|
||||||
|
organizationId: organizationId ?? this.organizationId,
|
||||||
|
categoryId: categoryId ?? this.categoryId,
|
||||||
|
sku: sku ?? this.sku,
|
||||||
|
name: name ?? this.name,
|
||||||
|
description: description ?? this.description,
|
||||||
|
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,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
|
variants: variants ?? this.variants,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Category {
|
class Category {
|
||||||
@ -259,6 +341,28 @@ class Category {
|
|||||||
"created_at": createdAt?.toIso8601String(),
|
"created_at": createdAt?.toIso8601String(),
|
||||||
"updated_at": updatedAt?.toIso8601String(),
|
"updated_at": updatedAt?.toIso8601String(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(covariant Category other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other.id == id &&
|
||||||
|
other.name == name &&
|
||||||
|
other.description == description &&
|
||||||
|
other.image == image &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.updatedAt == updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return id.hashCode ^
|
||||||
|
name.hashCode ^
|
||||||
|
description.hashCode ^
|
||||||
|
image.hashCode ^
|
||||||
|
createdAt.hashCode ^
|
||||||
|
updatedAt.hashCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProductVariant {
|
class ProductVariant {
|
||||||
@ -286,8 +390,8 @@ class ProductVariant {
|
|||||||
id: json["id"],
|
id: json["id"],
|
||||||
productId: json["product_id"],
|
productId: json["product_id"],
|
||||||
name: json["name"],
|
name: json["name"],
|
||||||
priceModifier: parseInt(json["price_modifier"]),
|
priceModifier: json["price_modifier"],
|
||||||
cost: parseInt(json["cost"]),
|
cost: json["cost"],
|
||||||
metadata: json["metadata"] ?? {},
|
metadata: json["metadata"] ?? {},
|
||||||
createdAt: json["created_at"] == null
|
createdAt: json["created_at"] == null
|
||||||
? null
|
? null
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user