import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/service/patientInPatientService.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import '../../locator.dart'; import 'base_view_model.dart'; class PatientSearchViewModel extends BaseViewModel { PatientInPatientService _inPatientService = locator(); List get _inPatientList => _inPatientService.inPatientList; List filteredInPatientItems = List(); Future getInPatientList(PatientSearchRequestModel requestModel, {bool isMyInpatient = false, bool isFirstTime = true}) async { if (isFirstTime) setState(ViewState.Busy); else setState(ViewState.BusyLocal); await _inPatientService.getInPatientList(requestModel, isMyInpatient); if (_inPatientService.hasError) { error = _inPatientService.error; setState(ViewState.Error); } else { filteredInPatientItems.clear(); if (_inPatientList.length > 0) filteredInPatientItems.addAll(_inPatientList); setState(ViewState.Idle); } } void filterSearchResults(String query) { var strExist = query.length > 0 ? true : false; if (strExist) { filteredInPatientItems = []; for (var i = 0; i < _inPatientList.length; i++) { String firstName = _inPatientList[i].firstName.toUpperCase(); String lastName = _inPatientList[i].lastName.toUpperCase(); String mobile = _inPatientList[i].mobileNumber.toUpperCase(); String patientID = _inPatientList[i].patientId.toString(); if (firstName.contains(query.toUpperCase()) || lastName.contains(query.toUpperCase()) || mobile.contains(query) || patientID.contains(query)) { filteredInPatientItems.add(_inPatientList[i]); } } notifyListeners(); } else { if (_inPatientList.length > 0) filteredInPatientItems.clear(); filteredInPatientItems.addAll(_inPatientList); notifyListeners(); } } }