| c2bc17b6898e68be8222832a6d5d2d3d | |||||
| 471e09183e20ec9c20cca9b580fecc10 |
| import 'TbCropDTO.dart'; | |||||
| class CropPlot { | class CropPlot { | ||||
| TbCropDTO tbCropDTO; | TbCropDTO tbCropDTO; | ||||
| List<Activities> activities; | List<Activities> activities; | ||||
| } | } | ||||
| } | } | ||||
| class TbCropDTO { | |||||
| int id; | |||||
| String qrCode; | |||||
| String code; | |||||
| num areaM2; | |||||
| int type; | |||||
| String startDate; | |||||
| String endDate; | |||||
| String status; | |||||
| String description; | |||||
| int ageDayStartAt; | |||||
| int tbSuppliesId; | |||||
| String suppliesName; | |||||
| int tbGuidelineId; | |||||
| int netHouseId; | |||||
| String netHouseName; | |||||
| int areaId; | |||||
| String area; | |||||
| List<TbDetailUsers> tbDetailUsers; | |||||
| TbCropDTO( | |||||
| {this.id, | |||||
| this.qrCode, | |||||
| this.code, | |||||
| this.areaM2, | |||||
| this.type, | |||||
| this.startDate, | |||||
| this.endDate, | |||||
| this.status, | |||||
| this.description, | |||||
| this.ageDayStartAt, | |||||
| this.tbSuppliesId, | |||||
| this.suppliesName, | |||||
| this.tbGuidelineId, | |||||
| this.netHouseId, | |||||
| this.netHouseName, | |||||
| this.areaId, | |||||
| this.area, | |||||
| this.tbDetailUsers}); | |||||
| TbCropDTO.fromJson(Map<String, dynamic> json) { | |||||
| id = json['id']; | |||||
| qrCode = json['qrCode']; | |||||
| code = json['code']; | |||||
| areaM2 = json['areaM2']; | |||||
| type = json['type']; | |||||
| startDate = json['startDate']; | |||||
| endDate = json['endDate']; | |||||
| status = json['status']; | |||||
| description = json['description']; | |||||
| ageDayStartAt = json['ageDayStartAt']; | |||||
| tbSuppliesId = json['tbSuppliesId']; | |||||
| suppliesName = json['suppliesName']; | |||||
| tbGuidelineId = json['tbGuidelineId']; | |||||
| netHouseId = json['netHouseId']; | |||||
| netHouseName = json['netHouseName']; | |||||
| areaId = json['areaId']; | |||||
| area = json['area']; | |||||
| if (json['tbDetailUsers'] != null) { | |||||
| tbDetailUsers = new List<TbDetailUsers>(); | |||||
| json['tbDetailUsers'].forEach((v) { | |||||
| tbDetailUsers.add(new TbDetailUsers.fromJson(v)); | |||||
| }); | |||||
| } | |||||
| } | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['qrCode'] = this.qrCode; | |||||
| data['code'] = this.code; | |||||
| data['areaM2'] = this.areaM2; | |||||
| data['type'] = this.type; | |||||
| data['startDate'] = this.startDate; | |||||
| data['endDate'] = this.endDate; | |||||
| data['status'] = this.status; | |||||
| data['description'] = this.description; | |||||
| data['ageDayStartAt'] = this.ageDayStartAt; | |||||
| data['tbSuppliesId'] = this.tbSuppliesId; | |||||
| data['suppliesName'] = this.suppliesName; | |||||
| data['tbGuidelineId'] = this.tbGuidelineId; | |||||
| data['netHouseId'] = this.netHouseId; | |||||
| data['netHouseName'] = this.netHouseName; | |||||
| data['areaId'] = this.areaId; | |||||
| data['area'] = this.area; | |||||
| if (this.tbDetailUsers != null) { | |||||
| data['tbDetailUsers'] = | |||||
| this.tbDetailUsers.map((v) => v.toJson()).toList(); | |||||
| } | |||||
| return data; | |||||
| } | |||||
| } | |||||
| class TbDetailUsers { | class TbDetailUsers { | ||||
| int id; | int id; | ||||
| String fullName; | String fullName; |
| import 'CropPlot.dart'; | |||||
| class TbCropDTO { | |||||
| int id; | |||||
| String qrCode; | |||||
| String code; | |||||
| num areaM2; | |||||
| int tbCropTypeId; | |||||
| String startDate; | |||||
| String endDate; | |||||
| String status; | |||||
| String description; | |||||
| int ageDayStartAt; | |||||
| int tbSuppliesId; | |||||
| String suppliesName; | |||||
| int tbGuidelineId; | |||||
| int netHouseId; | |||||
| String netHouseName; | |||||
| int areaId; | |||||
| String area; | |||||
| List<TbDetailUsers> tbDetailUsers; | |||||
| TbCropDTO( | |||||
| {this.id, | |||||
| this.qrCode, | |||||
| this.code, | |||||
| this.areaM2, | |||||
| this.tbCropTypeId, | |||||
| this.startDate, | |||||
| this.endDate, | |||||
| this.status, | |||||
| this.description, | |||||
| this.ageDayStartAt, | |||||
| this.tbSuppliesId, | |||||
| this.suppliesName, | |||||
| this.tbGuidelineId, | |||||
| this.netHouseId, | |||||
| this.netHouseName, | |||||
| this.areaId, | |||||
| this.area, | |||||
| this.tbDetailUsers}); | |||||
| TbCropDTO.fromJson(Map<String, dynamic> json) { | |||||
| id = json['id']; | |||||
| qrCode = json['qrCode']; | |||||
| code = json['code']; | |||||
| areaM2 = json['areaM2']; | |||||
| tbCropTypeId = json['tbCropTypeId']; | |||||
| startDate = json['startDate']; | |||||
| endDate = json['endDate']; | |||||
| status = json['status']; | |||||
| description = json['description']; | |||||
| ageDayStartAt = json['ageDayStartAt']; | |||||
| tbSuppliesId = json['tbSuppliesId']; | |||||
| suppliesName = json['suppliesName']; | |||||
| tbGuidelineId = json['tbGuidelineId']; | |||||
| netHouseId = json['netHouseId']; | |||||
| netHouseName = json['netHouseName']; | |||||
| areaId = json['areaId']; | |||||
| area = json['area']; | |||||
| if (json['tbDetailUsers'] != null) { | |||||
| tbDetailUsers = new List<TbDetailUsers>(); | |||||
| json['tbDetailUsers'].forEach((v) { | |||||
| tbDetailUsers.add(new TbDetailUsers.fromJson(v)); | |||||
| }); | |||||
| } | |||||
| } | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['qrCode'] = this.qrCode; | |||||
| data['code'] = this.code; | |||||
| data['areaM2'] = this.areaM2; | |||||
| data['tbCropTypeId'] = this.tbCropTypeId; | |||||
| data['startDate'] = this.startDate; | |||||
| data['endDate'] = this.endDate; | |||||
| data['status'] = this.status; | |||||
| data['description'] = this.description; | |||||
| data['ageDayStartAt'] = this.ageDayStartAt; | |||||
| data['tbSuppliesId'] = this.tbSuppliesId; | |||||
| data['suppliesName'] = this.suppliesName; | |||||
| data['tbGuidelineId'] = this.tbGuidelineId; | |||||
| data['netHouseId'] = this.netHouseId; | |||||
| data['netHouseName'] = this.netHouseName; | |||||
| data['areaId'] = this.areaId; | |||||
| data['area'] = this.area; | |||||
| if (this.tbDetailUsers != null) { | |||||
| data['tbDetailUsers'] = | |||||
| this.tbDetailUsers.map((v) => v.toJson()).toList(); | |||||
| } | |||||
| return data; | |||||
| } | |||||
| } |
| 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; | ||||
| } | } | ||||
| import 'package:farm_tpf/custom_model/Harvest.dart'; | import 'package:farm_tpf/custom_model/Harvest.dart'; | ||||
| import 'package:farm_tpf/custom_model/LocationUnit.dart'; | import 'package:farm_tpf/custom_model/LocationUnit.dart'; | ||||
| import 'package:farm_tpf/custom_model/Supply.dart'; | import 'package:farm_tpf/custom_model/Supply.dart'; | ||||
| import 'package:farm_tpf/custom_model/TbCropDTO.dart'; | |||||
| import 'package:farm_tpf/custom_model/UpdateNoti.dart'; | import 'package:farm_tpf/custom_model/UpdateNoti.dart'; | ||||
| import 'package:farm_tpf/custom_model/WaterType.dart'; | import 'package:farm_tpf/custom_model/WaterType.dart'; | ||||
| import 'package:farm_tpf/custom_model/account.dart'; | import 'package:farm_tpf/custom_model/account.dart'; | ||||
| Future<void> deleteFcmToken(@Body() String token); | Future<void> deleteFcmToken(@Body() String token); | ||||
| //Plot | //Plot | ||||
| @GET( | |||||
| "/api/_search/tb-crops?page={page}&size={size}&sort=id,asc&query={query}") | |||||
| Future<List<Crop>> getPlots( | |||||
| @GET("/api/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 = ""}); | {@Path() int page = 0, @Path() int size = 20, @Path() String query = ""}); | ||||
| @GET("/api/listActivityTypesOther") | @GET("/api/listActivityTypesOther") |
| class _RestClient implements RestClient { | class _RestClient implements RestClient { | ||||
| _RestClient(this._dio, {this.baseUrl}) { | _RestClient(this._dio, {this.baseUrl}) { | ||||
| ArgumentError.checkNotNull(_dio, '_dio'); | ArgumentError.checkNotNull(_dio, '_dio'); | ||||
| this.baseUrl ??= 'https://smartfarm.aztrace.vn'; | |||||
| this.baseUrl ??= 'https://smf.aztrace.vn'; | |||||
| } | } | ||||
| final Dio _dio; | final Dio _dio; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| '/api/_search/tb-crops?page=$page&size=$size&sort=id,asc&query=$query', | |||||
| '/api/tb-crops?page=$page&size=$size&sort=id,asc&query=$query', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | options: RequestOptions( | ||||
| method: 'GET', | method: 'GET', | ||||
| baseUrl: baseUrl), | baseUrl: baseUrl), | ||||
| data: _data); | data: _data); | ||||
| var value = _result.data | var value = _result.data | ||||
| .map((dynamic i) => Crop.fromJson(i as Map<String, dynamic>)) | |||||
| .map((dynamic i) => TbCropDTO.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | .toList(); | ||||
| return value; | return value; | ||||
| } | } |
| import 'dart:convert'; | |||||
| import 'package:dio/dio.dart'; | import 'package:dio/dio.dart'; | ||||
| import 'package:dio_http_cache/dio_http_cache.dart'; | import 'package:dio_http_cache/dio_http_cache.dart'; | ||||
| import 'package:farm_tpf/custom_model/CropPlot.dart'; | import 'package:farm_tpf/custom_model/CropPlot.dart'; | ||||
| import 'package:farm_tpf/custom_model/LocationUnit.dart'; | import 'package:farm_tpf/custom_model/LocationUnit.dart'; | ||||
| import 'package:farm_tpf/custom_model/NotificationObjectDTO.dart'; | import 'package:farm_tpf/custom_model/NotificationObjectDTO.dart'; | ||||
| import 'package:farm_tpf/custom_model/Supply.dart'; | import 'package:farm_tpf/custom_model/Supply.dart'; | ||||
| import 'package:farm_tpf/custom_model/TbCropDTO.dart'; | |||||
| import 'package:farm_tpf/custom_model/UpdateNoti.dart'; | import 'package:farm_tpf/custom_model/UpdateNoti.dart'; | ||||
| import 'package:farm_tpf/custom_model/WaterType.dart'; | import 'package:farm_tpf/custom_model/WaterType.dart'; | ||||
| import 'package:farm_tpf/custom_model/user.dart'; | import 'package:farm_tpf/custom_model/user.dart'; | ||||
| return client.getCropDetailByCode(cropCode, page: page, size: size); | return client.getCropDetailByCode(cropCode, page: page, size: size); | ||||
| } | } | ||||
| Future<List<Crop>> getPlots({int page, int size, String searchString}) { | |||||
| Future<List<TbCropDTO>> getPlots({int page, int size, String searchString}) { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getPlots(page: page, size: size, query: searchString); | return client.getPlots(page: page, size: size, query: searchString); | ||||
| } | } | ||||
| Object getInstanceClass() { | Object getInstanceClass() { | ||||
| var instanceClass; | var instanceClass; | ||||
| if (1 == 1) { | if (1 == 1) { | ||||
| instanceClass = new Crop(); | |||||
| instanceClass = new TbCropDTO(); | |||||
| } | } | ||||
| return instanceClass; | return instanceClass; | ||||
| } | } | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getEnvironmentParameters(cropId, page: page, size: size); | return client.getEnvironmentParameters(cropId, page: page, size: size); | ||||
| } | } | ||||
| //NEW IMPLEMENT | |||||
| Future<void> actionTypes(int cropTypeId, Function(List<ActionType>) onSuccess, | |||||
| Function(dynamic) onError) async { | |||||
| try { | |||||
| 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(); | |||||
| onSuccess(value); | |||||
| } on DioError catch (e) { | |||||
| onError(e); | |||||
| } | |||||
| } | |||||
| } | } |
| if (Get.isDialogOpen) Get.back(); | if (Get.isDialogOpen) Get.back(); | ||||
| Get.to(PlotDetailScreen( | Get.to(PlotDetailScreen( | ||||
| cropId: value.tbCropDTO.id, | cropId: value.tbCropDTO.id, | ||||
| cropType: value.tbCropDTO.type, | |||||
| cropType: value.tbCropDTO.tbCropTypeId, | |||||
| initialIndex: 0)); | initialIndex: 0)); | ||||
| }).catchError((onError) { | }).catchError((onError) { | ||||
| Utils.showDialog( | Utils.showDialog( |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| part 'Crop.g.dart'; | |||||
| @JsonSerializable() | |||||
| class Crop { | |||||
| Crop(); | |||||
| num id; | |||||
| String qrCode; | |||||
| String code; | |||||
| num areaM2; | |||||
| num type; | |||||
| String startDate; | |||||
| String endDate; | |||||
| String status; | |||||
| String description; | |||||
| num ageDayStartAt; | |||||
| num tbSuppliesId; | |||||
| String suppliesName; | |||||
| num tbGuidelineId; | |||||
| num netHouseId; | |||||
| String netHouseName; | |||||
| num areaId; | |||||
| String area; | |||||
| factory Crop.fromJson(Map<String,dynamic> json) => _$CropFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$CropToJson(this); | |||||
| } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'Crop.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| Crop _$CropFromJson(Map<String, dynamic> json) { | |||||
| return Crop() | |||||
| ..id = json['id'] as num | |||||
| ..qrCode = json['qrCode'] as String | |||||
| ..code = json['code'] as String | |||||
| ..areaM2 = json['areaM2'] as num | |||||
| ..type = json['type'] as num | |||||
| ..startDate = json['startDate'] as String | |||||
| ..endDate = json['endDate'] as String | |||||
| ..status = json['status'] as String | |||||
| ..description = json['description'] as String | |||||
| ..ageDayStartAt = json['ageDayStartAt'] as num | |||||
| ..tbSuppliesId = json['tbSuppliesId'] as num | |||||
| ..suppliesName = json['suppliesName'] as String | |||||
| ..tbGuidelineId = json['tbGuidelineId'] as num | |||||
| ..netHouseId = json['netHouseId'] as num | |||||
| ..netHouseName = json['netHouseName'] as String | |||||
| ..areaId = json['areaId'] as num | |||||
| ..area = json['area'] as String; | |||||
| } | |||||
| Map<String, dynamic> _$CropToJson(Crop instance) => <String, dynamic>{ | |||||
| 'id': instance.id, | |||||
| 'qrCode': instance.qrCode, | |||||
| 'code': instance.code, | |||||
| 'areaM2': instance.areaM2, | |||||
| 'type': instance.type, | |||||
| 'startDate': instance.startDate, | |||||
| 'endDate': instance.endDate, | |||||
| 'status': instance.status, | |||||
| 'description': instance.description, | |||||
| 'ageDayStartAt': instance.ageDayStartAt, | |||||
| 'tbSuppliesId': instance.tbSuppliesId, | |||||
| 'suppliesName': instance.suppliesName, | |||||
| 'tbGuidelineId': instance.tbGuidelineId, | |||||
| 'netHouseId': instance.netHouseId, | |||||
| 'netHouseName': instance.netHouseName, | |||||
| 'areaId': instance.areaId, | |||||
| 'area': instance.area, | |||||
| }; |
| export 'Crop.dart'; | |||||
| export 'ResourceHelper.dart'; | export 'ResourceHelper.dart'; | ||||
| export 'ActionType.dart'; | export 'ActionType.dart'; |
| import 'package:farm_tpf/custom_model/TbCropDTO.dart'; | |||||
| import 'package:farm_tpf/data/repository/repository.dart'; | import 'package:farm_tpf/data/repository/repository.dart'; | ||||
| import 'package:farm_tpf/models/index.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; | import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot/widget_search.dart'; | import 'package:farm_tpf/presentation/screens/plot/widget_search.dart'; | ||||
| } | } | ||||
| class ItemInfinityWidget extends StatelessWidget { | class ItemInfinityWidget extends StatelessWidget { | ||||
| final Crop item; | |||||
| final TbCropDTO item; | |||||
| const ItemInfinityWidget({Key key, @required this.item}) : super(key: key); | const ItemInfinityWidget({Key key, @required this.item}) : super(key: key); | ||||
| context, | context, | ||||
| MaterialPageRoute( | MaterialPageRoute( | ||||
| builder: (BuildContext context) => PlotDetailScreen( | builder: (BuildContext context) => PlotDetailScreen( | ||||
| cropId: item.id, initialIndex: 0, cropType: item.type))); | |||||
| cropId: item.id, | |||||
| initialIndex: 0, | |||||
| cropType: item.tbCropTypeId))); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } |
| import 'package:bloc/bloc.dart'; | |||||
| import 'package:equatable/equatable.dart'; | |||||
| import 'package:farm_tpf/data/api/app_exception.dart'; | |||||
| import 'package:farm_tpf/data/repository/repository.dart'; | |||||
| import 'package:farm_tpf/models/index.dart'; | |||||
| part 'plot_action_type_state.dart'; | |||||
| class PlotActionTypeCubit extends Cubit<PlotActionTypeState> { | |||||
| final Repository repository; | |||||
| PlotActionTypeCubit(this.repository) : super(PlotActionTypeInitial()); | |||||
| Future<void> getActionTypes(int cropTypeId) async { | |||||
| try { | |||||
| emit(PlotActionTypeLoading()); | |||||
| await repository.actionTypes(cropTypeId, (data) { | |||||
| emit(PlotActionTypeSuccess(data)); | |||||
| }, (error) { | |||||
| emit(PlotActionTypeError(AppException.handleError(error))); | |||||
| }); | |||||
| } catch (e) { | |||||
| print(e); | |||||
| emit(PlotActionTypeError(AppException.handleError(e))); | |||||
| } | |||||
| } | |||||
| } |
| part of 'plot_action_type_cubit.dart'; | |||||
| abstract class PlotActionTypeState extends Equatable { | |||||
| const PlotActionTypeState(); | |||||
| @override | |||||
| List<Object> get props => []; | |||||
| } | |||||
| class PlotActionTypeInitial extends PlotActionTypeState {} | |||||
| class PlotActionTypeLoading extends PlotActionTypeState {} | |||||
| class PlotActionTypeSuccess extends PlotActionTypeState { | |||||
| final List<ActionType> actionTypes; | |||||
| PlotActionTypeSuccess(this.actionTypes); | |||||
| } | |||||
| class PlotActionTypeError extends PlotActionTypeState { | |||||
| final String error; | |||||
| PlotActionTypeError(this.error); | |||||
| } |
| import 'package:farm_tpf/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/disease/sc_edit_action_disease.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/dung/sc_edit_action_dung.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/end/sc_edit_action_end.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/harvest/sc_edit_action_harvest.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/nursery/sc_edit_action_nursery.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/other/sc_edit_action_other.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/plant/sc_edit_action_plant.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/spraying/sc_edit_action_spraying.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/use_water/sc_edit_action_user_water.dart'; | |||||
| import 'package:cached_network_image/cached_network_image.dart'; | |||||
| import 'package:farm_tpf/data/repository/repository.dart'; | |||||
| import 'package:farm_tpf/models/index.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/plot_detail/bloc/cubit/plot_action_type_cubit.dart'; | |||||
| import 'package:farm_tpf/utils/const_assets.dart'; | import 'package:farm_tpf/utils/const_assets.dart'; | ||||
| import 'package:farm_tpf/utils/const_color.dart'; | import 'package:farm_tpf/utils/const_color.dart'; | ||||
| import 'package:farm_tpf/utils/const_string.dart'; | |||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
| import 'package:flutter_bloc/flutter_bloc.dart'; | |||||
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class PlotActionScreen extends StatefulWidget { | class PlotActionScreen extends StatefulWidget { | ||||
| @override | @override | ||||
| void initState() { | void initState() { | ||||
| super.initState(); | super.initState(); | ||||
| _initActionButtons(); | |||||
| // _initActionButtons(); | |||||
| } | } | ||||
| @override | @override | ||||
| super.dispose(); | super.dispose(); | ||||
| } | } | ||||
| _initActionButtons() { | |||||
| //type: 0- Trồng, 1- ướm | |||||
| if (widget.cropType == 1) { | |||||
| actions.add(ActionType( | |||||
| plot_action_nursery, | |||||
| EditActionNurseryScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionNursery)); | |||||
| } else if (widget.cropType == 0) { | |||||
| actions.add(ActionType( | |||||
| plot_action_plant, | |||||
| EditActionPlantScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionPlant)); | |||||
| } | |||||
| // _initActionButtons() { | |||||
| // //type: 0- Trồng, 1- ướm | |||||
| // if (widget.cropType == 1) { | |||||
| // actions.add(ActionType( | |||||
| // plot_action_nursery, | |||||
| // EditActionNurseryScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionNursery)); | |||||
| // } else if (widget.cropType == 0) { | |||||
| // actions.add(ActionType( | |||||
| // plot_action_plant, | |||||
| // EditActionPlantScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionPlant)); | |||||
| // } | |||||
| actions.add(ActionType( | |||||
| plot_action_crop_status, | |||||
| EditActionCropStatusScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionCropStatus)); | |||||
| actions.add(ActionType( | |||||
| plot_action_environment_update, | |||||
| EditActionEnvironmentUpdate( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionEnvironment)); | |||||
| actions.add(ActionType( | |||||
| plot_action_dung, | |||||
| EditActionDungScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionDung)); | |||||
| actions.add(ActionType( | |||||
| plot_action_spraying, | |||||
| EditActionSprayingScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionSpraying)); | |||||
| actions.add(ActionType( | |||||
| plot_action_disease, | |||||
| EditActionDiseaseScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionDisease)); | |||||
| actions.add(ActionType( | |||||
| plot_action_use_water, | |||||
| EditActionUseWaterScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionUseWater)); | |||||
| actions.add(ActionType( | |||||
| plot_action_other, | |||||
| EditActionOtherScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionOther)); | |||||
| actions.add(ActionType( | |||||
| plot_action_harvest, | |||||
| EditActionHarvestScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionHarvest)); | |||||
| actions.add(ActionType( | |||||
| plot_action_finish, | |||||
| EditActionEndScreen( | |||||
| cropId: widget.cropId, | |||||
| ), | |||||
| AppAssets.icActionEnd)); | |||||
| } | |||||
| // actions.add(ActionType( | |||||
| // plot_action_crop_status, | |||||
| // EditActionCropStatusScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionCropStatus)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_environment_update, | |||||
| // EditActionEnvironmentUpdate( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionEnvironment)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_dung, | |||||
| // EditActionDungScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionDung)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_spraying, | |||||
| // EditActionSprayingScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionSpraying)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_disease, | |||||
| // EditActionDiseaseScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionDisease)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_use_water, | |||||
| // EditActionUseWaterScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionUseWater)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_other, | |||||
| // EditActionOtherScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionOther)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_harvest, | |||||
| // EditActionHarvestScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionHarvest)); | |||||
| // actions.add(ActionType( | |||||
| // plot_action_finish, | |||||
| // EditActionEndScreen( | |||||
| // cropId: widget.cropId, | |||||
| // ), | |||||
| // AppAssets.icActionEnd)); | |||||
| // } | |||||
| Widget _createActionButtons(ActionType actionType, BuildContext _context) { | Widget _createActionButtons(ActionType actionType, BuildContext _context) { | ||||
| return GestureDetector( | return GestureDetector( | ||||
| onTap: () { | onTap: () { | ||||
| Navigator.of(context).push( | |||||
| MaterialPageRoute(builder: (context) => actionType.listScreen)); | |||||
| // Navigator.of(context).push( | |||||
| // MaterialPageRoute(builder: (context) => actionType.listScreen)); | |||||
| }, | }, | ||||
| child: Container( | child: Container( | ||||
| margin: EdgeInsets.all(8), | margin: EdgeInsets.all(8), | ||||
| mainAxisAlignment: MainAxisAlignment.center, | mainAxisAlignment: MainAxisAlignment.center, | ||||
| crossAxisAlignment: CrossAxisAlignment.center, | crossAxisAlignment: CrossAxisAlignment.center, | ||||
| children: [ | children: [ | ||||
| Image.asset( | |||||
| actionType.icon, | |||||
| width: Get.width / 9, | |||||
| height: Get.width / 9, | |||||
| ), | |||||
| 1 == 1 | |||||
| ? Image.asset( | |||||
| AppAssets.logo, | |||||
| width: Get.width / 9, | |||||
| height: Get.width / 9, | |||||
| ) | |||||
| : CachedNetworkImage( | |||||
| imageUrl: "http://via.placeholder.com/350x150", | |||||
| placeholder: (context, url) => | |||||
| CircularProgressIndicator(), | |||||
| errorWidget: (context, url, error) => Icon(Icons.error), | |||||
| ), | |||||
| Text( | Text( | ||||
| actionType.actionName, | |||||
| actionType.description, | |||||
| textAlign: TextAlign.center, | textAlign: TextAlign.center, | ||||
| style: TextStyle( | style: TextStyle( | ||||
| fontWeight: FontWeight.bold, | fontWeight: FontWeight.bold, | ||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return GridView.count( | |||||
| shrinkWrap: true, | |||||
| crossAxisCount: 3, | |||||
| children: actions.map( | |||||
| (item) { | |||||
| return _createActionButtons(item, context); | |||||
| return BlocProvider( | |||||
| create: (contex) => | |||||
| PlotActionTypeCubit(Repository())..getActionTypes(widget.cropType), | |||||
| child: BlocBuilder<PlotActionTypeCubit, PlotActionTypeState>( | |||||
| builder: (context, state) { | |||||
| if (state is PlotActionTypeLoading) { | |||||
| return LoadingListPage(); | |||||
| } else if (state is PlotActionTypeSuccess) { | |||||
| return GridView.count( | |||||
| shrinkWrap: true, | |||||
| crossAxisCount: 3, | |||||
| children: state.actionTypes.map( | |||||
| (item) { | |||||
| return _createActionButtons(item, context); | |||||
| }, | |||||
| ).toList()); | |||||
| } else if (state is PlotActionTypeError) { | |||||
| return Center(child: Text(state.error)); | |||||
| } else { | |||||
| //init | |||||
| return Container(); | |||||
| } | |||||
| }, | }, | ||||
| ).toList()); | |||||
| )); | |||||
| } | } | ||||
| @override | @override | ||||
| bool get wantKeepAlive => true; | bool get wantKeepAlive => true; | ||||
| } | } | ||||
| class ActionType { | |||||
| Widget listScreen; | |||||
| String actionName; | |||||
| String icon; | |||||
| ActionType(String actionName, Widget listScreen, String icon) { | |||||
| this.actionName = actionName; | |||||
| this.listScreen = listScreen; | |||||
| this.icon = icon; | |||||
| } | |||||
| } |
| import 'package:farm_tpf/custom_model/CropPlot.dart'; | import 'package:farm_tpf/custom_model/CropPlot.dart'; | ||||
| import 'package:farm_tpf/custom_model/TbCropDTO.dart'; | |||||
| import 'package:farm_tpf/data/api/app_exception.dart'; | import 'package:farm_tpf/data/api/app_exception.dart'; | ||||
| import 'package:farm_tpf/data/repository/repository.dart'; | import 'package:farm_tpf/data/repository/repository.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart'; | import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/bloc/widget_row_plot_info.dart'; | import 'package:farm_tpf/presentation/custom_widgets/bloc/widget_row_plot_info.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/button_widget.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | ||||
| color: AppColors.DEFAULT | color: AppColors.DEFAULT | ||||
| .withOpacity(0.1), | .withOpacity(0.1), | ||||
| name: 'Ngày gieo trồng', | name: 'Ngày gieo trồng', | ||||
| value: cropPlot.tbCropDTO.type == 0 | |||||
| value: cropPlot.tbCropDTO | |||||
| .tbCropTypeId == | |||||
| 0 | |||||
| ? '${cropPlot.tbCropDTO?.startDate?.format_DDMMYY_HHmm() ?? '--'}' | ? '${cropPlot.tbCropDTO?.startDate?.format_DDMMYY_HHmm() ?? '--'}' | ||||
| : '--'), | : '--'), | ||||
| WidgetRowPlotInfo( | WidgetRowPlotInfo( | ||||
| color: AppColors.DEFAULT | color: AppColors.DEFAULT | ||||
| .withOpacity(0.3), | .withOpacity(0.3), | ||||
| name: 'Ngày vô khây ươm', | name: 'Ngày vô khây ươm', | ||||
| value: cropPlot.tbCropDTO.type == 1 | |||||
| value: cropPlot.tbCropDTO | |||||
| .tbCropTypeId == | |||||
| 1 | |||||
| ? '${cropPlot.tbCropDTO?.startDate?.format_DDMMYY_HHmm() ?? '--'}' | ? '${cropPlot.tbCropDTO?.startDate?.format_DDMMYY_HHmm() ?? '--'}' | ||||
| : '--'), | : '--'), | ||||
| WidgetRowPlotInfo( | WidgetRowPlotInfo( |
| static int kExpiredTime = 518400000; //6* 24 * 60 * 60 * 1000; 6days | static int kExpiredTime = 518400000; //6* 24 * 60 * 60 * 1000; 6days | ||||
| static int kFileSize = 1000000; //1M = 1000.000 bytes | static int kFileSize = 1000000; //1M = 1000.000 bytes | ||||
| static int kMaxAgeCache = 7; // 7days | static int kMaxAgeCache = 7; // 7days | ||||
| static const String baseUrl = "https://smartfarm.aztrace.vn"; | |||||
| static const String baseImageUrl = "https://smartfarm.aztrace.vn/upload/"; | |||||
| static const String baseUrl = "https://smf.aztrace.vn"; | |||||
| static const String baseImageUrl = "https://smf.aztrace.vn/upload/"; | |||||
| static RegExp regExpDecimal = RegExp("[0-9.]"); | static RegExp regExpDecimal = RegExp("[0-9.]"); | ||||
| static const String apiDetailNursery = "api/activity-nursery"; | static const String apiDetailNursery = "api/activity-nursery"; |