import 'package:test_sa/models/hospital.dart'; import 'package:test_sa/models/lookup.dart'; class VisitsSearch { String deviceSerialNumber; Hospital hospital; String brand; Lookup model; Lookup contactStatus; DateTime expectedDateFrom; DateTime expectedDateTo; DateTime actualDateFrom; DateTime actualDateTo; Lookup statusValue; VisitsSearch({ this.deviceSerialNumber, this.statusValue, this.brand, this.hospital, this.actualDateTo, this.actualDateFrom, this.model, this.contactStatus, this.expectedDateFrom, this.expectedDateTo, }); fromSearch(VisitsSearch newSearch) { deviceSerialNumber = newSearch.deviceSerialNumber; brand = newSearch.brand; hospital = newSearch.hospital; actualDateTo = newSearch.actualDateTo; actualDateFrom = newSearch.actualDateFrom; model = newSearch.model; contactStatus = newSearch.contactStatus; expectedDateFrom = newSearch.expectedDateFrom; expectedDateTo = newSearch.expectedDateTo; statusValue = newSearch.statusValue; } Map toMap() { Map _search = {}; if (deviceSerialNumber != null && deviceSerialNumber.isNotEmpty) { _search["assetId"] = deviceSerialNumber; } if (hospital != null) { _search["siteId"] = hospital.id; } if (brand != null && brand.isNotEmpty) { // todo get new key _search[""] = brand; } if (model != null) { _search["modelId"] = model.id; } if (expectedDateFrom != null) { _search["expectedDateFrom"] = expectedDateFrom.toIso8601String(); } if (expectedDateTo != null) { _search["expectedDateTo"] = expectedDateTo.toIso8601String(); } if (actualDateFrom != null) { _search["actualDateFrom"] = actualDateFrom.toIso8601String(); } if (actualDateTo != null) { _search["actualDateTo"] = actualDateTo.toIso8601String(); } if (statusValue != null) { _search["visitStatusId"] = statusValue.id; } if (contactStatus != null) { _search["assignedToId"] = contactStatus.id; } return _search; } }