You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
Dart
43 lines
1.4 KiB
Dart
import 'package:diplomaticquarterapp/core/model/pharmacies/pharmacies_list_model.dart';
|
|
import '../../locator.dart';
|
|
import 'base_view_model.dart';
|
|
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
|
import 'package:diplomaticquarterapp/core/model/pharmacies/pharmacies_model.dart';
|
|
import 'package:diplomaticquarterapp/core/service/pharmacies_service.dart';
|
|
|
|
class PharmacyViewModel extends BaseViewModel {
|
|
bool isFinished = true;
|
|
bool hasError = false;
|
|
String errorMsg = '';
|
|
PharmacyService _pharmacyService = locator<PharmacyService>();
|
|
|
|
List<PharmaciesModel> get pharmacy => _pharmacyService.medicineItem;
|
|
List<PharmaciesListModel> get pharmacyList => _pharmacyService.pharmaciesList;
|
|
|
|
Future getPharmacies({int id}) async {
|
|
setState(ViewState.Busy);
|
|
|
|
await _pharmacyService.getPharmaciesList(itemID: id);
|
|
if (_pharmacyService.hasError) {
|
|
error = _pharmacyService.error;
|
|
setState(ViewState.Error);
|
|
} else
|
|
setState(ViewState.Idle);
|
|
}
|
|
|
|
clearMedicineSearch(){
|
|
_pharmacyService.clearMedicineList();
|
|
}
|
|
Future getMedicine({String name}) async {
|
|
hasError = false;
|
|
_pharmacyService.clearMedicineList();
|
|
setState(ViewState.BusyLocal);
|
|
await _pharmacyService.getMedicineList(drugName: name);
|
|
if (_pharmacyService.hasError) {
|
|
error = _pharmacyService.error;
|
|
setState(ViewState.ErrorLocal);
|
|
} else
|
|
setState(ViewState.Idle);
|
|
}
|
|
}
|