- http_util.dart: dio4->5 (DioException, nullable params, drop unused statusCode, null-safe e.response!.data), countryCode ?? '' - models/* (39 files): make all instance fields nullable (fromJson initializer-list pattern forces nullable); fix internal method usages (cart_info/cart_line_item/ order/shipping_rate) with !/?? - models/ now passes dart analyze with 0 errors Widget-level null-safety + remaining utils/store continue in next batch.
54 lines
1.3 KiB
Dart
54 lines
1.3 KiB
Dart
|
|
|
|
import 'dart:convert';
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
import 'product.dart';
|
|
|
|
class CartLineItem {
|
|
int? id;
|
|
double? unitPrice;
|
|
double? totalPrice;
|
|
Product? product;
|
|
String? name;
|
|
String? description;
|
|
double? quantity;
|
|
String? uuid;
|
|
String? parentUuid;
|
|
|
|
CartLineItem() {
|
|
uuid = Uuid().v4();
|
|
}
|
|
|
|
CartLineItem.fromJson(Map<String, dynamic> json)
|
|
: id = json['id'],
|
|
unitPrice = double.parse(json['unit_price'].toString()),
|
|
totalPrice = json['total_price'] != null ? double.parse(json['total_price'].toString()) : double.parse(json['unit_price'].toString()) * double.parse(json['quantity'].toString()),
|
|
product = json['product'] != null ? Product.fromJson(json['product']) : null,
|
|
name = json['name'],
|
|
description = json['description'],
|
|
quantity = double.parse(json['quantity'].toString()),
|
|
uuid = Uuid().v4();
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'unit_price': unitPrice,
|
|
'total_price': totalPrice,
|
|
'product': product,
|
|
'name': name,
|
|
'description': description,
|
|
'quantity': quantity,
|
|
'uuid': uuid,
|
|
'parentUuid': parentUuid
|
|
};
|
|
|
|
@override
|
|
String toString() {
|
|
return json.encode(this);
|
|
}
|
|
|
|
double getTotalPrice() {
|
|
totalPrice = (unitPrice ?? 0.0) * (quantity ?? 0);
|
|
return totalPrice ?? 0.0;
|
|
}
|
|
} |