2025-07-30 22:38:44 +07:00
|
|
|
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
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))),
|
|
|
|
|
totalCount: json["total_count"],
|
|
|
|
|
page: json["page"],
|
|
|
|
|
limit: json["limit"],
|
|
|
|
|
totalPages: 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-08-03 00:35:00 +07:00
|
|
|
price: json["price"],
|
|
|
|
|
cost: json["cost"],
|
|
|
|
|
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-08-03 00:35:00 +07:00
|
|
|
price: 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"],
|
|
|
|
|
price: json["price"],
|
2025-08-03 00:35:00 +07:00
|
|
|
cost: json["cost"],
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool operator ==(covariant Product other) {
|
|
|
|
|
if (identical(this, other)) return true;
|
|
|
|
|
|
|
|
|
|
return other.id == id &&
|
2025-08-03 00:35:00 +07:00
|
|
|
other.organizationId == organizationId &&
|
2025-07-30 22:38:44 +07:00
|
|
|
other.categoryId == categoryId &&
|
2025-08-03 00:35:00 +07:00
|
|
|
other.sku == sku &&
|
2025-07-30 22:38:44 +07:00
|
|
|
other.name == name &&
|
|
|
|
|
other.description == description &&
|
|
|
|
|
other.price == price &&
|
2025-08-03 00:35:00 +07:00
|
|
|
other.cost == cost &&
|
|
|
|
|
other.businessType == businessType &&
|
2025-08-03 01:00:33 +07:00
|
|
|
other.imageUrl == imageUrl &&
|
|
|
|
|
other.printerType == printerType &&
|
2025-08-03 00:35:00 +07:00
|
|
|
other.metadata == metadata &&
|
|
|
|
|
other.isActive == isActive &&
|
2025-07-30 22:38:44 +07:00
|
|
|
other.createdAt == createdAt &&
|
|
|
|
|
other.updatedAt == updatedAt &&
|
2025-08-03 00:35:00 +07:00
|
|
|
_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;
|
2025-07-30 22:38:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
int get hashCode {
|
|
|
|
|
return id.hashCode ^
|
2025-08-03 00:35:00 +07:00
|
|
|
organizationId.hashCode ^
|
2025-07-30 22:38:44 +07:00
|
|
|
categoryId.hashCode ^
|
2025-08-03 00:35:00 +07:00
|
|
|
sku.hashCode ^
|
2025-07-30 22:38:44 +07:00
|
|
|
name.hashCode ^
|
|
|
|
|
description.hashCode ^
|
|
|
|
|
price.hashCode ^
|
2025-08-03 00:35:00 +07:00
|
|
|
cost.hashCode ^
|
|
|
|
|
businessType.hashCode ^
|
2025-08-03 01:00:33 +07:00
|
|
|
imageUrl.hashCode ^
|
|
|
|
|
printerType.hashCode ^
|
2025-08-03 00:35:00 +07:00
|
|
|
metadata.hashCode ^
|
|
|
|
|
isActive.hashCode ^
|
2025-07-30 22:38:44 +07:00
|
|
|
createdAt.hashCode ^
|
|
|
|
|
updatedAt.hashCode ^
|
2025-08-03 00:35:00 +07:00
|
|
|
variants.hashCode;
|
2025-07-30 22:38:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Product copyWith({
|
2025-08-03 00:35:00 +07:00
|
|
|
String? id,
|
|
|
|
|
String? organizationId,
|
|
|
|
|
String? categoryId,
|
|
|
|
|
String? sku,
|
2025-07-30 22:38:44 +07:00
|
|
|
String? name,
|
|
|
|
|
String? description,
|
2025-08-03 00:35:00 +07:00
|
|
|
int? price,
|
|
|
|
|
int? cost,
|
|
|
|
|
String? businessType,
|
2025-08-03 01:00:33 +07:00
|
|
|
String? imageUrl,
|
|
|
|
|
String? printerType,
|
2025-08-03 00:35:00 +07:00
|
|
|
Map<String, dynamic>? metadata,
|
|
|
|
|
bool? isActive,
|
2025-07-30 22:38:44 +07:00
|
|
|
DateTime? createdAt,
|
|
|
|
|
DateTime? updatedAt,
|
2025-08-03 00:35:00 +07:00
|
|
|
List<ProductVariant>? variants,
|
2025-07-30 22:38:44 +07:00
|
|
|
}) {
|
|
|
|
|
return Product(
|
|
|
|
|
id: id ?? this.id,
|
2025-08-03 00:35:00 +07:00
|
|
|
organizationId: organizationId ?? this.organizationId,
|
2025-07-30 22:38:44 +07:00
|
|
|
categoryId: categoryId ?? this.categoryId,
|
2025-08-03 00:35:00 +07:00
|
|
|
sku: sku ?? this.sku,
|
2025-07-30 22:38:44 +07:00
|
|
|
name: name ?? this.name,
|
|
|
|
|
description: description ?? this.description,
|
|
|
|
|
price: price ?? this.price,
|
2025-08-03 00:35:00 +07:00
|
|
|
cost: cost ?? this.cost,
|
|
|
|
|
businessType: businessType ?? this.businessType,
|
2025-08-03 01:00:33 +07:00
|
|
|
imageUrl: imageUrl ?? this.imageUrl,
|
|
|
|
|
printerType: printerType ?? this.printerType,
|
2025-08-03 00:35:00 +07:00
|
|
|
metadata: metadata ?? this.metadata,
|
|
|
|
|
isActive: isActive ?? this.isActive,
|
2025-07-30 22:38:44 +07:00
|
|
|
createdAt: createdAt ?? this.createdAt,
|
|
|
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
2025-08-03 00:35:00 +07:00
|
|
|
variants: variants ?? this.variants,
|
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(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
}
|
|
|
|
|
}
|
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"],
|
|
|
|
|
priceModifier: json["price_modifier"],
|
|
|
|
|
cost: json["cost"],
|
|
|
|
|
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(),
|
|
|
|
|
};
|
|
|
|
|
}
|