import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/core/service/base_service.dart'; import 'package:diplomaticquarterapp/models/pharmacy/brandModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/topBrandsModel.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; class BrandsService extends BaseService { AppSharedPreferences sharedPref = AppSharedPreferences(); bool isLogin = false; List _brandsList = List(); List get brandsList => _brandsList; List _topBrandsList = List(); List get topBrandsList => _topBrandsList; List _searchList = List(); List get searchList => _searchList; clearSearchList() { _searchList.clear(); } Future getBrands() async { hasError = false; await baseAppClient.getPharmacy(GET_BRANDS, onSuccess: (dynamic response, int statusCode) { _brandsList.clear(); response['manufacturer'].forEach((item) { _brandsList.add(Brand.fromJson(item)); }); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }); } Future getTopBrands() async { hasError = false; await baseAppClient.getPharmacy(GET_TOP_BRANDS, onSuccess: (dynamic response, int statusCode) { _topBrandsList.clear(); response['manufacturer'].forEach((item) { _topBrandsList.add(TopBrand.fromJson(item)); }); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }); } Future searchProducts({String productName}) async { RegExp exp = new RegExp(productName.toUpperCase()); hasError = false; _searchList.clear(); await baseAppClient.getPharmacy( GET_BRANDS, onSuccess: (dynamic response, int statusCode) { response['manufacturer'].forEach((item) { if(exp.hasMatch(item['name'])){ _searchList.add(Brand.fromJson(item)); }else{ } }); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }, ); } }