import 'dart:convert'; class SceneModel { final String id; final String name; final Status status; final Type type; SceneModel({ required this.id, required this.name, required this.status, required this.type, }); factory SceneModel.fromRawJson(String str) => SceneModel.fromJson(json.decode(str)); String toRawJson() => json.encode(toJson()); factory SceneModel.fromJson(Map json) => SceneModel( id: json["id"], name: json["name"], status: statusValues.map[json["status"]]!, type: typeValues.map[json["type"]]!, ); Map toJson() => { "id": id, "name": name, "status": statusValues.reverse[status], "type": typeValues.reverse[type], }; } enum Status { ENABLE } final statusValues = EnumValues({"enable": Status.ENABLE}); enum Type { TAP_TO_RUN } final typeValues = EnumValues({"tap_to_run": Type.TAP_TO_RUN}); class EnumValues { Map map; late Map reverseMap; EnumValues(this.map); Map get reverse { reverseMap = map.map((k, v) => MapEntry(v, k)); return reverseMap; } }