import 'dart:convert'; import 'dart:typed_data'; class ScenesModel { final String id; final String? sceneTuyaId; final String name; final String status; final String type; final String? icon; ScenesModel( {required this.id, this.sceneTuyaId, required this.name, required this.status, required this.type, this.icon}); factory ScenesModel.fromRawJson(String str) => ScenesModel.fromJson(json.decode(str)); String toRawJson() => json.encode(toJson()); Uint8List get iconInBytes => base64Decode(icon ?? ''); factory ScenesModel.fromJson(Map json) { return ScenesModel( id: json["id"] ?? json["uuid"] ?? '', // Fallback to empty string if id is null sceneTuyaId: json["sceneTuyaId"] as String?, // Nullable name: json["name"] ?? '', // Fallback to empty string if name is null status: json["status"] ?? '', // Fallback to empty string if status is null type: json["type"] ?? '', // Fallback to empty string if type is null icon: json["icon"] as String?, // Nullable ); } Map toJson() => { "id": id, "sceneTuyaId": sceneTuyaId ?? '', "name": name, "status": status, "type": type, }; }