OP
Size: a a a
OP
M
OP
M
U
class CartModel {
String userId;
String warehouseId;
String total;
String subtotal;
bool isActive;
List<CartProducts> cartProducts;
CartModel(
{this.userId,
this.warehouseId,
this.total,
this.subtotal,
this.isActive,
this.cartProducts});
CartModel.fromJson(Map<String, dynamic> json) {
userId = json['user_id'];
warehouseId = json['warehouse_id'];
total = json['total'];
subtotal = json['subtotal'];
isActive = json['is_active'];
if (json['cart_products'] != null) {
cartProducts = new List<CartProducts>();
json['cart_products'].forEach((v) {
cartProducts.add(new CartProducts.fromJson(v));
});
}
}
U
class CartModel {
String userId;
String warehouseId;
String total;
String subtotal;
bool isActive;
List<CartProducts> cartProducts;
CartModel(
{this.userId,
this.warehouseId,
this.total,
this.subtotal,
this.isActive,
this.cartProducts});
CartModel.fromJson(Map<String, dynamic> json) {
userId = json['user_id'];
warehouseId = json['warehouse_id'];
total = json['total'];
subtotal = json['subtotal'];
isActive = json['is_active'];
if (json['cart_products'] != null) {
cartProducts = new List<CartProducts>();
json['cart_products'].forEach((v) {
cartProducts.add(new CartProducts.fromJson(v));
});
}
}
RC
U
[
{
"user_id": "dao",
"warehouse_id": "Sardoba",
"total": "2395355.000",
"subtotal": "0.000",
"is_active": false,
"cart_products": [
{
"cart_id": 2,
"quantity": 14,
"product": {
"id": 4,
"name": "Jesco 250gr",
"product_image": [
"/media/all_image/macbook_pro.jpeg"
],
"our_price": "1342.00",
"category": "Juise",
"product_quantity_type": "BLOK",
"quantity": 12
}
},
{
"cart_id": 2,
"quantity": 69,
"product": {
"id": 5,
"name": "Energetic JB",
"product_image": [
"/media/all_image/macbook_pro_2_grYzEMB.jpeg"
],
"our_price": "34443.00",
"category": "Energetic",
"product_quantity_type": "BLOK",
"quantity": 12
}
}
]
}
]
U
U
class CartModel {
String userId;
String warehouseId;
String total;
String subtotal;
bool isActive;
List<CartProducts> cartProducts;
CartModel(
{this.userId,
this.warehouseId,
this.total,
this.subtotal,
this.isActive,
this.cartProducts});
CartModel.fromJson(Map<String, dynamic> json) {
userId = json['user_id'];
warehouseId = json['warehouse_id'];
total = json['total'];
subtotal = json['subtotal'];
isActive = json['is_active'];
if (json['cart_products'] != null) {
cartProducts = new List<CartProducts>();
json['cart_products'].forEach((v) {
cartProducts.add(new CartProducts.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['user_id'] = this.userId;
data['warehouse_id'] = this.warehouseId;
data['total'] = this.total;
data['subtotal'] = this.subtotal;
data['is_active'] = this.isActive;
if (this.cartProducts != null) {
data['cart_products'] = this.cartProducts.map((v) => v.toJson()).toList();
}
return data;
}
}
class CartProducts {
int cartId;
int quantity;
Product product;
CartProducts({this.cartId, this.quantity, this.product});
CartProducts.fromJson(Map<String, dynamic> json) {
cartId = json['cart_id'];
quantity = json['quantity'];
product =
json['product'] != null ? new Product.fromJson(json['product']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['cart_id'] = this.cartId;
data['quantity'] = this.quantity;
if (this.product != null) {
data['product'] = this.product.toJson();
}
return data;
}
}
class Product {
int id;
String name;
List<String> productImage;
String ourPrice;
String category;
String productQuantityType;
int quantity;
Product(
{this.id,
this.name,
this.productImage,
this.ourPrice,
this.category,
this.productQuantityType,
this.quantity});
Product.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
productImage = json['product_image'].cast<String>();
ourPrice = json['our_price'];
category = json['category'];
productQuantityType = json['product_quantity_type'];
quantity = json['quantity'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['name'] = this.name;
data['product_image'] = this.productImage;
data['our_price'] = this.ourPrice;
data['category'] = this.category;
data['product_quantity_type'] = this.productQuantityType;
data['quantity'] = this.quantity;
return data;
}
}
С
RC
[
{
"user_id": "dao",
"warehouse_id": "Sardoba",
"total": "2395355.000",
"subtotal": "0.000",
"is_active": false,
"cart_products": [
{
"cart_id": 2,
"quantity": 14,
"product": {
"id": 4,
"name": "Jesco 250gr",
"product_image": [
"/media/all_image/macbook_pro.jpeg"
],
"our_price": "1342.00",
"category": "Juise",
"product_quantity_type": "BLOK",
"quantity": 12
}
},
{
"cart_id": 2,
"quantity": 69,
"product": {
"id": 5,
"name": "Energetic JB",
"product_image": [
"/media/all_image/macbook_pro_2_grYzEMB.jpeg"
],
"our_price": "34443.00",
"category": "Energetic",
"product_quantity_type": "BLOK",
"quantity": 12
}
}
]
}
]
U
Future<CartModel> fetchData() async {
Map<String, String> headers = {
"Authorization": "Token 0136756a8a68a572b6426202c9c5d936cbee61",
};
final response = await http.get(Constans.cart_list,headers: headers);
if (response.statusCode == 200) {
return CartModel.fromJson(json.decode(response.body));
} else {
var responseJson2 = utf8.decode(response.bodyBytes);
print(responseJson2);
}
}
U
FutureBuilder<CartModel>(
future: cartModel,
builder: (context, snapshot) {
if (snapshot.hasError) print("error ... ${snapshot.error}");
return snapshot.hasData
? ListCart(cartProduct: snapshot.data.cartProducts)
: Center(
child: CircularProgressIndicator(
valueColor:
new AlwaysStoppedAnimation<Color>(Colors.green),
));
},
)
U
Future<CartModel> cartModel;
@override
void initState() {
super.initState();
cartModel = fetchData();
}
У
П
lf
Ю