Initialer Commit: Projekt Start
This commit is contained in:
78
lib/models/address.dart
Normal file
78
lib/models/address.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
class Address {
|
||||
final String? firstName;
|
||||
final String? lastName;
|
||||
final String? company;
|
||||
final String? address1;
|
||||
final String? address2;
|
||||
final String? city;
|
||||
final String? state;
|
||||
final String? postcode;
|
||||
final String? country;
|
||||
final String? email;
|
||||
final String? phone;
|
||||
|
||||
Address({
|
||||
this.firstName,
|
||||
this.lastName,
|
||||
this.company,
|
||||
this.address1,
|
||||
this.address2,
|
||||
this.city,
|
||||
this.state,
|
||||
this.postcode,
|
||||
this.country,
|
||||
this.email,
|
||||
this.phone,
|
||||
});
|
||||
|
||||
factory Address.fromJson(Map<String, dynamic> json) {
|
||||
return Address(
|
||||
firstName: json['first_name'],
|
||||
lastName: json['last_name'],
|
||||
company: json['company'],
|
||||
address1: json['address_1'] ?? json['address1'],
|
||||
address2: json['address_2'] ?? json['address2'],
|
||||
city: json['city'],
|
||||
state: json['state'],
|
||||
postcode: json['postcode'],
|
||||
country: json['country'],
|
||||
email: json['email'],
|
||||
phone: json['phone'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'first_name': firstName,
|
||||
'last_name': lastName,
|
||||
'company': company,
|
||||
'address_1': address1,
|
||||
'address_2': address2,
|
||||
'city': city,
|
||||
'state': state,
|
||||
'postcode': postcode,
|
||||
'country': country,
|
||||
'email': email,
|
||||
'phone': phone,
|
||||
};
|
||||
}
|
||||
|
||||
String get fullAddress {
|
||||
final parts = <String>[];
|
||||
if (address1 != null && address1!.isNotEmpty) parts.add(address1!);
|
||||
if (address2 != null && address2!.isNotEmpty) parts.add(address2!);
|
||||
if (postcode != null && postcode!.isNotEmpty) parts.add(postcode!);
|
||||
if (city != null && city!.isNotEmpty) parts.add(city!);
|
||||
if (state != null && state!.isNotEmpty) parts.add(state!);
|
||||
if (country != null && country!.isNotEmpty) parts.add(country!);
|
||||
return parts.join(', ');
|
||||
}
|
||||
|
||||
bool get isEmpty {
|
||||
return (firstName == null || firstName!.isEmpty) &&
|
||||
(lastName == null || lastName!.isEmpty) &&
|
||||
(address1 == null || address1!.isEmpty) &&
|
||||
(city == null || city!.isEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user