Created
August 3, 2020 10:02
-
-
Save 5lineofcode/0d5a202e30dfca38f85774e61e1f22dc 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
// To parse this JSON data, do | |
// | |
// final getMateriApiResponse = getMateriApiResponseFromJson(jsonString); | |
import 'dart:convert'; | |
class GetMateriApiResponse { | |
GetMateriApiResponse({ | |
this.datas, | |
this.success, | |
this.msg, | |
}); | |
List<Data> datas; | |
bool success; | |
String msg; | |
factory GetMateriApiResponse.fromRawJson(String str) => GetMateriApiResponse.fromJson(json.decode(str)); | |
String toRawJson() => json.encode(toJson()); | |
factory GetMateriApiResponse.fromJson(Map<String, dynamic> json) => GetMateriApiResponse( | |
datas: List<Data>.from(json["datas"].map((x) => Data.fromJson(x))), | |
success: json["success"], | |
msg: json["msg"], | |
); | |
Map<String, dynamic> toJson() => { | |
"datas": List<dynamic>.from(datas.map((x) => x.toJson())), | |
"success": success, | |
"msg": msg, | |
}; | |
} | |
class Data { | |
Data({ | |
this.id, | |
this.title, | |
this.data, | |
}); | |
int id; | |
String title; | |
List<Datum> data; | |
factory Data.fromRawJson(String str) => Data.fromJson(json.decode(str)); | |
String toRawJson() => json.encode(toJson()); | |
factory Data.fromJson(Map<String, dynamic> json) => Data( | |
id: json["id"], | |
title: json["title"], | |
data: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))), | |
); | |
Map<String, dynamic> toJson() => { | |
"id": id, | |
"title": title, | |
"data": List<dynamic>.from(data.map((x) => x.toJson())), | |
}; | |
} | |
class Datum { | |
Datum({ | |
this.id, | |
this.title, | |
this.deskripsi, | |
this.file, | |
this.idKategori, | |
this.urutan, | |
this.createdAt, | |
this.updatedAt, | |
this.status, | |
this.point, | |
}); | |
int id; | |
String title; | |
Deskripsi deskripsi; | |
dynamic file; | |
int idKategori; | |
String urutan; | |
DateTime createdAt; | |
DateTime updatedAt; | |
int status; | |
int point; | |
factory Datum.fromRawJson(String str) => Datum.fromJson(json.decode(str)); | |
String toRawJson() => json.encode(toJson()); | |
factory Datum.fromJson(Map<String, dynamic> json) => Datum( | |
id: json["id"], | |
title: json["title"], | |
deskripsi: deskripsiValues.map[json["deskripsi"]], | |
file: json["file"], | |
idKategori: json["id_kategori"], | |
urutan: json["urutan"], | |
createdAt: DateTime.parse(json["created_at"]), | |
updatedAt: DateTime.parse(json["updated_at"]), | |
status: json["status"], | |
point: json["point"], | |
); | |
Map<String, dynamic> toJson() => { | |
"id": id, | |
"title": title, | |
"deskripsi": deskripsiValues.reverse[deskripsi], | |
"file": file, | |
"id_kategori": idKategori, | |
"urutan": urutan, | |
"created_at": createdAt.toIso8601String(), | |
"updated_at": updatedAt.toIso8601String(), | |
"status": status, | |
"point": point, | |
}; | |
} | |
enum Deskripsi { LOREM_IMPSUM } | |
final deskripsiValues = EnumValues({ | |
"Lorem impsum": Deskripsi.LOREM_IMPSUM | |
}); | |
class EnumValues<T> { | |
Map<String, T> map; | |
Map<T, String> reverseMap; | |
EnumValues(this.map); | |
Map<T, String> get reverse { | |
if (reverseMap == null) { | |
reverseMap = map.map((k, v) => new MapEntry(v, k)); | |
} | |
return reverseMap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment