Last active
November 2, 2021 17:49
-
-
Save locohost/3197a38be463ffe19240590226820233 to your computer and use it in GitHub Desktop.
Flutter/Dart Location simple model example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:league_tracker/lm_track/feature/region/model/region_model.dart'; | |
@immutable | |
class Location { | |
final String id; | |
final String shortName; | |
final String description; | |
final String phone; | |
final String email; | |
final String street1; | |
final String street2; | |
final String city; | |
final String state; | |
final String zipcode; | |
final Region? region; | |
Location({ | |
this.id '', | |
this.shortName = '', | |
this.description = '', | |
this.phone = '', | |
this.email = '', | |
this.street1= '', | |
this.street2 = '', | |
this.city = '', | |
this.state = '', | |
this.zipcode = '', | |
this.region = null, | |
}); | |
factory Location.fromJson(Map<String, dynamic> json) => Location( | |
id: json['id'] ?? '', | |
shortName: json['shortname'] ?? '', | |
description: json['description'] ?? '', | |
phone: json['phone'] ?? '', | |
email: json['email'] ?? '', | |
street1: json['street1'] ?? '', | |
street2: json['street2'] ?? '', | |
city: json['city'] ?? '', | |
state: json['state'] ?? '', | |
zipcode: json['zipcode'] ?? '', | |
region: json['region'] != null | |
? Region.fromJson(json['region']) | |
: Region.blank(), | |
); | |
Map<String, dynamic> toJson() { | |
final doc = {}; | |
doc['phone'] = this.phone; | |
doc['email'] = this.email; | |
doc['street1'] = this.street1; | |
doc['street2'] = this.street2; | |
doc['city'] = this.city; | |
doc['state'] = this.state; | |
doc['zipcode'] = this.zipcode; | |
doc['region'] = this.region.toJson(); | |
return doc; | |
} | |
Location copyWith({ | |
String? id, | |
String? shortName, | |
String? description, | |
String? phone, | |
String? email, | |
String? street1, | |
String? street2, | |
String? city, | |
String? state, | |
String? zipcode, | |
Region? region, | |
}) => | |
Location( | |
id: id ?? this.id, | |
shortName: shortName ?? this.shortName, | |
description: description ?? this.description, | |
phone: phone ?? this.phone, | |
email: email ?? this.email, | |
street1: street1 ?? this.street1, | |
street2: street2 ?? this.street2, | |
city: city ?? this.city, | |
state: state ?? this.state, | |
zipcode: zipcode ?? this.zipcode, | |
region: region ?? this.region, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment