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/floor.dart

61 lines
1.8 KiB
Dart

import 'package:test_sa/models/base.dart';
import 'package:test_sa/models/new_models/department.dart';
class Floor extends Base {
Floor({
this.id,
String? name, // Name is now nullable
this.value,
this.departments,
}) : super(identifier: id?.toString() ?? '', name: name); // Handle potentialnull id
Floor.fromJson(dynamic json) {
id = json['id']??json['floorId'];
identifier = id?.toString() ?? ''; // Handle potential null id
name = json['name']??json['floorName'];
value = json['value'];
if (json['departments'] != null) {
departments = [];
json['departments'].forEach((v) {
departments!.add(Department.fromJson(v)); // Use '!' since departments is non-nullable after initialization
});
}
else if (json['assetInventoryDepartments'] != null) {
departments = [];
json['assetInventoryDepartments'].forEach((v) {
departments!.add(Department.fromJson(v)); // Use '!' since departments is non-nullable after initialization
});
}
}
num? id; // Now nullable
num? value; //Now nullable
List<Department>? departments; // Now nullable
Floor copyWith({
num? id, // Parameters are now nullable
String? name,
num? value,
List<Department>? departments,
}) =>
Floor(
id: id ?? this.id,
name: name ?? this.name,
value: value ?? this.value,
departments: departments ?? this.departments,
);
Map<String, dynamic> toJson({bool addDepartments = true}) {
final map = <String, dynamic>{};
map['id'] = id;
map['name'] = name;
map['value'] = value;
if (addDepartments) {
if (departments != null) {
map['departments'] = departments!.map((v) => v.toJson()).toList(); // Use '!' since departments could be null
}
}
return map;
}
}