Skip to content

Instantly share code, notes, and snippets.

@fabiomsr
Last active February 24, 2019 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fabiomsr/7360ca689308183d42c70bbaf151a31b to your computer and use it in GitHub Desktop.
Save fabiomsr/7360ca689308183d42c70bbaf151a31b to your computer and use it in GitHub Desktop.
Contact data
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