2025-07-30 22:38:44 +07:00
|
|
|
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
2025-09-03 12:15:43 +07:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 22:38:44 +07:00
|
|
|
class ProductResponseModel {
|
2025-08-03 00:35:00 +07:00
|
|
|
final bool? success;
|
|
|
|
|
final ProductData? data;
|
|
|
|
|
final dynamic errors;
|
2025-07-30 22:38:44 +07:00
|
|
|
|
|
|
|
|
ProductResponseModel({
|
2025-08-03 00:35:00 +07:00
|
|
|
this.success,
|
2025-07-30 22:38:44 +07:00
|
|
|
this.data,
|
2025-08-03 00:35:00 +07:00
|
|
|
this.errors,
|
2025-07-30 22:38:44 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory ProductResponseModel.fromJson(String str) =>
|
|
|
|
|
ProductResponseModel.fromMap(json.decode(str));
|
|
|
|
|
|
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
|
|
|
|
|
factory ProductResponseModel.fromMap(Map<String, dynamic> json) =>
|
|
|
|
|
ProductResponseModel(
|
2025-08-03 00:35:00 +07:00
|
|
|
success: json["success"],
|
|
|
|
|
data: json["data"] == null ? null : ProductData.fromMap(json["data"]),
|
|
|
|
|
errors: json["errors"],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
|
|
|
"success": success,
|
|
|
|
|
"data": data?.toMap(),
|
|
|
|
|
"errors": errors,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ProductData {
|
|
|
|
|
final List<Product>? products;
|
|
|
|
|
final int? totalCount;
|
|
|
|
|
final int? page;
|
|
|
|
|
final int? limit;
|
|
|
|
|
final int? totalPages;
|
|
|
|
|
|
|
|
|
|
ProductData({
|
|
|
|
|
this.products,
|
|
|
|
|
this.totalCount,
|
|
|
|
|
this.page,
|
|
|
|
|
this.limit,
|
|
|
|
|
this.totalPages,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory ProductData.fromMap(Map<String, dynamic> json) => ProductData(
|
|
|
|
|
products: json["products"] == null
|
2025-07-30 22:38:44 +07:00
|
|
|
? []
|
2025-08-03 00:35:00 +07:00
|
|
|
: List<Product>.from(
|
|
|
|
|
json["products"].map((x) => Product.fromMap(x))),
|
2025-09-03 12:15:43 +07:00
|
|
|
totalCount: parseInt(json["total_count"]),
|
|
|
|
|
page: parseInt(json["page"]),
|
|
|
|
|
limit: parseInt(json["limit"]),
|
|
|
|
|
totalPages: parseInt(json["total_pages"]),
|
2025-07-30 22:38:44 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
2025-08-03 00:35:00 +07:00
|
|
|
"products": products == null
|
|
|
|
|
? []
|
|
|
|
|
: List<dynamic>.from(products!.map((x) => x.toMap())),
|
|
|
|
|
"total_count": totalCount,
|
|
|
|
|
"page": page,
|
|
|
|
|
"limit": limit,
|
|
|
|
|
"total_pages": totalPages,
|
2025-07-30 22:38:44 +07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Product {
|
2025-08-03 00:35:00 +07:00
|
|
|
final String? id;
|
|
|
|
|
final String? organizationId;
|
|
|
|
|
final String? categoryId;
|
|
|
|
|
final String? sku;
|
2025-07-30 22:38:44 +07:00
|
|
|
final String? name;
|
|
|
|
|
final String? description;
|
2025-08-03 00:35:00 +07:00
|
|
|
final int? price;
|
|
|
|
|
final int? cost;
|
|
|
|
|
final String? businessType;
|
2025-08-03 01:00:33 +07:00
|
|
|
final String? imageUrl;
|
|
|
|
|
final String? printerType;
|
2025-08-03 00:35:00 +07:00
|
|
|
final Map<String, dynamic>? metadata;
|
|
|
|
|
final bool? isActive;
|
2025-07-30 22:38:44 +07:00
|
|
|
final DateTime? createdAt;
|
|
|
|
|
final DateTime? updatedAt;
|
2025-08-03 00:35:00 +07:00
|
|
|
final List<ProductVariant>? variants;
|
2025-07-30 22:38:44 +07:00
|
|
|
|
|
|
|
|
Product({
|
|
|
|
|
this.id,
|
2025-08-03 00:35:00 +07:00
|
|
|
this.organizationId,
|
2025-07-30 22:38:44 +07:00
|
|
|
this.categoryId,
|
2025-08-03 00:35:00 +07:00
|
|
|
this.sku,
|
2025-07-30 22:38:44 +07:00
|
|
|
this.name,
|
|
|
|
|
this.description,
|
|
|
|
|
this.price,
|
2025-08-03 00:35:00 +07:00
|
|
|
this.cost,
|
|
|
|
|
this.businessType,
|
2025-08-03 01:00:33 +07:00
|
|
|
this.imageUrl,
|
|
|
|
|
this.printerType,
|
2025-08-03 00:35:00 +07:00
|
|
|
this.metadata,
|
|
|
|
|
this.isActive,
|
2025-07-30 22:38:44 +07:00
|
|
|
this.createdAt,
|
|
|
|
|
this.updatedAt,
|
2025-08-03 00:35:00 +07:00
|
|
|
this.variants,
|
2025-07-30 22:38:44 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory Product.fromJson(String str) => Product.fromMap(json.decode(str));
|
|
|
|
|
|
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
|
|
|
|
|
factory Product.fromMap(Map<String, dynamic> json) => Product(
|
2025-08-03 00:35:00 +07:00
|
|
|
id: json["id"],
|
|
|
|
|
organizationId: json["organization_id"],
|
|
|
|
|
categoryId: json["category_id"],
|
|
|
|
|
sku: json["sku"],
|
2025-07-30 22:38:44 +07:00
|
|
|
name: json["name"],
|
|
|
|
|
description: json["description"],
|
2025-09-03 12:15:43 +07:00
|
|
|
price: parseInt(json["price"]),
|
|
|
|
|
cost: parseInt(json["cost"]),
|
2025-08-03 00:35:00 +07:00
|
|
|
businessType: json["business_type"],
|
2025-08-03 01:00:33 +07:00
|
|
|
imageUrl: json["image_url"],
|
|
|
|
|
printerType: json["printer_type"],
|
2025-08-03 00:35:00 +07:00
|
|
|
metadata: json["metadata"] ?? {},
|
|
|
|
|
isActive: json["is_active"],
|
2025-07-30 22:38:44 +07:00
|
|
|
createdAt: json["created_at"] == null
|
|
|
|
|
? null
|
|
|
|
|
: DateTime.parse(json["created_at"]),
|
|
|
|
|
updatedAt: json["updated_at"] == null
|
|
|
|
|
? null
|
|
|
|
|
: DateTime.parse(json["updated_at"]),
|
2025-08-03 00:35:00 +07:00
|
|
|
variants: json["variants"] == null
|
|
|
|
|
? []
|
|
|
|
|
: List<ProductVariant>.from(
|
|
|
|
|
json["variants"].map((x) => ProductVariant.fromMap(x))),
|
2025-07-30 22:38:44 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
factory Product.fromOrderMap(Map<String, dynamic> json) => Product(
|
|
|
|
|
id: json["id_product"],
|
2025-09-03 12:15:43 +07:00
|
|
|
price: parseInt(json["price"]),
|
2025-07-30 22:38:44 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
factory Product.fromLocalMap(Map<String, dynamic> json) => Product(
|
|
|
|
|
id: json["id"],
|
2025-08-03 00:35:00 +07:00
|
|
|
organizationId: json["organization_id"],
|
|
|
|
|
categoryId: json["category_id"],
|
|
|
|
|
sku: json["sku"],
|
2025-07-30 22:38:44 +07:00
|
|
|
name: json["name"],
|
|
|
|
|
description: json["description"],
|
2025-09-03 12:15:43 +07:00
|
|
|
price: parseInt(json["price"]),
|
|
|
|
|
cost: parseInt(json["cost"]),
|
2025-08-03 00:35:00 +07:00
|
|
|
businessType: json["business_type"],
|
2025-08-03 01:00:33 +07:00
|
|
|
imageUrl: json["image_url"],
|
|
|
|
|
printerType: json["printer_type"],
|
2025-08-03 00:35:00 +07:00
|
|
|
metadata: json["metadata"] ?? {},
|
|
|
|
|
isActive: json["is_active"],
|
|
|
|
|
createdAt: json["created_at"] == null
|
2025-07-30 22:38:44 +07:00
|
|
|
? null
|
2025-08-03 00:35:00 +07:00
|
|
|
: DateTime.parse(json["created_at"]),
|
|
|
|
|
updatedAt: json["updated_at"] == null
|
2025-07-30 22:38:44 +07:00
|
|
|
? null
|
2025-08-03 00:35:00 +07:00
|
|
|
: DateTime.parse(json["updated_at"]),
|
|
|
|
|
variants: json["variants"] == null
|
|
|
|
|
? []
|
|
|
|
|
: List<ProductVariant>.from(
|
|
|
|
|
json["variants"].map((x) => ProductVariant.fromMap(x))),
|
2025-07-30 22:38:44 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toLocalMap() => {
|
2025-08-03 00:35:00 +07:00
|
|
|
"id": id,
|
|
|
|
|
"organization_id": organizationId,
|
|
|
|
|
"category_id": categoryId,
|
|
|
|
|
"sku": sku,
|
2025-07-30 22:38:44 +07:00
|
|
|
"name": name,
|
|
|
|
|
"description": description,
|
2025-08-03 00:35:00 +07:00
|
|
|
"price": price,
|
|
|
|
|
"cost": cost,
|
|
|
|
|
"business_type": businessType,
|
2025-08-03 01:00:33 +07:00
|
|
|
"image_url": imageUrl,
|
|
|
|
|
"printer_type": printerType,
|
2025-08-03 00:35:00 +07:00
|
|
|
"metadata": metadata,
|
|
|
|
|
"is_active": isActive,
|
|
|
|
|
"created_at": createdAt?.toIso8601String(),
|
|
|
|
|
"updated_at": updatedAt?.toIso8601String(),
|
|
|
|
|
"variants": variants == null
|
|
|
|
|
? []
|
|
|
|
|
: List<dynamic>.from(variants!.map((x) => x.toMap())),
|
2025-07-30 22:38:44 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
|
|
|
"id": id,
|
2025-08-03 00:35:00 +07:00
|
|
|
"organization_id": organizationId,
|
2025-07-30 22:38:44 +07:00
|
|
|
"category_id": categoryId,
|
2025-08-03 00:35:00 +07:00
|
|
|
"sku": sku,
|
2025-07-30 22:38:44 +07:00
|
|
|
"name": name,
|
|
|
|
|
"description": description,
|
|
|
|
|
"price": price,
|
2025-08-03 00:35:00 +07:00
|
|
|
"cost": cost,
|
|
|
|
|
"business_type": businessType,
|
2025-08-03 01:00:33 +07:00
|
|
|
"image_url": imageUrl,
|
|
|
|
|
"printer_type": printerType,
|
2025-08-03 00:35:00 +07:00
|
|
|
"metadata": metadata,
|
|
|
|
|
"is_active": isActive,
|
2025-07-30 22:38:44 +07:00
|
|
|
"created_at": createdAt?.toIso8601String(),
|
|
|
|
|
"updated_at": updatedAt?.toIso8601String(),
|
2025-08-03 00:35:00 +07:00
|
|
|
"variants": variants == null
|
|
|
|
|
? []
|
|
|
|
|
: List<dynamic>.from(variants!.map((x) => x.toMap())),
|
2025-07-30 22:38:44 +07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Category {
|
|
|
|
|
final int? id;
|
|
|
|
|
final String? name;
|
|
|
|
|
final String? description;
|
|
|
|
|
final String? image;
|
|
|
|
|
final DateTime? createdAt;
|
|
|
|
|
final DateTime? updatedAt;
|
|
|
|
|
|
|
|
|
|
Category({
|
|
|
|
|
this.id,
|
|
|
|
|
this.name,
|
|
|
|
|
this.description,
|
|
|
|
|
this.image,
|
|
|
|
|
this.createdAt,
|
|
|
|
|
this.updatedAt,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory Category.fromJson(String str) => Category.fromMap(json.decode(str));
|
|
|
|
|
|
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
|
|
|
|
|
factory Category.fromMap(Map<String, dynamic> json) => Category(
|
|
|
|
|
id: json["id"] is String ? int.tryParse(json["id"]) : json["id"],
|
|
|
|
|
name: json["name"],
|
|
|
|
|
description: json["description"],
|
|
|
|
|
image: json["image"],
|
|
|
|
|
createdAt: json["created_at"] == null
|
|
|
|
|
? null
|
|
|
|
|
: DateTime.parse(json["created_at"]),
|
|
|
|
|
updatedAt: json["updated_at"] == null
|
|
|
|
|
? null
|
|
|
|
|
: DateTime.parse(json["updated_at"]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
|
|
|
"id": id,
|
|
|
|
|
"name": name,
|
|
|
|
|
"description": description,
|
|
|
|
|
"image": image,
|
|
|
|
|
"created_at": createdAt?.toIso8601String(),
|
|
|
|
|
"updated_at": updatedAt?.toIso8601String(),
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-08-03 00:35:00 +07:00
|
|
|
|
|
|
|
|
class ProductVariant {
|
|
|
|
|
final String? id;
|
|
|
|
|
final String? productId;
|
|
|
|
|
final String? name;
|
|
|
|
|
final int? priceModifier;
|
|
|
|
|
final int? cost;
|
|
|
|
|
final Map<String, dynamic>? metadata;
|
|
|
|
|
final DateTime? createdAt;
|
|
|
|
|
final DateTime? updatedAt;
|
|
|
|
|
|
|
|
|
|
ProductVariant({
|
|
|
|
|
this.id,
|
|
|
|
|
this.productId,
|
|
|
|
|
this.name,
|
|
|
|
|
this.priceModifier,
|
|
|
|
|
this.cost,
|
|
|
|
|
this.metadata,
|
|
|
|
|
this.createdAt,
|
|
|
|
|
this.updatedAt,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory ProductVariant.fromMap(Map<String, dynamic> json) => ProductVariant(
|
|
|
|
|
id: json["id"],
|
|
|
|
|
productId: json["product_id"],
|
|
|
|
|
name: json["name"],
|
2025-09-03 12:15:43 +07:00
|
|
|
priceModifier: parseInt(json["price_modifier"]),
|
|
|
|
|
cost: parseInt(json["cost"]),
|
2025-08-03 00:35:00 +07:00
|
|
|
metadata: json["metadata"] ?? {},
|
|
|
|
|
createdAt: json["created_at"] == null
|
|
|
|
|
? null
|
|
|
|
|
: DateTime.parse(json["created_at"]),
|
|
|
|
|
updatedAt: json["updated_at"] == null
|
|
|
|
|
? null
|
|
|
|
|
: DateTime.parse(json["updated_at"]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
|
|
|
"id": id,
|
|
|
|
|
"product_id": productId,
|
|
|
|
|
"name": name,
|
|
|
|
|
"price_modifier": priceModifier,
|
|
|
|
|
"cost": cost,
|
|
|
|
|
"metadata": metadata,
|
|
|
|
|
"created_at": createdAt?.toIso8601String(),
|
|
|
|
|
"updated_at": updatedAt?.toIso8601String(),
|
|
|
|
|
};
|
|
|
|
|
}
|