Files
syncrow-app/lib/features/scene/model/scene_model.dart
2024-06-27 02:35:50 +03:00

55 lines
1.2 KiB
Dart

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<String, dynamic> json) => SceneModel(
id: json["id"],
name: json["name"],
status: statusValues.map[json["status"]]!,
type: typeValues.map[json["type"]]!,
);
Map<String, dynamic> 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<T> {
Map<String, T> map;
late Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
reverseMap = map.map((k, v) => MapEntry(v, k));
return reverseMap;
}
}