diff --git a/lib/models/Subproduct.dart b/lib/models/Subproduct.dart index fcbdab7..515b022 100644 --- a/lib/models/Subproduct.dart +++ b/lib/models/Subproduct.dart @@ -4,9 +4,9 @@ import 'dart:convert'; import 'package:flutter_wisetronic/models/product_attribute.dart'; class Subproduct { - int id; - SimpleProduct product; - double quantity; + int? id; + SimpleProduct? product; + double? quantity; Subproduct.fromJson(Map json) : id = json['id'], @@ -26,15 +26,15 @@ class Subproduct { } class SimpleProduct { - int id; - String name; - String sku; - double price; - String description; - String image; - List productAttributes; - double customerLastPrice; - String extraData; + int? id; + String? name; + String? sku; + double? price; + String? description; + String? image; + List? productAttributes; + double? customerLastPrice; + String? extraData; SimpleProduct.fromJson(Map json) : id = json['id'], diff --git a/lib/models/address.dart b/lib/models/address.dart index ffd7ec3..e9ac611 100644 --- a/lib/models/address.dart +++ b/lib/models/address.dart @@ -1,21 +1,21 @@ import 'dart:convert'; class Address { - int id; - String addressLine1; - String addressLine2; - String city; - String state; - String country; - String zip; - String phone; - String fax; - String email; - String contactName; - int gender; - String lat; - String lng; - String fullAddress; + int? id; + String? addressLine1; + String? addressLine2; + String? city; + String? state; + String? country; + String? zip; + String? phone; + String? fax; + String? email; + String? contactName; + int? gender; + String? lat; + String? lng; + String? fullAddress; Address.fromJson(Map json) : id = json['id'], diff --git a/lib/models/blog.dart b/lib/models/blog.dart index 538a5fb..6dc9acf 100644 --- a/lib/models/blog.dart +++ b/lib/models/blog.dart @@ -2,8 +2,8 @@ import 'dart:convert'; class Section { - int id; - String name; + int? id; + String? name; Section.fromJson(Map json) : id = json['id'], @@ -21,14 +21,14 @@ class Section { } class Blog { - int id; - String title; - String body; - String createdAt; - String thumbUrl; - String imageUrl; - String videoUrl; - Section section; + int? id; + String? title; + String? body; + String? createdAt; + String? thumbUrl; + String? imageUrl; + String? videoUrl; + Section? section; Blog.fromJson(Map json) : id = json['id'], diff --git a/lib/models/booking_date_time.dart b/lib/models/booking_date_time.dart index f9cb071..13f5710 100644 --- a/lib/models/booking_date_time.dart +++ b/lib/models/booking_date_time.dart @@ -4,10 +4,10 @@ import 'dart:convert'; import 'booking_time.dart'; class BookingDateTime { - String viewDate; - int unixTime; - String sendTimeTip; - List bookTimes; + String? viewDate; + int? unixTime; + String? sendTimeTip; + List? bookTimes; BookingDateTime(this.viewDate, this.unixTime, this.sendTimeTip, this.bookTimes); diff --git a/lib/models/booking_time.dart b/lib/models/booking_time.dart index 9f4c055..becb51e 100644 --- a/lib/models/booking_time.dart +++ b/lib/models/booking_time.dart @@ -2,9 +2,9 @@ import 'dart:convert'; class BookingTime { - String viewTime; - int unixTime; - String sendTimeTip; + String? viewTime; + int? unixTime; + String? sendTimeTip; BookingTime(this.viewTime, this.unixTime, this.sendTimeTip); diff --git a/lib/models/business.dart b/lib/models/business.dart index d6e1bd0..9286c5d 100644 --- a/lib/models/business.dart +++ b/lib/models/business.dart @@ -8,7 +8,7 @@ import 'product.dart'; import 'waiting_line.dart'; class QuickInput { - String value; + String? value; QuickInput.fromJson(Map json) : value = json['value']; @@ -23,48 +23,48 @@ class QuickInput { } class Business { - int id; - String name; - String phone; - Address address; - String fullAddress; - String picUrl; - int status; - List openingTime; - double shippingFee; - double packageFee; - double minPrice; - int shippingTime; - int monthSales; - String bulletin; - int category; - bool isLike; - String description; - String policy; - String bannerImageUrl; - int todayOpen; - int todayClose; - bool showMonthlySold; - List slideImages; - List promoProducts; - String paypalEmail; - bool deliveryCanadaPost; - bool deliveryStoreDelivery; - bool deliveryPickup; - String currency; - List waitingLine; - bool enableWaitingLine; - double pointsToCreditsConversionRate; - String chaseXLogin; - String chaseTransactionKey; - String chaseResponseKey; - DistanceInfo distanceInfo; - int commentsCount; - bool forceClose; - bool isPublic; - double referrerCoupon; - bool instanceDelivery; - List quickInputs; + int? id; + String? name; + String? phone; + Address? address; + String? fullAddress; + String? picUrl; + int? status; + List? openingTime; + double? shippingFee; + double? packageFee; + double? minPrice; + int? shippingTime; + int? monthSales; + String? bulletin; + int? category; + bool? isLike; + String? description; + String? policy; + String? bannerImageUrl; + int? todayOpen; + int? todayClose; + bool? showMonthlySold; + List? slideImages; + List? promoProducts; + String? paypalEmail; + bool? deliveryCanadaPost; + bool? deliveryStoreDelivery; + bool? deliveryPickup; + String? currency; + List? waitingLine; + bool? enableWaitingLine; + double? pointsToCreditsConversionRate; + String? chaseXLogin; + String? chaseTransactionKey; + String? chaseResponseKey; + DistanceInfo? distanceInfo; + int? commentsCount; + bool? forceClose; + bool? isPublic; + double? referrerCoupon; + bool? instanceDelivery; + List? quickInputs; Business.fromJson(Map json) : id = json['id'], diff --git a/lib/models/business_time.dart b/lib/models/business_time.dart index 3247474..8a883e3 100644 --- a/lib/models/business_time.dart +++ b/lib/models/business_time.dart @@ -1,8 +1,8 @@ import 'dart:convert'; class BusinessTime { - String openTime; - String closeTime; + String? openTime; + String? closeTime; BusinessTime.fromJson(Map json) : openTime = json['open_time'], diff --git a/lib/models/cart_info.dart b/lib/models/cart_info.dart index 4516a53..0ef4b58 100644 --- a/lib/models/cart_info.dart +++ b/lib/models/cart_info.dart @@ -7,18 +7,18 @@ import 'cart_line_item.dart'; import 'extra_fee.dart'; class CartInfo { - int id; - double originPrice; - double discountPrice; - double totalPrice; - Business businessInfo; - List productList; - List extraFeeList; - List discountList; - int deliveryMethod; - String shippingMethod; - double amountPaid; - String extraData; + int? id; + double? originPrice; + double? discountPrice; + double? totalPrice; + Business? businessInfo; + List? productList; + List? extraFeeList; + List? discountList; + int? deliveryMethod; + String? shippingMethod; + double? amountPaid; + String? extraData; CartInfo.fromJson(Map json) : id = json['id'], @@ -53,7 +53,7 @@ class CartInfo { if (productList == null) { productList = [item]; } else { - productList.add(item); + productList!.add(item); } } @@ -74,19 +74,19 @@ class CartInfo { originPrice = 0.0; discountPrice = 0.0; totalPrice = 0.0; - for (var i = 0; i < productList.length; i++) { - newTotal += productList[i].getTotalPrice(); + for (var i = 0; i < (productList?.length ?? 0); i++) { + newTotal += productList![i].getTotalPrice(); } originPrice = newTotal; totalPrice = newTotal; - return totalPrice; + return totalPrice ?? 0.0; } int getProductListTotalQuantity() { int qty = 0; - if (productList != null && productList.length > 0) { - for (var i = 0; i < productList.length; i++) { - qty += productList[i].quantity.round(); + if (productList != null && productList!.length > 0) { + for (var i = 0; i < productList!.length; i++) { + qty += (productList![i].quantity ?? 0).round(); } } return qty; diff --git a/lib/models/cart_line_item.dart b/lib/models/cart_line_item.dart index 5adb0ec..6865707 100644 --- a/lib/models/cart_line_item.dart +++ b/lib/models/cart_line_item.dart @@ -6,15 +6,15 @@ 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; + int? id; + double? unitPrice; + double? totalPrice; + Product? product; + String? name; + String? description; + double? quantity; + String? uuid; + String? parentUuid; CartLineItem() { uuid = Uuid().v4(); @@ -48,7 +48,7 @@ class CartLineItem { } double getTotalPrice() { - totalPrice = unitPrice * quantity; - return totalPrice; + totalPrice = (unitPrice ?? 0.0) * (quantity ?? 0); + return totalPrice ?? 0.0; } } \ No newline at end of file diff --git a/lib/models/category.dart b/lib/models/category.dart index 9f41558..faa9a57 100644 --- a/lib/models/category.dart +++ b/lib/models/category.dart @@ -2,8 +2,8 @@ import 'dart:convert'; class Category { - int id; - String name; + int? id; + String? name; Category.fromJson(Map json) : id = json['id'], diff --git a/lib/models/category_products.dart b/lib/models/category_products.dart index f740278..4f32cae 100644 --- a/lib/models/category_products.dart +++ b/lib/models/category_products.dart @@ -4,12 +4,12 @@ import 'dart:convert'; import 'product.dart'; class CategoryProducts { - int id; - int businessId; - String name; - String description; - String iconUrl; - List products; + int? id; + int? businessId; + String? name; + String? description; + String? iconUrl; + List? products; CategoryProducts.fromJson(Map json) : id = json['id'], diff --git a/lib/models/comment.dart b/lib/models/comment.dart index 780dd27..d3bae99 100644 --- a/lib/models/comment.dart +++ b/lib/models/comment.dart @@ -4,15 +4,15 @@ import 'dart:convert'; import 'product_image.dart'; class Comment { - int id; - String contact; - String content; - int rating; - List images; - String createdAt; - int thumbUp; - int thumbDown; - String replyFromStore; + int? id; + String? contact; + String? content; + int? rating; + List? images; + String? createdAt; + int? thumbUp; + int? thumbDown; + String? replyFromStore; Comment.fromJson(Map json) : id = json['id'], diff --git a/lib/models/coupon.dart b/lib/models/coupon.dart index 45ac37b..99e1e49 100644 --- a/lib/models/coupon.dart +++ b/lib/models/coupon.dart @@ -4,14 +4,14 @@ import 'dart:convert'; import 'business.dart'; class Coupon { - int id; - String code; - String description; - String expirationDate; - double minAmount; - Business store; - double valueAmount; - bool isPercentage; + int? id; + String? code; + String? description; + String? expirationDate; + double? minAmount; + Business? store; + double? valueAmount; + bool? isPercentage; Coupon.fromJson(Map json) : id = json['id'], diff --git a/lib/models/distance_info.dart b/lib/models/distance_info.dart index 96cad60..2a6ca6f 100644 --- a/lib/models/distance_info.dart +++ b/lib/models/distance_info.dart @@ -4,9 +4,9 @@ import 'dart:convert'; import 'text_value.dart'; class DistanceInfo { - TextValue duration; - TextValue distance; - String status; + TextValue? duration; + TextValue? distance; + String? status; DistanceInfo.fromJson(Map json) : duration = json['duration'] != null ? TextValue.fromJson(json['duration']) : null, diff --git a/lib/models/error_message.dart b/lib/models/error_message.dart index e99e64e..5771a97 100644 --- a/lib/models/error_message.dart +++ b/lib/models/error_message.dart @@ -2,8 +2,8 @@ import 'dart:convert'; class ErrorMessage { - String code; - String string; + String? code; + String? string; ErrorMessage.fromJson(Map json) : code = json['code'], diff --git a/lib/models/extra_fee.dart b/lib/models/extra_fee.dart index 65f85df..c7334b4 100644 --- a/lib/models/extra_fee.dart +++ b/lib/models/extra_fee.dart @@ -3,11 +3,11 @@ import 'dart:convert'; class ExtraFee { - int id; - String name; - String description; - double rate; - double price; + int? id; + String? name; + String? description; + double? rate; + double? price; ExtraFee.fromJson(Map json) : id = json['id'], diff --git a/lib/models/fulfillment.dart b/lib/models/fulfillment.dart index 5d94fac..d7144e9 100644 --- a/lib/models/fulfillment.dart +++ b/lib/models/fulfillment.dart @@ -2,11 +2,11 @@ import 'dart:convert'; class Fulfillment { - int id; - String shippingMethod; - String trackingNumber; - String note; - String createdAt; + int? id; + String? shippingMethod; + String? trackingNumber; + String? note; + String? createdAt; Fulfillment.fromJson(Map json) : id = json['id'], diff --git a/lib/models/gallery.dart b/lib/models/gallery.dart index 47358d1..05a8dcc 100644 --- a/lib/models/gallery.dart +++ b/lib/models/gallery.dart @@ -2,9 +2,9 @@ import 'dart:convert'; class Gallery { - int id; - String image; - String linkUrl; + int? id; + String? image; + String? linkUrl; Gallery.fromJson(Map json) : id = json['id'], diff --git a/lib/models/group.dart b/lib/models/group.dart index 22be707..9f1be95 100644 --- a/lib/models/group.dart +++ b/lib/models/group.dart @@ -3,8 +3,8 @@ import 'dart:convert'; class Group { - int id; - String name; + int? id; + String? name; Group.fromJson(Map json) : id = json['id'], diff --git a/lib/models/image_url.dart b/lib/models/image_url.dart index 62599c1..210bb1a 100644 --- a/lib/models/image_url.dart +++ b/lib/models/image_url.dart @@ -1,8 +1,8 @@ import 'dart:convert'; class ImageUrl { - int id; - String imageUrl; + int? id; + String? imageUrl; ImageUrl.fromJson(Map json) : id = json['id'], diff --git a/lib/models/key_value.dart b/lib/models/key_value.dart index 333271c..79f8916 100644 --- a/lib/models/key_value.dart +++ b/lib/models/key_value.dart @@ -1,7 +1,7 @@ class KeyValue { - String name; - dynamic value; + String? name; + dynamic? value; KeyValue(this.name, this.value); diff --git a/lib/models/located_address.dart b/lib/models/located_address.dart index 1f9dd24..2b77fcd 100644 --- a/lib/models/located_address.dart +++ b/lib/models/located_address.dart @@ -1,17 +1,17 @@ import 'dart:convert'; class LocatedAddress { - int storeId; - double latitude; - double longitude; - String streetNumber; - String streetName; - String city; - String locality; - String province; - String country; - String postalCode; - String formattedAddress; + int? storeId; + double? latitude; + double? longitude; + String? streetNumber; + String? streetName; + String? city; + String? locality; + String? province; + String? country; + String? postalCode; + String? formattedAddress; LocatedAddress.fromJson(Map json) : storeId = json['store_id'], diff --git a/lib/models/order.dart b/lib/models/order.dart index 9528d3b..aa93947 100644 --- a/lib/models/order.dart +++ b/lib/models/order.dart @@ -11,33 +11,33 @@ import 'fulfillment.dart'; import 'user_position.dart'; class Order { - int id; - int userId; - int businessId; - Business businessInfo; - CartInfo cartInfo; - int status; - double originPrice; - double discountPrice; - double totalPrice; - String consignee; - String phone; - String address; - Address shippingAddress; - int payMethod; - String remark; - String orderNum; - int bookedAt; - int createdAt; - String shippingMethod; + int? id; + int? userId; + int? businessId; + Business? businessInfo; + CartInfo? cartInfo; + int? status; + double? originPrice; + double? discountPrice; + double? totalPrice; + String? consignee; + String? phone; + String? address; + Address? shippingAddress; + int? payMethod; + String? remark; + String? orderNum; + int? bookedAt; + int? createdAt; + String? shippingMethod; String paymentStatus; // UNPAID, PAID, PARTIALPAID - double amountPaid; - List fulfillments; - String extraData; - bool hasComment; - double fee; - UserPosition shipperPosition; - DistanceInfo deliveryDistance; + double? amountPaid; + List? fulfillments; + String? extraData; + bool? hasComment; + double? fee; + UserPosition? shipperPosition; + DistanceInfo? deliveryDistance; Order.fromJson(Map json) : id = json['id'], @@ -100,7 +100,7 @@ class Order { double getSubtotal() { double subtotal = 0.0; - for (CartLineItem lineItem in cartInfo.productList) { + for (CartLineItem lineItem in cartInfo?.productList ?? []) { subtotal += lineItem.getTotalPrice(); } return subtotal; diff --git a/lib/models/payment_platform.dart b/lib/models/payment_platform.dart index 5395030..1bdce8a 100644 --- a/lib/models/payment_platform.dart +++ b/lib/models/payment_platform.dart @@ -6,19 +6,19 @@ import 'package:flutter/cupertino.dart'; import '../generated/l10n.dart'; class PaymentPlatform { - int id; - String name; - String code; - String method; - String icon; - String xLogin; - String transactionKey; - String responseKey; - String squareAppId; - String squareAccessToken; - String squareLocationId; - String publishableKey; - String merchantId; + int? id; + String? name; + String? code; + String? method; + String? icon; + String? xLogin; + String? transactionKey; + String? responseKey; + String? squareAppId; + String? squareAccessToken; + String? squareLocationId; + String? publishableKey; + String? merchantId; PaymentPlatform(this.code); diff --git a/lib/models/position.dart b/lib/models/position.dart index 96a202e..aee2fa2 100644 --- a/lib/models/position.dart +++ b/lib/models/position.dart @@ -1,7 +1,7 @@ class Position { - final double latitude; - final double longitude; + final double? latitude; + final double? longitude; Position({this.latitude, this.longitude}); diff --git a/lib/models/product.dart b/lib/models/product.dart index e7ca4d8..049e6e2 100644 --- a/lib/models/product.dart +++ b/lib/models/product.dart @@ -5,23 +5,23 @@ import 'Subproduct.dart'; import 'product_attribute.dart'; class Product { - int id; - int businessId; - int categoryId; - String name; - double price; - double regularPrice; - String description; - String detailDescription; - String imagePath; - String secondImagePath; - double monthSales; - int rate; - double leftNum; - List productAttributes; - bool nonInventory; - String extraData; - List subproducts; + int? id; + int? businessId; + int? categoryId; + String? name; + double? price; + double? regularPrice; + String? description; + String? detailDescription; + String? imagePath; + String? secondImagePath; + double? monthSales; + int? rate; + double? leftNum; + List? productAttributes; + bool? nonInventory; + String? extraData; + List? subproducts; Product(int id, int businessId, String name, double price, String description, String imagePath, List productAttributes) { diff --git a/lib/models/product_attribute.dart b/lib/models/product_attribute.dart index e519a4d..1d403a6 100644 --- a/lib/models/product_attribute.dart +++ b/lib/models/product_attribute.dart @@ -4,14 +4,14 @@ import 'dart:convert'; import 'product_option.dart'; class ProductAttribute { - int id; - String name; - List productOptions; - bool singleSelection; - bool byQuantity; - bool required; - String extra; - bool disabled; + int? id; + String? name; + List? productOptions; + bool? singleSelection; + bool? byQuantity; + bool? required; + String? extra; + bool? disabled; ProductAttribute.fromJson(Map json) : id = json['id'], diff --git a/lib/models/product_detail.dart b/lib/models/product_detail.dart index 2d6f529..74642a4 100644 --- a/lib/models/product_detail.dart +++ b/lib/models/product_detail.dart @@ -8,30 +8,30 @@ import 'product_attribute.dart'; import 'product_image.dart'; class ProductDetail { - int id; - String image; - List images; - String sku; - String name; - double price; - double regularPrice; - String description; - String description2; - String detailDescription; - double monthSales; - int rate; - double leftNum; - List productAttributes; - bool nonInventory; - String extraData; - String purchaseNote; - double weight; - double dimentionsLength; - double dimentionsWidth; - double dimentionsHeight; - bool reviewsAllowed; - List categories; - List subproducts; + int? id; + String? image; + List? images; + String? sku; + String? name; + double? price; + double? regularPrice; + String? description; + String? description2; + String? detailDescription; + double? monthSales; + int? rate; + double? leftNum; + List? productAttributes; + bool? nonInventory; + String? extraData; + String? purchaseNote; + double? weight; + double? dimentionsLength; + double? dimentionsWidth; + double? dimentionsHeight; + bool? reviewsAllowed; + List? categories; + List? subproducts; ProductDetail.fromJson(Map json) : id = json['id'], diff --git a/lib/models/product_image.dart b/lib/models/product_image.dart index 5275d57..f258ef2 100644 --- a/lib/models/product_image.dart +++ b/lib/models/product_image.dart @@ -1,8 +1,8 @@ import 'dart:convert'; class ProductImage { - int id; - String image; + int? id; + String? image; ProductImage.fromJson(Map json) : id = json['id'], diff --git a/lib/models/product_option.dart b/lib/models/product_option.dart index 6e50e96..5876840 100644 --- a/lib/models/product_option.dart +++ b/lib/models/product_option.dart @@ -2,11 +2,11 @@ import 'dart:convert'; class ProductOption { - int id; - String name; - double adjustAmount; - String extra; - bool disabled; + int? id; + String? name; + double? adjustAmount; + String? extra; + bool? disabled; ProductOption.fromJson(Map json) : id = json['id'], diff --git a/lib/models/shipping_rate.dart b/lib/models/shipping_rate.dart index 08f811e..2ed4f4c 100644 --- a/lib/models/shipping_rate.dart +++ b/lib/models/shipping_rate.dart @@ -4,9 +4,9 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; class ShippingRate { - String name; - double price; - List rates; + String? name; + double? price; + List? rates; ShippingRate.fromJson(Map json) : name = json['name'], @@ -25,7 +25,7 @@ class ShippingRate { other is ShippingRate && runtimeType == other.runtimeType && name == other.name && - price.toStringAsFixed(2) == other.price.toStringAsFixed(2) && + price?.toStringAsFixed(2) == other.price?.toStringAsFixed(2) && listEquals(rates, other.rates); @override @@ -41,8 +41,8 @@ class ShippingRate { } class Rate { - String name; - double rate; + String? name; + double? rate; Rate.fromJson(Map json) : name = json['name'], @@ -59,7 +59,7 @@ class Rate { other is Rate && runtimeType == other.runtimeType && name == other.name && - rate.toStringAsFixed(2) == other.rate.toStringAsFixed(2); + rate?.toStringAsFixed(2) == other.rate?.toStringAsFixed(2); @override String toString() { diff --git a/lib/models/simple_business.dart b/lib/models/simple_business.dart index cfcab03..4435495 100644 --- a/lib/models/simple_business.dart +++ b/lib/models/simple_business.dart @@ -4,9 +4,9 @@ import 'dart:convert'; import 'address.dart'; class Store { - int id; - String name; - Address address; + int? id; + String? name; + Address? address; Store.fromJson(Map json) : id = json['id'], diff --git a/lib/models/simple_product.dart b/lib/models/simple_product.dart index 206745f..4f324b7 100644 --- a/lib/models/simple_product.dart +++ b/lib/models/simple_product.dart @@ -1,12 +1,12 @@ import 'dart:convert'; class SimpleProduct { - int id; - String name; - double price; - double regularPrice; - String description; - String imagePath; + int? id; + String? name; + double? price; + double? regularPrice; + String? description; + String? imagePath; SimpleProduct.fromJson(Map json) : id = json['id'], diff --git a/lib/models/text_value.dart b/lib/models/text_value.dart index 57d5c90..31fb708 100644 --- a/lib/models/text_value.dart +++ b/lib/models/text_value.dart @@ -2,8 +2,8 @@ import 'dart:convert'; class TextValue { - String text; - int value; + String? text; + int? value; TextValue.fromJson(Map json) : text = json['text'], diff --git a/lib/models/ticket.dart b/lib/models/ticket.dart index 4226a3a..a98574a 100644 --- a/lib/models/ticket.dart +++ b/lib/models/ticket.dart @@ -4,10 +4,10 @@ import 'dart:convert'; import 'simple_business.dart'; class TicketFile { - int id; - String url; - String fileName; - String fileType; + int? id; + String? url; + String? fileName; + String? fileType; TicketFile.fromJson(Map json) : id = json['id'], @@ -29,9 +29,9 @@ class TicketFile { } class Issue { - int id; - String msg; - List files; + int? id; + String? msg; + List? files; Issue.fromJson(Map json) : id = json['id'], @@ -51,11 +51,11 @@ class Issue { } class FollowUp { - int id; - String msg; - String poster; - String createdAt; - List files; + int? id; + String? msg; + String? poster; + String? createdAt; + List? files; FollowUp.fromJson(Map json) : id = json['id'], @@ -79,12 +79,12 @@ class FollowUp { } class Ticket { - int id; - Issue issue; - Store store; - List followUps; - bool isClosed; - String createdAt; + int? id; + Issue? issue; + Store? store; + List? followUps; + bool? isClosed; + String? createdAt; Ticket.fromJson(Map json) : id = json['id'], diff --git a/lib/models/user.dart b/lib/models/user.dart index c467a19..70f6358 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -2,22 +2,22 @@ import 'dart:convert'; class User { - int id; - String username; - String nickname; - String mobile; - String email; - String avatarUrl; - int lastAddressId; - String passCode; - double credit; - double wallet; - int coupon; - int points; - int orderNum; - double pointsToCreditsConversionRate; - String contactNumber; - String flutterMiniStoreToken; + int? id; + String? username; + String? nickname; + String? mobile; + String? email; + String? avatarUrl; + int? lastAddressId; + String? passCode; + double? credit; + double? wallet; + int? coupon; + int? points; + int? orderNum; + double? pointsToCreditsConversionRate; + String? contactNumber; + String? flutterMiniStoreToken; User.fromJson(Map json) : id = json['id'], diff --git a/lib/models/user_position.dart b/lib/models/user_position.dart index dbe9f56..b001b33 100644 --- a/lib/models/user_position.dart +++ b/lib/models/user_position.dart @@ -2,8 +2,8 @@ import 'dart:convert'; class UserPosition { - double lat; - double lng; + double? lat; + double? lng; UserPosition.fromJson(Map json) : lat = double.parse(json['lat'].toString()), diff --git a/lib/models/waiting_line.dart b/lib/models/waiting_line.dart index dc1dffa..baccc69 100644 --- a/lib/models/waiting_line.dart +++ b/lib/models/waiting_line.dart @@ -4,8 +4,8 @@ import 'dart:convert'; import 'waiting_line_item.dart'; class WaitingLine { - List waitingLines; - String storeSn; + List? waitingLines; + String? storeSn; WaitingLine.fromJson(Map json) : waitingLines = (json['waiting_lines'] as List).map((i) => WaitingLineItem.fromJson(i)).toList(), diff --git a/lib/models/waiting_line_item.dart b/lib/models/waiting_line_item.dart index ce1127f..6b4414e 100644 --- a/lib/models/waiting_line_item.dart +++ b/lib/models/waiting_line_item.dart @@ -1,11 +1,11 @@ import 'dart:convert'; class WaitingLineItem { - String deviceId; - String phone; - String createdAt; - int peopleCount; - int waitingNumber; + String? deviceId; + String? phone; + String? createdAt; + int? peopleCount; + int? waitingNumber; WaitingLineItem.fromJson(Map json) : deviceId = json['device_id'], diff --git a/lib/utils/http_util.dart b/lib/utils/http_util.dart index bbd669c..7c12e0e 100644 --- a/lib/utils/http_util.dart +++ b/lib/utils/http_util.dart @@ -14,10 +14,8 @@ import '../constants.dart'; typedef void PostCallback(Response response); -String generateSignature(String string, {String key}) { - if (key == null) { - key = Constants.API_SECRET; - } +String generateSignature(String string, {String? key}) { + key ??= Constants.API_SECRET; Hmac mac = new Hmac(sha256, utf8.encode(key)); Digest digest = mac.convert(utf8.encode(string + key)); String base64Mac = base64.encode(utf8.encode("$digest")); @@ -38,16 +36,16 @@ class HttpUtil { 'Http-Device-Type': Utils.getOs(checkWeb: true), 'Http-Api-Branch': 'flutter', 'Http-Language-Code': store.state.locale.languageCode, - 'Http-Country-Code': store.state.locale.countryCode, + 'Http-Country-Code': store.state.locale.countryCode ?? '', }; static Future httpGet(String url, { - Map queryParameters, + Map? queryParameters, int businessId = 0, - Function(int, int) receiveProgress, + Function(int, int)? receiveProgress, bool returnError = false, - Map additionalHeaders, + Map? additionalHeaders, }) async { Map localHeaders = json.decode(json.encode(headers)); if (additionalHeaders != null) { @@ -69,7 +67,7 @@ class HttpUtil { requestUrl = url; } - Utils.jsonPrettyPrint(queryParameters); + Utils.jsonPrettyPrint(queryParameters ?? {}); Dio dio = Dio(); try { @@ -84,9 +82,8 @@ class HttpUtil { // print('response data: ${response.data}'); // Utils.jsonPrettyPrint(response.data); - int statusCode = response.statusCode; return response.data; - } on DioError catch(e) { + } on DioException catch(e) { print('HttpGet failed, request: $requestUrl, headers: $localHeaders, error ${e.response}'); if (returnError) { return e; @@ -97,14 +94,14 @@ class HttpUtil { static Future httpPost(String url, PostCallback callback, { - Map queryParameters, + Map? queryParameters, int businessId = 0, bool isFormData = false, - Map additionalHeaders, - Map body, - FormData formData, - Function(int, int) sendProgress, - Function(int, int) receiveProgress, + Map? additionalHeaders, + Map? body, + FormData? formData, + Function(int, int)? sendProgress, + Function(int, int)? receiveProgress, bool returnError = false, }) async { @@ -130,15 +127,15 @@ class HttpUtil { } // Don't print body will cause upload Multipart file failed - //Utils.jsonPrettyPrint(body); + //Utils.jsonPrettyPrint(body ?? {}); Dio dio = Dio(); dio.interceptors.add(LogInterceptor()); try { Response response = await dio.post( requestUrl, - queryParameters: queryParameters == null ? {} : queryParameters, - data: isFormData ? ((formData != null)?formData:FormData.fromMap(body)) : json.encode(body), + queryParameters: queryParameters ?? {}, + data: isFormData ? ((formData != null)?formData:FormData.fromMap(body ?? {})) : json.encode(body), options: Options( headers: localHeaders, contentType: isFormData ? Headers.formUrlEncodedContentType : Headers.jsonContentType, @@ -149,17 +146,16 @@ class HttpUtil { // Utils.jsonPrettyPrint(response.data); - int statusCode = response.statusCode; if (callback != null) { callback(response); } return response.data; - } on DioError catch(e, stacktrace) { + } on DioException catch(e, stacktrace) { if (e.response != null) { try { - Utils.jsonPrettyPrint(e.response.data); + Utils.jsonPrettyPrint(e.response!.data); } catch (err) { - print(e.response.data); + print(e.response!.data); } } if (returnError) { @@ -171,12 +167,12 @@ class HttpUtil { static Future httpPut(String url, PostCallback callback, { - Map queryParameters, + Map? queryParameters, int businessId = 0, - Map additionalHeaders, - Map body, - Function(int, int) sendProgress, - Function(int, int) receiveProgress, + Map? additionalHeaders, + Map? body, + Function(int, int)? sendProgress, + Function(int, int)? receiveProgress, bool returnError = false, }) async { @@ -207,7 +203,7 @@ class HttpUtil { try { Response response = await dio.put( requestUrl, - queryParameters: queryParameters == null ? {} : queryParameters, + queryParameters: queryParameters ?? {}, data: json.encode(body), options: Options( headers: localHeaders, @@ -218,14 +214,13 @@ class HttpUtil { // Utils.jsonPrettyPrint(response.data); - int statusCode = response.statusCode; if (callback != null) { callback(response); } return response.data; - } on DioError catch(e) { + } on DioException catch(e) { if (e.response != null) { - Utils.jsonPrettyPrint(e.response.data); + Utils.jsonPrettyPrint(e.response!.data); } if (returnError) { return e; @@ -236,12 +231,12 @@ class HttpUtil { static Future httpPatch(String url, PostCallback callback, { - Map queryParameters, + Map? queryParameters, int businessId = 0, - Map additionalHeaders, - Map body, - Function(int, int) sendProgress, - Function(int, int) receiveProgress, + Map? additionalHeaders, + Map? body, + Function(int, int)? sendProgress, + Function(int, int)? receiveProgress, bool returnError = false, }) async { @@ -268,13 +263,13 @@ class HttpUtil { requestUrl = url; } - Utils.jsonPrettyPrint(body); + Utils.jsonPrettyPrint(body ?? {}); Dio dio = Dio(); try { Response response = await dio.patch( requestUrl, - queryParameters: queryParameters == null ? {} : queryParameters, + queryParameters: queryParameters ?? {}, data: json.encode(body), options: Options( headers: localHeaders, @@ -285,14 +280,13 @@ class HttpUtil { // Utils.jsonPrettyPrint(response.data); - int statusCode = response.statusCode; if (callback != null) { callback(response); } return response.data; - } on DioError catch(e) { + } on DioException catch(e) { if (e.response != null) { - Utils.jsonPrettyPrint(e.response.data); + Utils.jsonPrettyPrint(e.response!.data); } if (returnError) { return e; @@ -303,10 +297,10 @@ class HttpUtil { static Future httpDelete(String url, PostCallback callback, { - Map queryParameters, + Map? queryParameters, int businessId = 0, - Map additionalHeaders, - Map body, + Map? additionalHeaders, + Map? body, bool returnError = false, }) async { @@ -333,13 +327,13 @@ class HttpUtil { requestUrl = url; } - Utils.jsonPrettyPrint(body); + Utils.jsonPrettyPrint(body ?? {}); Dio dio = Dio(); try { Response response = await dio.delete( requestUrl, - queryParameters: queryParameters == null ? {} : queryParameters, + queryParameters: queryParameters ?? {}, data: json.encode(body), options: Options( headers: localHeaders, @@ -348,14 +342,13 @@ class HttpUtil { // Utils.jsonPrettyPrint(response.data); - int statusCode = response.statusCode; if (callback != null) { callback(response); } return response.data; - } on DioError catch(e) { + } on DioException catch(e) { if (e.response != null) { - Utils.jsonPrettyPrint(e.response.data); + Utils.jsonPrettyPrint(e.response!.data); } if(returnError) { return e;