Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MetaData.fromJson in order.dart for non String value #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/models/billing.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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;
}
}
129 changes: 6 additions & 123 deletions lib/models/customer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

*/

import 'billing.dart';
import 'shipping.dart';
import 'meta_data.dart';

class WooCustomer {
int id;
String dateCreated;
Expand All @@ -47,7 +51,7 @@ class WooCustomer {
Shipping shipping;
bool isPayingCustomer;
String avatarUrl;
List<WooCustomerMetaData> metaData;
List<MetaData> metaData;
Links links;

WooCustomer(
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<String, dynamic> json)
: id = json['id'],
key = json['key'],
value = json['value'];

Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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> self;
List<Collection> collection;
Expand Down
21 changes: 21 additions & 0 deletions lib/models/meta_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class MetaData {
int id;
String key;
String value;

MetaData({this.id, this.key, this.value});

MetaData.fromJson(Map<String, dynamic> json) {
id = json['id'];
key = json['key'];
value = json['value'].toString();
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['key'] = this.key;
data['value'] = this.value;
return data;
}
}
137 changes: 7 additions & 130 deletions lib/models/order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,7 +81,8 @@ class WooOrder {
Links links;

WooOrder(
{@required this.id,
{@required
this.id,
this.parentId,
this.number,
this.orderKey,
Expand Down Expand Up @@ -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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> json) {
id = json['id'];
key = json['key'];
value = json['value'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['key'] = this.key;
data['value'] = this.value;
return data;
}
}

class Refunds {
int id;
String reason;
Expand Down
Loading