import 'package:test_sa/models/new_models/room_model.dart'; import '../base.dart'; class Department extends Base { Department({ this.id, this.departmentName, this.departmentCode, this.departmentId, this.ntCode, this.rooms, }) : super(identifier: id?.toString() ?? '', name: departmentName); // Handle potential null id Department.fromJson(dynamic json) { id = json['id']??json['departmentId']; identifier = id?.toString() ?? ''; // Handle potential null id departmentName = json['departmentName'] ?? json['name']; name = departmentName; departmentCode = json['departmentCode']; departmentId = json['departmentId']; ntCode = json['ntCode']; if (json['rooms'] != null) { rooms = []; json['rooms'].forEach((v) { rooms!.add(Rooms.fromJson(v)); // Use '!' since rooms is non-nullable after initialization }); } else if (json['assetInventoryRooms'] != null) { rooms = []; json['assetInventoryRooms'].forEach((v) { rooms!.add(Rooms.fromJson(v)); // Use '!' since rooms is non-nullable after initialization }); } } num? id; // Now nullable String? departmentName; // Now nullable String? departmentCode; // Now nullable dynamic departmentId; // Now nullable String? ntCode; // Now nullable List? rooms=[]; // Now nullable Department copyWith({ num? id, // Parameters are now nullable String? departmentName, String? departmentCode, String? departmentId, String? ntCode, List? rooms, }) => Department( id: id ?? this.id, departmentName: departmentName ?? this.departmentName, departmentCode: departmentCode ?? this.departmentCode, departmentId: departmentId ?? this.departmentId, ntCode: ntCode ?? this.ntCode, rooms: rooms ?? this.rooms, ); Map toJson() { final map = {}; map['id'] = id; map['departmentName'] = departmentName; map['departmentCode'] = departmentCode; map['departmentId'] = departmentId; map['ntCode'] = ntCode; if (rooms != null) { map['rooms'] = rooms!.map((v) => v.toJson()).toList(); // Use '!' since rooms could be null } return map; } }