import 'package:test_sa/models/device/supplier.dart'; class ModelDefinition { ModelDefinition({ this.id, this.assetName, this.assetDescription, this.modelDefCode, this.modelName, this.manufacturerId, this.manufacturerName, this.supplierName, this.replacementDate, this.essentialEquipement, this.businessCritical, this.lifeSpan, this.modelDefRelatedDefects, this.suppliers, }); ModelDefinition.fromJson(dynamic json) { id = json['id']; assetName = json['assetName']; assetDescription = json['assetDescription']; modelDefCode = json['modelDefCode']; modelName = json['modelName']; manufacturerId = json['manufacturerId']; manufacturerName = json['manufacturerName']; supplierName = json['supplierName']; replacementDate = json['replacementDate']; essentialEquipement = json['essentialEquipement']; businessCritical = json['businessCritical']; lifeSpan = json['lifeSpan']; if (json['modelDefRelatedDefects'] != null) { modelDefRelatedDefects = []; json['modelDefRelatedDefects'].forEach((v) { modelDefRelatedDefects!.add(ModelDefRelatedDefects.fromJson(v)); // Use '!' since modelDefRelatedDefects is initialized here }); } if (json['suppliers'] != null) { suppliers = []; json['suppliers'].forEach((v) { suppliers!.add(Supplier.fromJson(v)); // Use '!' since suppliers is initialized here }); } } num? id; // Now nullable String? assetName; // Now nullable String? assetDescription; // Now nullable String? modelDefCode; // Now nullable String? modelName; // Now nullable num? manufacturerId; // Now nullable String? manufacturerName; // Now nullable String? supplierName; // Remains dynamic asit can hold various types String? replacementDate; // Now nullable String? essentialEquipement; // Now nullable String? businessCritical; // Now nullable num? lifeSpan; // Now nullable List? modelDefRelatedDefects; // Now nullable List? suppliers; // Now nullable // ... (copyWith method remains the same, just with nullable parameters) Map toJson() { final map = {}; map['id'] = id; map['assetName'] = assetName; // ... (rest of the toJson method remains the same, no need for null-aware operator here as properties are already checked for null in the if conditions) if (modelDefRelatedDefects != null) { map['modelDefRelatedDefects'] = modelDefRelatedDefects!.map((v) => v.toJson()).toList(); // Use '!' since modelDefRelatedDefects could be null } if (suppliers != null) { map['suppliers'] = suppliers!.map((v) => v.toJson()).toList(); // Use '!' since suppliers could be null } return map; } } class ModelDefRelatedDefects { ModelDefRelatedDefects({ this.id, this.defectName, this.workPerformed, this.estimatedTime, }); ModelDefRelatedDefects.fromJson(dynamic json) { id = json['id']; defectName = json['defectName']; workPerformed = json['workPerformed']; estimatedTime = json['estimatedTime']; } num? id; // Now nullable String? defectName; // Now nullable String? workPerformed; // Now nullable String? estimatedTime; // Now nullable // ... (copyWith method remains the same, just with nullable parameters) Map toJson() { final map = {}; map['id'] = id; map['defectName'] = defectName; map['workPerformed'] = workPerformed; map['estimatedTime'] = estimatedTime; return map; } }