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}) async { setState(ViewState.Busy); await _inPatientService.getInPatientList(requestModel, isMyInpatient); if (_inPatientService.hasError) { error = _inPatientService.error; setState(ViewState.Error); } else { setState(ViewState.Idle); filteredInPatientItems.clear(); filteredInPatientItems.addAll(_inPatientList); } } 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 { filteredInPatientItems = _inPatientList; notifyListeners(); } } }