Files
syncrow-app/lib/features/devices/model/room_model.dart
Mohammad Salameh 5dc4f96a71 Add functionality to fetch devices by room ID
Added a new method in DevicesCubit to fetch devices by room ID and updated
related classes and API calls to support this functionality.
2024-04-02 12:12:54 +03:00

38 lines
809 B
Dart

import 'package:syncrow_app/features/devices/model/device_category_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
class RoomModel {
final int? id;
final String? name;
List<DeviceModel>? devices;
RoomModel({
required this.id,
required this.name,
required this.devices,
});
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'devices': devices,
};
}
factory RoomModel.fromJson(Map<String, dynamic> json) {
List<DeviceModel> devices = [];
if (json['devices'] != null) {
for (var device in json['devices']) {
devices.add(DeviceModel.fromJson(device));
}
}
return RoomModel(
id: json['roomId'],
name: json['roomName'],
devices: devices,
);
}
}