You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/models/new_models/department.dart

73 lines
2.2 KiB
Dart

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>? rooms=[]; // Now nullable
Department copyWith({
num? id, // Parameters are now nullable
String? departmentName,
String? departmentCode,
String? departmentId,
String? ntCode,
List<Rooms>? 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<String, dynamic> toJson() {
final map = <String, dynamic>{};
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;
}
}