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? departments; // Now nullable Floor copyWith({ num? id, // Parameters are now nullable String? name, num? value, List? departments, }) => Floor( id: id ?? this.id, name: name ?? this.name, value: value ?? this.value, departments: departments ?? this.departments, ); Map toJson({bool addDepartments = true}) { final map = {}; 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; } }