Skip to content

Instantly share code, notes, and snippets.

@arnold-parge
Last active May 31, 2020 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnold-parge/c68180916d330376974eaa27f716a10f to your computer and use it in GitHub Desktop.
Save arnold-parge/c68180916d330376974eaa27f716a10f to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:best_db_poc/service/model_ctrl/user_model_ctrl.dart';
import 'package:best_db_poc/utils/app_keys.dart';
class UserModel {
String gender;
_Name name;
_Location location;
String email;
_Login login;
_Dob dob;
_Dob registered;
String phone;
String cell;
_Id id;
_Picture picture;
String nat;
static String get tableName => 'user';
UserModel({
this.gender,
this.name,
this.location,
this.email,
this.login,
this.dob,
this.registered,
this.phone,
this.cell,
this.id,
this.picture,
this.nat,
});
factory UserModel.fromJson(String str) => UserModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory UserModel.fromMap(Map<String, dynamic> jsonData) => UserModel(
gender: jsonData[AppKeys.gender],
name: _Name.fromMap(jsonData[AppKeys.name]),
location: _Location.fromMap(jsonData[AppKeys.location]),
email: jsonData[AppKeys.email],
login: _Login.fromMap(jsonData[AppKeys.login]),
dob: _Dob.fromMap(jsonData[AppKeys.dob]),
registered: _Dob.fromMap(jsonData[AppKeys.registered]),
phone: jsonData[AppKeys.phone],
cell: jsonData[AppKeys.cell],
id: _Id.fromMap(jsonData[AppKeys.id]),
picture: _Picture.fromMap(jsonData[AppKeys.picture]),
nat: jsonData[AppKeys.nat],
);
Map<String, dynamic> toMap() => {
AppKeys.gender: gender,
AppKeys.name: name.toMap(),
AppKeys.location: location.toMap(),
AppKeys.email: email,
AppKeys.login: login.toMap(),
AppKeys.dob: dob.toMap(),
AppKeys.registered: registered.toMap(),
AppKeys.phone: phone,
AppKeys.cell: cell,
AppKeys.id: id.toMap(),
AppKeys.picture: picture.toMap(),
AppKeys.nat: nat,
};
}
class _Dob {
DateTime date;
int age;
_Dob({
this.date,
this.age,
});
factory _Dob.fromJson(String str) => _Dob.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Dob.fromMap(Map<String, dynamic> jsonData) => _Dob(
date: DateTime.parse(jsonData[AppKeys.date]),
age: jsonData[AppKeys.age],
);
Map<String, dynamic> toMap() => {
AppKeys.date: date.toIso8601String(),
AppKeys.age: age,
};
}
class _Id {
String name;
String value;
_Id({
this.name,
this.value,
});
factory _Id.fromJson(String str) => _Id.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Id.fromMap(Map<String, dynamic> jsonData) => _Id(
name: jsonData[AppKeys.name],
value: jsonData[AppKeys.value],
);
Map<String, dynamic> toMap() => {
AppKeys.name: name,
AppKeys.value: value,
};
}
class _Location {
_Street street;
String city;
String state;
String country;
String postcode;
_Coordinates coordinates;
_Timezone timezone;
_Location({
this.street,
this.city,
this.state,
this.country,
this.postcode,
this.coordinates,
this.timezone,
});
factory _Location.fromJson(String str) => _Location.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Location.fromMap(Map<String, dynamic> jsonData) => _Location(
street: _Street.fromMap(jsonData[AppKeys.street]),
city: jsonData[AppKeys.city],
state: jsonData[AppKeys.state],
country: jsonData[AppKeys.country],
postcode: jsonData[AppKeys.postcode].toString(),
coordinates: _Coordinates.fromMap(jsonData[AppKeys.coordinates]),
timezone: _Timezone.fromMap(jsonData[AppKeys.timezone]),
);
Map<String, dynamic> toMap() => {
AppKeys.street: street.toMap(),
AppKeys.city: city,
AppKeys.state: state,
AppKeys.country: country,
AppKeys.postcode: postcode,
AppKeys.coordinates: coordinates.toMap(),
AppKeys.timezone: timezone.toMap(),
};
}
class _Coordinates {
String latitude;
String longitude;
_Coordinates({
this.latitude,
this.longitude,
});
factory _Coordinates.fromJson(String str) =>
_Coordinates.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Coordinates.fromMap(Map<String, dynamic> jsonData) => _Coordinates(
latitude: jsonData[AppKeys.latitude],
longitude: jsonData[AppKeys.longitude],
);
Map<String, dynamic> toMap() => {
AppKeys.latitude: latitude,
AppKeys.longitude: longitude,
};
}
class _Street {
int number;
String name;
_Street({
this.number,
this.name,
});
factory _Street.fromJson(String str) => _Street.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Street.fromMap(Map<String, dynamic> jsonData) => _Street(
number: jsonData[AppKeys.number],
name: jsonData[AppKeys.name],
);
Map<String, dynamic> toMap() => {
AppKeys.number: number,
AppKeys.name: name,
};
}
class _Timezone {
String offset;
String description;
_Timezone({
this.offset,
this.description,
});
factory _Timezone.fromJson(String str) => _Timezone.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Timezone.fromMap(Map<String, dynamic> jsonData) => _Timezone(
offset: jsonData[AppKeys.offset],
description: jsonData[AppKeys.description],
);
Map<String, dynamic> toMap() => {
AppKeys.offset: offset,
AppKeys.description: description,
};
}
class _Login {
String uuid;
String username;
String password;
String salt;
String md5;
String sha1;
String sha256;
_Login({
this.uuid,
this.username,
this.password,
this.salt,
this.md5,
this.sha1,
this.sha256,
});
factory _Login.fromJson(String str) => _Login.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Login.fromMap(Map<String, dynamic> jsonData) => _Login(
uuid: jsonData[AppKeys.uuid],
username: jsonData[AppKeys.username],
password: jsonData[AppKeys.password],
salt: jsonData[AppKeys.salt],
md5: jsonData[AppKeys.md5],
sha1: jsonData[AppKeys.sha1],
sha256: jsonData[AppKeys.sha256],
);
Map<String, dynamic> toMap() => {
AppKeys.uuid: uuid,
AppKeys.username: username,
AppKeys.password: password,
AppKeys.salt: salt,
AppKeys.md5: md5,
AppKeys.sha1: sha1,
AppKeys.sha256: sha256,
};
}
class _Name {
String title;
String first;
String last;
_Name({
this.title,
this.first,
this.last,
});
factory _Name.fromJson(String str) => _Name.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Name.fromMap(Map<String, dynamic> jsonData) => _Name(
title: jsonData[AppKeys.title],
first: jsonData[AppKeys.first],
last: jsonData[AppKeys.last],
);
Map<String, dynamic> toMap() => {
AppKeys.title: title,
AppKeys.first: first,
AppKeys.last: last,
};
}
class _Picture {
String large;
String medium;
String thumbnail;
_Picture({
this.large,
this.medium,
this.thumbnail,
});
factory _Picture.fromJson(String str) => _Picture.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory _Picture.fromMap(Map<String, dynamic> jsonData) => _Picture(
large: jsonData[AppKeys.large],
medium: jsonData[AppKeys.medium],
thumbnail: jsonData[AppKeys.thumbnail],
);
Map<String, dynamic> toMap() => {
AppKeys.large: large,
AppKeys.medium: medium,
AppKeys.thumbnail: thumbnail,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment