-
-
Save chhumsina/22a0db48259235c41f27e180dc7ddbc4 to your computer and use it in GitHub Desktop.
Contact data
This file contains hidden or 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 'dart:async'; | |
import 'package:intl/intl.dart'; | |
class Contact { | |
static final DateFormat _formatter = DateFormat('MMMM d, yyyy'); | |
final String fullName; | |
final String gender; | |
final String email; | |
final String imageUrl; | |
final String birthday; | |
final Location location; | |
final List<Phone> phones; | |
const Contact({this.fullName, this.gender, this.email, this.imageUrl, | |
this.birthday, this.location, this.phones}); | |
Contact.fromMap(Map<String, dynamic> map) : | |
fullName = "${map['name']['first']} ${map['name']['last']}", | |
gender = map['gender'], | |
email = map['email'], | |
imageUrl = map['picture']['large'], | |
birthday = _formatter.format(DateTime.parse(map['dob']['date'])), | |
location = Location.fromMap(map['location']), | |
phones = <Phone>[ | |
new Phone(type: 'Home', number: map['phone']), | |
new Phone(type: 'Mobile', number: map['cell']) | |
]; | |
} | |
class Location { | |
final String street; | |
final String city; | |
const Location({this.street, this.city}); | |
Location.fromMap(Map<String, dynamic> map) : | |
street = map['street'], | |
city = map['city']; | |
} | |
class Phone { | |
final String type; | |
final String number; | |
const Phone({this.type, this.number}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment