-
-
Save AbhishekDoshi26/7be9d99d7dfd6d8015c74a334b3b94bb to your computer and use it in GitHub Desktop.
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 'dart:convert'; | |
List<UserModel> userModelFromJson(String str) => | |
List<UserModel>.from(json.decode(str).map((x) => UserModel.fromJson(x))); | |
String userModelToJson(List<UserModel> data) => | |
json.encode(List<dynamic>.from(data.map((x) => x.toJson()))); | |
class UserModel { | |
UserModel({ | |
required this.id, | |
required this.name, | |
required this.username, | |
required this.email, | |
required this.address, | |
required this.phone, | |
required this.website, | |
required this.company, | |
}); | |
int id; | |
String name; | |
String username; | |
String email; | |
Address address; | |
String phone; | |
String website; | |
Company company; | |
factory UserModel.fromJson(Map<String, dynamic> json) => UserModel( | |
id: json["id"], | |
name: json["name"], | |
username: json["username"], | |
email: json["email"], | |
address: Address.fromJson(json["address"]), | |
phone: json["phone"], | |
website: json["website"], | |
company: Company.fromJson(json["company"]), | |
); | |
Map<String, dynamic> toJson() => { | |
"id": id, | |
"name": name, | |
"username": username, | |
"email": email, | |
"address": address.toJson(), | |
"phone": phone, | |
"website": website, | |
"company": company.toJson(), | |
}; | |
} | |
class Address { | |
Address({ | |
required this.street, | |
required this.suite, | |
required this.city, | |
required this.zipcode, | |
required this.geo, | |
}); | |
String street; | |
String suite; | |
String city; | |
String zipcode; | |
Geo geo; | |
factory Address.fromJson(Map<String, dynamic> json) => Address( | |
street: json["street"], | |
suite: json["suite"], | |
city: json["city"], | |
zipcode: json["zipcode"], | |
geo: Geo.fromJson(json["geo"]), | |
); | |
Map<String, dynamic> toJson() => { | |
"street": street, | |
"suite": suite, | |
"city": city, | |
"zipcode": zipcode, | |
"geo": geo.toJson(), | |
}; | |
} | |
class Geo { | |
Geo({ | |
required this.lat, | |
required this.lng, | |
}); | |
String lat; | |
String lng; | |
factory Geo.fromJson(Map<String, dynamic> json) => Geo( | |
lat: json["lat"], | |
lng: json["lng"], | |
); | |
Map<String, dynamic> toJson() => { | |
"lat": lat, | |
"lng": lng, | |
}; | |
} | |
class Company { | |
Company({ | |
required this.name, | |
required this.catchPhrase, | |
required this.bs, | |
}); | |
String name; | |
String catchPhrase; | |
String bs; | |
factory Company.fromJson(Map<String, dynamic> json) => Company( | |
name: json["name"], | |
catchPhrase: json["catchPhrase"], | |
bs: json["bs"], | |
); | |
Map<String, dynamic> toJson() => { | |
"name": name, | |
"catchPhrase": catchPhrase, | |
"bs": bs, | |
}; | |
} |
Brilliant, thanks a lot.
Thank you
Thank you!
love the tool used to generate this file. https://app.quicktype.io/
Thanks man
Thanks 👍
Thank you
Great
Merciiii
cool
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Man!