I'm new at Flutter and I'm trying to handle the complex json structure but i dont know how to store complex JSON data into the firebase realtime database using flutter.Here I attached my JSON structure and Data model class structure too. Are there are any related article or tutorialregarding the same.
JSON Structure:
{
"users": {
"[email protected]": {
"name": "John Doe",
"Country": "United Kingdom",
"verified_phone": true,
"ID_verification": False,
},
"Properties": {
"Properties":[ {
"propertiename":"Hilton_Common",
"Role" : "owner"},
{"propertiename":"Carraige_guest_house",
"Role" : "staff",
}
....
....
]},
"Reservations": {
"Properties": [{
"propertiename":"Hilton_Common"
"Guest" : "Primary_guest"},
{"propertiename":"Carraige_guest_house"
"Guest" : "Aditional",
}
....
....
]},
}}
User model:
class User {
String key;
final List<Host> host;
final List<User_Reservation> reservation;
String nameformlogin, phone, email;
String verifiedphone, idverification;
var list;
User({
this.key,
this.nameformlogin,
this.phone,
this.email
this.verifiedphone,
this.idverification,
this.host,
this.reservation,
});
factory User.fromJson(Map<String, dynamic> json) {
return new User(
nameformlogin: json["nameformlogin"],
phone: json["phone"],
email: json["email"],
verifiedphone: json["verifiedphone"],
idverification: json["idverification"],
host: json["host"],
reservation:json["reservation"]
);
}
toJson() {
return {
'name': nameformlogin,
'county':phone,
'email': email,
'verifiedphone':verifiedphone,
'idverification':idverification,
'host':host,
'reservation':reservation
};
}
}
class Host {
String propertiesname, role;
Host({this.propertiesname, this.role});
factory Host.fromJson(Map<String, dynamic> json) {
return new Host(propertiesname: json['propertiesname'], role: json['role']);
}
}
class User_Reservation {
String propertiesname, guest;
User_Reservation({this.propertiesname, this.guest});
factory User_Reservation.fromJson(Map<String, dynamic> json) {
return new User_Reservation(
propertiesname: json['propertiesname'], guest: json['guest']);
}
}