From 2b95c9c19f446d6d1955c048ba240bf0650e33ce Mon Sep 17 00:00:00 2001 From: CarloDotLog Date: Fri, 30 Oct 2020 19:42:02 +0100 Subject: [PATCH] Fix duplicated classes --- lib/models/billing.dart | 56 ++++++++++++++++ lib/models/customer.dart | 129 ++--------------------------------- lib/models/meta_data.dart | 21 ++++++ lib/models/order.dart | 137 ++------------------------------------ lib/models/products.dart | 16 +---- lib/models/shipping.dart | 48 +++++++++++++ 6 files changed, 139 insertions(+), 268 deletions(-) create mode 100644 lib/models/billing.dart create mode 100644 lib/models/meta_data.dart create mode 100644 lib/models/shipping.dart diff --git a/lib/models/billing.dart b/lib/models/billing.dart new file mode 100644 index 0000000..ddc5a6f --- /dev/null +++ b/lib/models/billing.dart @@ -0,0 +1,56 @@ +class Billing { + String firstName; + String lastName; + String company; + String address1; + String address2; + String city; + String state; + String postcode; + String country; + String email; + String phone; + + Billing( + {this.firstName, + this.lastName, + this.company, + this.address1, + this.address2, + this.city, + this.state, + this.postcode, + this.country, + this.email, + this.phone}); + + Billing.fromJson(Map json) { + firstName = json['first_name']; + lastName = json['last_name']; + company = json['company']; + address1 = json['address_1']; + address2 = json['address_2']; + city = json['city']; + state = json['state']; + postcode = json['postcode']; + country = json['country']; + email = json['email']; + phone = json['phone']; + } + + Map toJson() { + final Map data = new Map(); + data['first_name'] = this.firstName; + data['last_name'] = this.lastName; + data['company'] = this.company; + data['address_1'] = this.address1; + data['address_2'] = this.address2; + data['city'] = this.city; + data['state'] = this.state; + data['postcode'] = this.postcode; + data['country'] = this.country; + data['email'] = this.email; + data['phone'] = this.phone; + return data; + } +} diff --git a/lib/models/customer.dart b/lib/models/customer.dart index f132085..08a3e1e 100755 --- a/lib/models/customer.dart +++ b/lib/models/customer.dart @@ -31,6 +31,10 @@ */ +import 'billing.dart'; +import 'shipping.dart'; +import 'meta_data.dart'; + class WooCustomer { int id; String dateCreated; @@ -47,7 +51,7 @@ class WooCustomer { Shipping shipping; bool isPayingCustomer; String avatarUrl; - List metaData; + List metaData; Links links; WooCustomer( @@ -88,7 +92,7 @@ class WooCustomer { isPayingCustomer = json['is_paying_customer']; avatarUrl = json['avatar_url']; metaData = - (json['meta_data'] as List).map((i) => WooCustomerMetaData.fromJson(i)).toList(); + (json['meta_data'] as List).map((i) => MetaData.fromJson(i)).toList(); links = json['_links'] != null ? new Links.fromJson(json['_links']) : null; } @@ -129,127 +133,6 @@ class WooCustomer { @override toString() => this.toJson().toString(); } -class WooCustomerMetaData { - final int id; - final String key; - final dynamic value; - - WooCustomerMetaData(this.id, this.key, this.value); - - WooCustomerMetaData.fromJson(Map json) - : id = json['id'], - key = json['key'], - value = json['value']; - - Map toJson() => {'id': id, 'key': key, 'value': value}; -} - -class Billing { - String firstName; - String lastName; - String company; - String address1; - String address2; - String city; - String state; - String postcode; - String country; - String email; - String phone; - - Billing( - {this.firstName, - this.lastName, - this.company, - this.address1, - this.address2, - this.city, - this.state, - this.postcode, - this.country, - this.email, - this.phone}); - - Billing.fromJson(Map json) { - firstName = json['first_name']; - lastName = json['last_name']; - company = json['company']; - address1 = json['address_1']; - address2 = json['address_2']; - city = json['city']; - state = json['state']; - postcode = json['postcode']; - country = json['country']; - email = json['email']; - phone = json['phone']; - } - - Map toJson() { - final Map data = new Map(); - data['first_name'] = this.firstName; - data['last_name'] = this.lastName; - data['company'] = this.company; - data['address_1'] = this.address1; - data['address_2'] = this.address2; - data['city'] = this.city; - data['state'] = this.state; - data['postcode'] = this.postcode; - data['country'] = this.country; - data['email'] = this.email; - data['phone'] = this.phone; - return data; - } -} - -class Shipping { - String firstName; - String lastName; - String company; - String address1; - String address2; - String city; - String state; - String postcode; - String country; - - Shipping( - {this.firstName, - this.lastName, - this.company, - this.address1, - this.address2, - this.city, - this.state, - this.postcode, - this.country}); - - Shipping.fromJson(Map json) { - firstName = json['first_name']; - lastName = json['last_name']; - company = json['company']; - address1 = json['address_1']; - address2 = json['address_2']; - city = json['city']; - state = json['state']; - postcode = json['postcode']; - country = json['country']; - } - - Map toJson() { - final Map data = new Map(); - data['first_name'] = this.firstName; - data['last_name'] = this.lastName; - data['company'] = this.company; - data['address_1'] = this.address1; - data['address_2'] = this.address2; - data['city'] = this.city; - data['state'] = this.state; - data['postcode'] = this.postcode; - data['country'] = this.country; - return data; - } -} - class Links { List self; List collection; diff --git a/lib/models/meta_data.dart b/lib/models/meta_data.dart new file mode 100644 index 0000000..73dbc14 --- /dev/null +++ b/lib/models/meta_data.dart @@ -0,0 +1,21 @@ +class MetaData { + int id; + String key; + String value; + + MetaData({this.id, this.key, this.value}); + + MetaData.fromJson(Map json) { + id = json['id']; + key = json['key']; + value = json['value'].toString(); + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['key'] = this.key; + data['value'] = this.value; + return data; + } +} diff --git a/lib/models/order.dart b/lib/models/order.dart index 0cf44b6..51061ee 100755 --- a/lib/models/order.dart +++ b/lib/models/order.dart @@ -31,7 +31,11 @@ */ -import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; +import 'meta_data.dart'; +import 'billing.dart'; +import 'shipping.dart'; + class WooOrder { int id; int parentId; @@ -77,7 +81,8 @@ class WooOrder { Links links; WooOrder( - {@required this.id, + {@required + this.id, this.parentId, this.number, this.orderKey, @@ -382,134 +387,6 @@ class FeeLineTax { } } -class Billing { - String firstName; - String lastName; - String company; - String address1; - String address2; - String city; - String state; - String postcode; - String country; - String email; - String phone; - - Billing( - {this.firstName, - this.lastName, - this.company, - this.address1, - this.address2, - this.city, - this.state, - this.postcode, - this.country, - this.email, - this.phone}); - - Billing.fromJson(Map json) { - firstName = json['first_name']; - lastName = json['last_name']; - company = json['company']; - address1 = json['address_1']; - address2 = json['address_2']; - city = json['city']; - state = json['state']; - postcode = json['postcode']; - country = json['country']; - email = json['email']; - phone = json['phone']; - } - - Map toJson() { - final Map data = new Map(); - data['first_name'] = this.firstName; - data['last_name'] = this.lastName; - data['company'] = this.company; - data['address_1'] = this.address1; - data['address_2'] = this.address2; - data['city'] = this.city; - data['state'] = this.state; - data['postcode'] = this.postcode; - data['country'] = this.country; - data['email'] = this.email; - data['phone'] = this.phone; - return data; - } -} - -class Shipping { - String firstName; - String lastName; - String company; - String address1; - String address2; - String city; - String state; - String postcode; - String country; - - Shipping( - {this.firstName, - this.lastName, - this.company, - this.address1, - this.address2, - this.city, - this.state, - this.postcode, - this.country}); - - Shipping.fromJson(Map json) { - firstName = json['first_name']; - lastName = json['last_name']; - company = json['company']; - address1 = json['address_1']; - address2 = json['address_2']; - city = json['city']; - state = json['state']; - postcode = json['postcode']; - country = json['country']; - } - - Map toJson() { - final Map data = new Map(); - data['first_name'] = this.firstName; - data['last_name'] = this.lastName; - data['company'] = this.company; - data['address_1'] = this.address1; - data['address_2'] = this.address2; - data['city'] = this.city; - data['state'] = this.state; - data['postcode'] = this.postcode; - data['country'] = this.country; - return data; - } -} - -class MetaData { - int id; - String key; - String value; - - MetaData({this.id, this.key, this.value}); - - MetaData.fromJson(Map json) { - id = json['id']; - key = json['key']; - value = json['value'].toString(); - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['key'] = this.key; - data['value'] = this.value; - return data; - } -} - class Refunds { int id; String reason; diff --git a/lib/models/products.dart b/lib/models/products.dart index c0d470d..d7bd12d 100755 --- a/lib/models/products.dart +++ b/lib/models/products.dart @@ -32,6 +32,7 @@ */ import 'product_category.dart'; +import 'meta_data.dart'; class WooProduct { final int id; @@ -240,21 +241,6 @@ class WooProductItemTag { @override toString() => 'Tag: $name'; } -class MetaData { - final int id; - final String key; - final String value; - - MetaData(this.id, this.key, this.value); - - MetaData.fromJson(Map json) - : id = json['id'], - key = json['key'], - value = json['value'].toString(); - - Map toJson() => {'id': id, 'key': key, 'value': value}; -} - class WooProductDefaultAttribute { final int id; final String name; diff --git a/lib/models/shipping.dart b/lib/models/shipping.dart new file mode 100644 index 0000000..f8c24de --- /dev/null +++ b/lib/models/shipping.dart @@ -0,0 +1,48 @@ +class Shipping { + String firstName; + String lastName; + String company; + String address1; + String address2; + String city; + String state; + String postcode; + String country; + + Shipping( + {this.firstName, + this.lastName, + this.company, + this.address1, + this.address2, + this.city, + this.state, + this.postcode, + this.country}); + + Shipping.fromJson(Map json) { + firstName = json['first_name']; + lastName = json['last_name']; + company = json['company']; + address1 = json['address_1']; + address2 = json['address_2']; + city = json['city']; + state = json['state']; + postcode = json['postcode']; + country = json['country']; + } + + Map toJson() { + final Map data = new Map(); + data['first_name'] = this.firstName; + data['last_name'] = this.lastName; + data['company'] = this.company; + data['address_1'] = this.address1; + data['address_2'] = this.address2; + data['city'] = this.city; + data['state'] = this.state; + data['postcode'] = this.postcode; + data['country'] = this.country; + return data; + } +}