| dab672e712362fdbbfa98386624f95d6 | |||||
| 440505e9ea1eee7043d2cbfeb318f6bc |
| var token = await pref.getString(DATA_CONST.TOKEN_KEY); | var token = await pref.getString(DATA_CONST.TOKEN_KEY); | ||||
| options.headers["Authorization"] = "Bearer $token"; | options.headers["Authorization"] = "Bearer $token"; | ||||
| options.receiveTimeout = 20000; | options.receiveTimeout = 20000; | ||||
| // log("onRequest: ${options.uri}\n" | |||||
| // "data=${options.data}\n" | |||||
| // "method=${options.method}\n" | |||||
| // "headers=${options.headers}\n" | |||||
| // "queryParameters=${options.queryParameters}"); | |||||
| log("onRequest: ${options.uri}\n" | |||||
| "data=${options.data}\n" | |||||
| "method=${options.method}\n" | |||||
| "headers=${options.headers}\n" | |||||
| "queryParameters=${options.queryParameters}"); | |||||
| return options; | return options; | ||||
| } | } | ||||
| @PUT("/api/update-my-profile") | @PUT("/api/update-my-profile") | ||||
| Future<Account> updateProfile(@Body() Account account); | Future<Account> updateProfile(@Body() Account account); | ||||
| @GET("/api/list-supplies-in-warehouses/ALL?q={query}") | |||||
| Future<List<Supply>> getSupplies( | |||||
| @GET("/api/list-supplies-in-warehouses/{type}?q={query}") | |||||
| Future<List<Supply>> getSupplies(@Path() String type, | |||||
| {@DioOptions() Options options, @Path() String query = ""}); | {@DioOptions() Options options, @Path() String query = ""}); | ||||
| //Common | //Common |
| } | } | ||||
| @override | @override | ||||
| getSupplies({options, query = ""}) async { | |||||
| getSupplies(type, {options, query = ""}) async { | |||||
| ArgumentError.checkNotNull(type, 'type'); | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| '/api/list-supplies-in-warehouses/ALL?q=$query', | |||||
| '/api/list-supplies-in-warehouses/$type?q=$query', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); |
| return value; | return value; | ||||
| } | } | ||||
| Future<List<Supply>> getSupplies({String query = ""}) async { | |||||
| Future<List<Supply>> getSupplies(String type, {String query = ""}) async { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | var op = buildConfigurableCacheOptions( | ||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | ||||
| return client.getSupplies(query: query, options: op); | |||||
| return client.getSupplies(type, query: query, options: op); | |||||
| } | } | ||||
| Future<List<Device>> getDeviceForActivity() async { | Future<List<Device>> getDeviceForActivity() async { |
| child: Text( | child: Text( | ||||
| plot_action_harvest_process, | plot_action_harvest_process, | ||||
| style: TextStyle( | style: TextStyle( | ||||
| color: Colors.white, fontSize: 16), | |||||
| color: Colors.white, fontSize: 14), | |||||
| ), | ), | ||||
| ), | ), | ||||
| ), | ), | ||||
| child: Text( | child: Text( | ||||
| plot_action_packing, | plot_action_packing, | ||||
| style: TextStyle( | style: TextStyle( | ||||
| color: Colors.white, fontSize: 16), | |||||
| color: Colors.white, fontSize: 14), | |||||
| ), | ), | ||||
| ), | ), | ||||
| ) | ) | ||||
| child: Text( | child: Text( | ||||
| plot_action_sell, | plot_action_sell, | ||||
| style: TextStyle( | style: TextStyle( | ||||
| color: Colors.white, fontSize: 16), | |||||
| color: Colors.white, fontSize: 14), | |||||
| ), | ), | ||||
| ), | ), | ||||
| ) | ) |
| ) async* { | ) async* { | ||||
| if (event is DataFetched) { | if (event is DataFetched) { | ||||
| try { | try { | ||||
| final response = await repository.getSupplies(query: event.type); | |||||
| final response = await repository.getSupplies(event.type); | |||||
| List<Supply> supplies = response.map((supply) { | List<Supply> supplies = response.map((supply) { | ||||
| if (supply.id == event.selectedId) { | if (supply.id == event.selectedId) { | ||||
| supply.isSelected = true; | supply.isSelected = true; | ||||
| } | } | ||||
| } else if (event is OnRefresh) { | } else if (event is OnRefresh) { | ||||
| try { | try { | ||||
| final response = await repository.getSupplies(query: event.type); | |||||
| final response = await repository.getSupplies(event.type); | |||||
| List<Supply> supplies = response.map((supply) { | List<Supply> supplies = response.map((supply) { | ||||
| if (supply.id == event.selectedId) { | if (supply.id == event.selectedId) { | ||||
| supply.isSelected = true; | supply.isSelected = true; | ||||
| } | } | ||||
| } else if (event is OnSearch) { | } else if (event is OnSearch) { | ||||
| try { | try { | ||||
| final response = await repository.getSupplies(query: event.type); | |||||
| bool query(Supply supply) => | |||||
| event.searchString.isEmpty || | |||||
| supply.tbSuppliesName | |||||
| .toLowerCase() | |||||
| .contains(event.searchString.toLowerCase()); | |||||
| final result = response.where(query).toList(); | |||||
| List<Supply> supplies = result.map((supply) { | |||||
| final response = | |||||
| await repository.getSupplies(event.type, query: event.searchString); | |||||
| List<Supply> supplies = response.map((supply) { | |||||
| if (supply.id == event.selectedId) { | if (supply.id == event.selectedId) { | ||||
| supply.isSelected = true; | supply.isSelected = true; | ||||
| } | } |
| static const String supplyTypeDung = "PHANBON"; | static const String supplyTypeDung = "PHANBON"; | ||||
| static const String supplyTypeSubStrate = "GIATHE"; | static const String supplyTypeSubStrate = "GIATHE"; | ||||
| static const String supplyTypeProtectPlant = "THUOCBVTV"; | static const String supplyTypeProtectPlant = "THUOCBVTV"; | ||||
| static const String supplyTypeAll = ""; | |||||
| static const String supplyTypeAll = "ALL"; | |||||
| } | } | ||||
| enum CRUDStatus { unknown, add, edit, delete } | enum CRUDStatus { unknown, add, edit, delete } |