| @@ -44,8 +44,7 @@ abstract class RestClient { | |||
| Future<Account> updateProfile(@Body() Account account); | |||
| @GET("/api/list-supplies-in-warehouses/{type}?q={query}") | |||
| Future<List<Supply>> getSupplies(@Path() String type, | |||
| {@DioOptions() Options options, @Path() String query = ""}); | |||
| Future<List<Supply>> getSupplies(@Path() String type, {@DioOptions() Options options, @Path() String query = ""}); | |||
| //Common | |||
| @PUT("/api/update-fcmToken") | |||
| @@ -55,10 +54,8 @@ abstract class RestClient { | |||
| Future<void> deleteFcmToken(@Body() String token); | |||
| //Plot | |||
| @GET( | |||
| "/api/_search/tb-crops?page={page}&size={size}&sort=id,asc&query={query}") | |||
| Future<List<TbCropDTO>> getPlots( | |||
| {@Path() int page = 0, @Path() int size = 20, @Path() String query = ""}); | |||
| @GET("/api/_search/tb-crops?page={page}&size={size}&sort=id,asc&query={query}") | |||
| Future<List<TbCropDTO>> getPlots({@Path() int page = 0, @Path() int size = 20, @Path() String query = ""}); | |||
| //TODO: check clean code | |||
| @GET("/api/listActivityTypesOther") | |||
| @@ -80,46 +77,26 @@ abstract class RestClient { | |||
| Future<void> updateNoti(@Body() UpdateNoti updateNoti); | |||
| @GET("/api/tb-countries?page={page}&size={size}&query={query}&&sort=name,ASC") | |||
| Future<List<LocationUnit>> getCountries( | |||
| {@Path() int page = 0, | |||
| @Path() int size = 400, | |||
| @Path() String query = '', | |||
| @DioOptions() Options options}); | |||
| @GET( | |||
| "/api/tb-cities-by-country/{countryId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||
| Future<List<LocationUnit>> getCountries({@Path() int page = 0, @Path() int size = 400, @Path() String query = '', @DioOptions() Options options}); | |||
| @GET("/api/tb-cities-by-country/{countryId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||
| Future<List<LocationUnit>> getProvinces(@Path() int countryId, | |||
| {@Path() int page = 0, | |||
| @Path() int size = 20, | |||
| @Path() String query = '', | |||
| @DioOptions() Options options}); | |||
| {@Path() int page = 0, @Path() int size = 20, @Path() String query = '', @DioOptions() Options options}); | |||
| @GET( | |||
| "/api/tb-districts-by-city/{provinceId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||
| @GET("/api/tb-districts-by-city/{provinceId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||
| Future<List<LocationUnit>> getDistricts(@Path() int provinceId, | |||
| {@Path() int page = 0, | |||
| @Path() int size = 20, | |||
| @Path() String query = '', | |||
| @DioOptions() Options options}); | |||
| {@Path() int page = 0, @Path() int size = 20, @Path() String query = '', @DioOptions() Options options}); | |||
| @GET( | |||
| "/api/tb-wards-by-district/{districtId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||
| @GET("/api/tb-wards-by-district/{districtId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||
| Future<List<LocationUnit>> getWards(@Path() int districtId, | |||
| {@Path() int page = 0, | |||
| @Path() int size = 20, | |||
| @Path() String query = '', | |||
| @DioOptions() Options options}); | |||
| {@Path() int page = 0, @Path() int size = 20, @Path() String query = '', @DioOptions() Options options}); | |||
| //Crop | |||
| @GET( | |||
| "/api/tb-crops-detail-for-app/{cropId}?page={page}&size={size}&sort=executeDate,DESC") | |||
| Future<CropPlot> getCropDetail(@Path() int cropId, | |||
| {@Path() int page = 0, @Path() int size = 20}); | |||
| @GET("/api/tb-crops-detail-for-app/{cropId}?page={page}&size={size}&sort=executeDate,DESC") | |||
| Future<CropPlot> getCropDetail(@Path() int cropId, {@Path() int page = 0, @Path() int size = 20}); | |||
| @GET( | |||
| "/api/tb-crops-scan-qrCode/{cropCode}?page={page}&size={size}&sort=executeDate,DESC") | |||
| Future<CropPlot> getCropDetailByCode(@Path() String cropCode, | |||
| {@Path() int page = 0, @Path() int size = 20}); | |||
| @GET("/api/tb-crops-scan-qrCode/{cropCode}") | |||
| Future<CropPlot> getCropDetailByCode(@Path() String cropCode); | |||
| @PUT("/api/tb-crops") | |||
| Future<void> updateCrop(@Body() TbCropDTO crop); | |||
| @@ -128,16 +105,11 @@ abstract class RestClient { | |||
| Future<List<Device>> getDevices({@Path() String query}); | |||
| //Get environment parameter | |||
| @GET("/api/list-environment-updates-display/{cropId}?page={page}&size={size}") | |||
| Future<List<EnvironmentParameter>> getEnvironmentParameters( | |||
| @Path() int cropId, | |||
| {@Path() int page = 0, | |||
| @Path() int size = 20}); | |||
| Future<List<EnvironmentParameter>> getEnvironmentParameters(@Path() int cropId, {@Path() int page = 0, @Path() int size = 20}); | |||
| //NEW Activity implement | |||
| @GET('/api/display-object-param-dynamic-form/{idAction}') | |||
| Future<ActionUIForm> getActionUIForm( | |||
| @Path() idAction, @DioOptions() Options options); | |||
| Future<ActionUIForm> getActionUIForm(@Path() idAction, @DioOptions() Options options); | |||
| @GET('/api/get-detail-common-activity/{actionType}/{activityId}') | |||
| Future<RequestActivity> getDetailActivityCommon( | |||
| {@required @Path() String actionType, @required @Path() int activityId}); | |||
| Future<RequestActivity> getDetailActivityCommon({@required @Path() String actionType, @required @Path() int activityId}); | |||
| } | |||
| @@ -322,13 +322,13 @@ class _RestClient implements RestClient { | |||
| } | |||
| @override | |||
| Future<CropPlot> getCropDetailByCode(cropCode, {page = 0, size = 20}) async { | |||
| Future<CropPlot> getCropDetailByCode(cropCode) async { | |||
| ArgumentError.checkNotNull(cropCode, 'cropCode'); | |||
| const _extra = <String, dynamic>{}; | |||
| final queryParameters = <String, dynamic>{}; | |||
| queryParameters.removeWhere((k, v) => v == null); | |||
| final _data = <String, dynamic>{}; | |||
| final _result = await _dio.request<Map<String, dynamic>>('/api/tb-crops-scan-qrCode/$cropCode?page=$page&size=$size&sort=executeDate,DESC', | |||
| final _result = await _dio.request<Map<String, dynamic>>('/api/tb-crops-scan-qrCode/$cropCode', | |||
| queryParameters: queryParameters, | |||
| options: RequestOptions(method: 'GET', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||
| data: _data); | |||
| @@ -27,22 +27,19 @@ class Repository { | |||
| Future<List<ActionType>> getActionTypes() { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions( | |||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| return client.getActionTypes(options: op); | |||
| } | |||
| Future<List<Harvest>> getHarvests() { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions( | |||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| return client.getHarvests(options: op); | |||
| } | |||
| Future<List<WaterType>> getWaterTypes() { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions( | |||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| return client.getWaterTypes(options: op); | |||
| } | |||
| @@ -51,9 +48,9 @@ class Repository { | |||
| return client.getCropDetail(cropId, page: page, size: size); | |||
| } | |||
| Future<CropPlot> getPlotDetailByCode(String cropCode, {int page, int size}) { | |||
| Future<CropPlot> getPlotDetailByCode(String cropCode) { | |||
| final client = RestClient(dio); | |||
| return client.getCropDetailByCode(cropCode, page: page, size: size); | |||
| return client.getCropDetailByCode(cropCode); | |||
| } | |||
| Future<List<TbCropDTO>> getPlots({int page, int size, String searchString}) { | |||
| @@ -71,11 +68,9 @@ class Repository { | |||
| return client.login(UserRequest(username: username, password: password)); | |||
| } | |||
| Future<PagedResult<T>> getInfinityList<T>(String url, | |||
| {int page = 0, int size = 20}) async { | |||
| Future<PagedResult<T>> getInfinityList<T>(String url, {int page = 0, int size = 20}) async { | |||
| var initUrl = "/api/activities/latest-env-by-activity-type/1/2"; | |||
| var url = | |||
| ConstCommon.baseUrl + initUrl + "?page=$page&paged=true&size=$size"; | |||
| var url = ConstCommon.baseUrl + initUrl + "?page=$page&paged=true&size=$size"; | |||
| var response = await dio.get(url); | |||
| final value = PagedResult<T>.fromJson(response.data, getInstanceClass()); | |||
| @@ -84,15 +79,13 @@ class Repository { | |||
| Future<List<Supply>> getSupplies(String type, {String query = ""}) async { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions( | |||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| return client.getSupplies(type, query: query, options: op); | |||
| } | |||
| Future<List<Device>> getDeviceForActivity() async { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions( | |||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| return client.getDeviceForActivity(options: op); | |||
| } | |||
| @@ -106,38 +99,27 @@ class Repository { | |||
| return client.updateNoti(updateNoti); | |||
| } | |||
| Future<NotificationObjectDTO> getNotifications( | |||
| {int page = 0, int size = 20}) async { | |||
| var url = ConstCommon.baseUrl + | |||
| "/api/notifications-current-user?page=$page&size=$size&sort=sendDate,DESC"; | |||
| Future<NotificationObjectDTO> getNotifications({int page = 0, int size = 20}) async { | |||
| var url = ConstCommon.baseUrl + "/api/notifications-current-user?page=$page&size=$size&sort=sendDate,DESC"; | |||
| var response = await dio.get(url); | |||
| final value = NotificationObjectDTO.fromJson(response.data); | |||
| return value; | |||
| } | |||
| Future<List<LocationUnit>> getLocationUnits( | |||
| {@required LocationType locationType, | |||
| int filterId, | |||
| int page = 0, | |||
| int size = 500, | |||
| String query = ''}) { | |||
| Future<List<LocationUnit>> getLocationUnits({@required LocationType locationType, int filterId, int page = 0, int size = 500, String query = ''}) { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions( | |||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var response; | |||
| switch (locationType) { | |||
| case LocationType.province: | |||
| response = client.getProvinces(filterId, | |||
| options: op, page: page, size: size, query: query); | |||
| response = client.getProvinces(filterId, options: op, page: page, size: size, query: query); | |||
| break; | |||
| case LocationType.district: | |||
| response = client.getDistricts(filterId, | |||
| options: op, page: page, size: size, query: query); | |||
| response = client.getDistricts(filterId, options: op, page: page, size: size, query: query); | |||
| break; | |||
| case LocationType.ward: | |||
| response = client.getWards(filterId, | |||
| options: op, page: page, size: size, query: query); | |||
| response = client.getWards(filterId, options: op, page: page, size: size, query: query); | |||
| break; | |||
| default: | |||
| response = client.getCountries(query: query); | |||
| @@ -154,21 +136,15 @@ class Repository { | |||
| } | |||
| //Action | |||
| Future<void> createAction( | |||
| Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {String apiAddAction, | |||
| String paramActivity, | |||
| String activityAction, | |||
| List<String> filePaths}) async { | |||
| Future<void> createAction(Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {String apiAddAction, String paramActivity, String activityAction, List<String> filePaths}) async { | |||
| var formData = FormData(); | |||
| filePaths.forEach((f) { | |||
| formData.files.add(MapEntry("images", MultipartFile.fromFileSync(f))); | |||
| }); | |||
| formData.fields.add(MapEntry(paramActivity, activityAction)); | |||
| try { | |||
| await dio | |||
| .post("${ConstCommon.baseUrl}/$apiAddAction", data: formData) | |||
| .then((value) { | |||
| await dio.post("${ConstCommon.baseUrl}/$apiAddAction", data: formData).then((value) { | |||
| onSuccess(value.data); | |||
| }); | |||
| } on DioError catch (e) { | |||
| @@ -176,21 +152,15 @@ class Repository { | |||
| } | |||
| } | |||
| Future<void> updateAction( | |||
| Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {String apiUpdateAction, | |||
| String paramActivity, | |||
| String activityAction, | |||
| List<String> filePaths}) async { | |||
| Future<void> updateAction(Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {String apiUpdateAction, String paramActivity, String activityAction, List<String> filePaths}) async { | |||
| var formData = FormData(); | |||
| filePaths.forEach((f) { | |||
| formData.files.add(MapEntry("images", MultipartFile.fromFileSync(f))); | |||
| }); | |||
| formData.fields.add(MapEntry(paramActivity, activityAction)); | |||
| try { | |||
| await dio | |||
| .post("${ConstCommon.baseUrl}/$apiUpdateAction", data: formData) | |||
| .then((value) { | |||
| await dio.post("${ConstCommon.baseUrl}/$apiUpdateAction", data: formData).then((value) { | |||
| onSuccess(value.data); | |||
| }); | |||
| } on DioError catch (e) { | |||
| @@ -205,23 +175,18 @@ class Repository { | |||
| } | |||
| //Environment Parameter | |||
| Future<List<EnvironmentParameter>> getEnvironmentParameters( | |||
| {@required int cropId, int page, int size}) { | |||
| Future<List<EnvironmentParameter>> getEnvironmentParameters({@required int cropId, int page, int size}) { | |||
| final client = RestClient(dio); | |||
| return client.getEnvironmentParameters(cropId, page: page, size: size); | |||
| } | |||
| //NEW IMPLEMENT | |||
| Future<void> allActionTypes(int cropTypeId, | |||
| Function(List<ActionType>) onSuccess, Function(dynamic) onError) async { | |||
| Future<void> allActionTypes(int cropTypeId, Function(List<ActionType>) onSuccess, Function(dynamic) onError) async { | |||
| try { | |||
| var url = | |||
| '${ConstCommon.baseUrl}/api/listActivityTypesCulture/$cropTypeId'; | |||
| var url = '${ConstCommon.baseUrl}/api/listActivityTypesCulture/$cropTypeId'; | |||
| final Response<List<dynamic>> _result = await dio.get(url); | |||
| var value = _result.data | |||
| .map((dynamic i) => ActionType.fromJson(i as Map<String, dynamic>)) | |||
| .toList(); | |||
| var value = _result.data.map((dynamic i) => ActionType.fromJson(i as Map<String, dynamic>)).toList(); | |||
| onSuccess(value); | |||
| } on DioError catch (e) { | |||
| onError(e); | |||
| @@ -230,39 +195,27 @@ class Repository { | |||
| Future<ActionUIForm> getActionUIForm({@required int idAction}) { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions( | |||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||
| return client.getActionUIForm(idAction, op); | |||
| } | |||
| Future<List<CommonData>> getCommonData( | |||
| {String tableSupply, String condition}) async { | |||
| var url = | |||
| '${ConstCommon.baseUrl}/api/get-data-from-table-common?tableName=$tableSupply&condition=$condition'; | |||
| Future<List<CommonData>> getCommonData({String tableSupply, String condition}) async { | |||
| var url = '${ConstCommon.baseUrl}/api/get-data-from-table-common?tableName=$tableSupply&condition=$condition'; | |||
| final Response<List<dynamic>> _result = await dio.get(url); | |||
| var value = _result.data | |||
| .map((dynamic i) => CommonData.fromJson(i as Map<String, dynamic>)) | |||
| .toList(); | |||
| var value = _result.data.map((dynamic i) => CommonData.fromJson(i as Map<String, dynamic>)).toList(); | |||
| return value; | |||
| } | |||
| Future<void> createActionCommon( | |||
| Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {@required String activityType, | |||
| @required String activityData, | |||
| List<String> filePaths}) async { | |||
| Future<void> createActionCommon(Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {@required String activityType, @required String activityData, List<String> filePaths}) async { | |||
| var formData = FormData(); | |||
| filePaths.forEach((f) { | |||
| formData.files.add(MapEntry('images', MultipartFile.fromFileSync(f))); | |||
| }); | |||
| formData.fields.add(MapEntry('tbCommonActivityDTO', activityData)); | |||
| try { | |||
| await dio | |||
| .post( | |||
| "${ConstCommon.baseUrl}/api/create-common-activity/$activityType", | |||
| data: formData) | |||
| .then((value) { | |||
| await dio.post("${ConstCommon.baseUrl}/api/create-common-activity/$activityType", data: formData).then((value) { | |||
| onSuccess(value.data); | |||
| }); | |||
| } on DioError catch (e) { | |||
| @@ -270,22 +223,15 @@ class Repository { | |||
| } | |||
| } | |||
| Future<void> updateActionCommon( | |||
| Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {@required String activityType, | |||
| @required String activityData, | |||
| List<String> filePaths}) async { | |||
| Future<void> updateActionCommon(Function(dynamic) onSuccess, Function(dynamic) onError, | |||
| {@required String activityType, @required String activityData, List<String> filePaths}) async { | |||
| var formData = FormData(); | |||
| filePaths.forEach((f) { | |||
| formData.files.add(MapEntry('images', MultipartFile.fromFileSync(f))); | |||
| }); | |||
| formData.fields.add(MapEntry('tbCommonActivityDTO', activityData)); | |||
| try { | |||
| await dio | |||
| .post( | |||
| "${ConstCommon.baseUrl}/api/update-common-activity/$activityType", | |||
| data: formData) | |||
| .then((value) { | |||
| await dio.post("${ConstCommon.baseUrl}/api/update-common-activity/$activityType", data: formData).then((value) { | |||
| onSuccess(value.data); | |||
| }); | |||
| } on DioError catch (e) { | |||
| @@ -293,10 +239,8 @@ class Repository { | |||
| } | |||
| } | |||
| Future<RequestActivity> detailCommonAction( | |||
| {@required int activityId, @required String activityType}) async { | |||
| Future<RequestActivity> detailCommonAction({@required int activityId, @required String activityType}) async { | |||
| final client = RestClient(dio); | |||
| return client.getDetailActivityCommon( | |||
| actionType: activityType, activityId: activityId); | |||
| return client.getDetailActivityCommon(actionType: activityType, activityId: activityId); | |||
| } | |||
| } | |||
| @@ -73,7 +73,7 @@ _showAlertCheckCropCode(String cropCode) async { | |||
| var repository = Repository(); | |||
| Get.defaultDialog(title: "Kiểm tra thông tin lô ....", middleText: "", content: CircularProgressIndicator()); | |||
| try { | |||
| await repository.getPlotDetailByCode(cropCode, page: 1, size: 1).then((value) { | |||
| await repository.getPlotDetailByCode(cropCode).then((value) { | |||
| print("ok"); | |||
| if (Get.isDialogOpen) Get.back(); | |||
| Get.to(PlotDetailScreen(cropId: value.tbCropDTO.id, cropType: value.tbCropDTO.tbCropTypeId, initialIndex: 0)); | |||
| @@ -19,30 +19,18 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { | |||
| Stream<PlotDetailState> mapEventToState( | |||
| PlotDetailEvent event, | |||
| ) async* { | |||
| if (event is DataFetched && | |||
| !(state is PlotDetailSuccess && | |||
| (state as PlotDetailSuccess).hasReachedMax)) { | |||
| if (event is DataFetched && !(state is PlotDetailSuccess && (state as PlotDetailSuccess).hasReachedMax)) { | |||
| try { | |||
| if (state is PlotDetailInitial) { | |||
| yield PlotDetailLoading(); | |||
| var response; | |||
| if (event.cropId != null) { | |||
| response = await repository.getPlotDetail(event.cropId, | |||
| page: 0, size: pageSize); | |||
| yield PlotDetailSuccess( | |||
| items: response.activities, | |||
| page: 0, | |||
| hasReachedMax: | |||
| response.activities.length < pageSize ? true : false); | |||
| response = await repository.getPlotDetail(event.cropId, page: 0, size: pageSize); | |||
| yield PlotDetailSuccess(items: response.activities, page: 0, hasReachedMax: response.activities.length < pageSize ? true : false); | |||
| } else { | |||
| CropPlot response = await repository | |||
| .getPlotDetailByCode(event.cropCode, page: 0, size: pageSize); | |||
| CropPlot response = await repository.getPlotDetailByCode(event.cropCode); | |||
| yield PlotDetailSuccess( | |||
| ownerItem: response, | |||
| items: response.activities, | |||
| page: 0, | |||
| hasReachedMax: true); | |||
| yield PlotDetailSuccess(ownerItem: response, items: response.activities, page: 0, hasReachedMax: true); | |||
| } | |||
| } | |||
| if (state is PlotDetailSuccess) { | |||
| @@ -50,24 +38,13 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { | |||
| int page = currentState.page + 1; | |||
| var response; | |||
| if (event.cropId != null) { | |||
| response = await repository.getPlotDetail(event.cropId, | |||
| page: page, size: pageSize); | |||
| response = await repository.getPlotDetail(event.cropId, page: page, size: pageSize); | |||
| yield response.activities.isEmpty | |||
| ? currentState.copyWith(hasReachedMax: true) | |||
| : PlotDetailSuccess( | |||
| items: currentState.items + response.activities, | |||
| page: currentState.page + 1, | |||
| hasReachedMax: false); | |||
| : PlotDetailSuccess(items: currentState.items + response.activities, page: currentState.page + 1, hasReachedMax: false); | |||
| } else { | |||
| CropPlot response = await repository.getPlotDetailByCode( | |||
| event.cropCode, | |||
| page: page, | |||
| size: pageSize); | |||
| yield PlotDetailSuccess( | |||
| ownerItem: response, | |||
| items: response.activities, | |||
| page: 0, | |||
| hasReachedMax: true); | |||
| CropPlot response = await repository.getPlotDetailByCode(event.cropCode); | |||
| yield PlotDetailSuccess(ownerItem: response, items: response.activities, page: 0, hasReachedMax: true); | |||
| } | |||
| } | |||
| } catch (e) { | |||
| @@ -80,18 +57,12 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { | |||
| yield PlotDetailLoading(); | |||
| var response; | |||
| if (event.cropId != null) { | |||
| response = await repository.getPlotDetail(event.cropId, | |||
| page: 0, size: pageSize); | |||
| response = await repository.getPlotDetail(event.cropId, page: 0, size: pageSize); | |||
| } else { | |||
| response = await repository.getPlotDetailByCode(event.cropCode, | |||
| page: 0, size: pageSize); | |||
| response = await repository.getPlotDetailByCode(event.cropCode); | |||
| } | |||
| CropPlot cropPlot = response as CropPlot; | |||
| yield PlotDetailSuccess( | |||
| ownerItem: cropPlot, | |||
| page: 0, | |||
| hasReachedMax: | |||
| response.activities.length < pageSize ? true : false); | |||
| yield PlotDetailSuccess(ownerItem: cropPlot, page: 0, hasReachedMax: response.activities.length < pageSize ? true : false); | |||
| } catch (e) { | |||
| yield PlotDetailFailure(errorString: AppException.handleError(e)); | |||
| } | |||
| @@ -101,28 +72,19 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { | |||
| yield PlotDetailLoading(); | |||
| var response; | |||
| if (event.cropId != null) { | |||
| response = await repository.getPlotDetail(event.cropId, | |||
| page: 0, size: pageSize); | |||
| response = await repository.getPlotDetail(event.cropId, page: 0, size: pageSize); | |||
| } else { | |||
| response = await repository.getPlotDetailByCode(event.cropCode, | |||
| page: 0, size: pageSize); | |||
| response = await repository.getPlotDetailByCode(event.cropCode); | |||
| } | |||
| yield PlotDetailSuccess( | |||
| items: response.activities, | |||
| page: 0, | |||
| hasReachedMax: | |||
| response.activities.length < pageSize ? true : false); | |||
| yield PlotDetailSuccess(items: response.activities, page: 0, hasReachedMax: response.activities.length < pageSize ? true : false); | |||
| } catch (e) { | |||
| yield PlotDetailFailure(errorString: AppException.handleError(e)); | |||
| } | |||
| } else if (event is OnUpdate) { | |||
| yield PlotDetailLoading(); | |||
| try { | |||
| yield PlotDetailSuccess( | |||
| items: event.currentItems, | |||
| page: event.currentPage, | |||
| hasReachedMax: event.hasReachedMax); | |||
| yield PlotDetailSuccess(items: event.currentItems, page: event.currentPage, hasReachedMax: event.hasReachedMax); | |||
| } catch (e) { | |||
| yield PlotDetailFailure(errorString: AppException.handleError(e)); | |||
| } | |||
| @@ -299,7 +299,7 @@ class _TabbarScreenState extends State<TabbarScreen> { | |||
| var repository = Repository(); | |||
| Get.defaultDialog(title: "Kiểm tra thông tin lô ....", middleText: "", content: CircularProgressIndicator()); | |||
| try { | |||
| await repository.getPlotDetailByCode(cropCode, page: 1, size: 1).then((value) { | |||
| await repository.getPlotDetailByCode(cropCode).then((value) { | |||
| print("ok"); | |||
| if (Get.isDialogOpen) Get.back(); | |||
| Get.to(PlotDetailScreen(cropId: value.tbCropDTO.id, cropType: value.tbCropDTO.tbCropTypeId, initialIndex: 0)); | |||