| @@ -1 +1 @@ | |||
| 0d1f90510e22958a585802bb59f9c570 | |||
| eb141365fb69a4e0decadd2584d53516 | |||
| @@ -1,6 +1,7 @@ | |||
| import 'package:dio/dio.dart'; | |||
| import 'package:farm_tpf/custom_model/CropPlot.dart'; | |||
| import 'package:farm_tpf/custom_model/Device.dart'; | |||
| import 'package:farm_tpf/custom_model/Harvest.dart'; | |||
| import 'package:farm_tpf/custom_model/WaterType.dart'; | |||
| import 'package:farm_tpf/custom_model/account.dart'; | |||
| import 'package:farm_tpf/custom_model/password.dart'; | |||
| @@ -51,6 +52,9 @@ abstract class RestClient { | |||
| @GET("/api/water-types") | |||
| Future<List<WaterType>> getWaterTypes({@DioOptions() Options options}); | |||
| @GET("/api/tb-harvests") | |||
| Future<List<Harvest>> getHarvests(); | |||
| //Crop | |||
| @GET( | |||
| "/api/tb-crops-detail-for-app/{cropId}?page={page}&size={size}&sort=executeDate,DESC") | |||
| @@ -226,6 +226,26 @@ class _RestClient implements RestClient { | |||
| return value; | |||
| } | |||
| @override | |||
| getHarvests() async { | |||
| const _extra = <String, dynamic>{}; | |||
| final queryParameters = <String, dynamic>{}; | |||
| final _data = <String, dynamic>{}; | |||
| final Response<List<dynamic>> _result = await _dio.request( | |||
| '/api/tb-harvests', | |||
| queryParameters: queryParameters, | |||
| options: RequestOptions( | |||
| method: 'GET', | |||
| headers: <String, dynamic>{}, | |||
| extra: _extra, | |||
| baseUrl: baseUrl), | |||
| data: _data); | |||
| var value = _result.data | |||
| .map((dynamic i) => Harvest.fromJson(i as Map<String, dynamic>)) | |||
| .toList(); | |||
| return value; | |||
| } | |||
| @override | |||
| getCropDetail(cropId, {page = 0, size = 20}) async { | |||
| ArgumentError.checkNotNull(cropId, 'cropId'); | |||
| @@ -4,6 +4,7 @@ import 'package:dio/dio.dart'; | |||
| import 'package:dio_http_cache/dio_http_cache.dart'; | |||
| import 'package:farm_tpf/custom_model/CropPlot.dart'; | |||
| import 'package:farm_tpf/custom_model/Device.dart'; | |||
| import 'package:farm_tpf/custom_model/Harvest.dart'; | |||
| import 'package:farm_tpf/custom_model/WaterType.dart'; | |||
| import 'package:farm_tpf/custom_model/user.dart'; | |||
| import 'package:farm_tpf/custom_model/user_request.dart'; | |||
| @@ -24,6 +25,11 @@ class Repository { | |||
| return client.getActionTypes(); | |||
| } | |||
| Future<List<Harvest>> getHarvests() { | |||
| final client = RestClient(dio); | |||
| return client.getHarvests(); | |||
| } | |||
| Future<List<WaterType>> getWaterTypes() { | |||
| final client = RestClient(dio); | |||
| var op = buildConfigurableCacheOptions(forceRefresh: true); | |||
| @@ -0,0 +1,32 @@ | |||
| import 'package:farm_tpf/data/repository/repository.dart'; | |||
| import 'package:rxdart/rxdart.dart'; | |||
| class GetHarvestBloc { | |||
| final _repository = Repository(); | |||
| final _getHarvestFetcher = PublishSubject<dynamic>(); | |||
| Stream<dynamic> get actions => _getHarvestFetcher.stream; | |||
| void getHarvests( | |||
| Function(dynamic) onSuccess, Function(String) onError) async { | |||
| try { | |||
| _repository.getHarvests().then((value) { | |||
| onSuccess(value); | |||
| _getHarvestFetcher.sink.add(value); | |||
| }).catchError((onError) { | |||
| _getHarvestFetcher.addError(onError); | |||
| onError(onError); | |||
| }); | |||
| } catch (e) { | |||
| _getHarvestFetcher.addError(e); | |||
| onError(e); | |||
| } | |||
| } | |||
| void dispose() async { | |||
| await _getHarvestFetcher.drain(); | |||
| _getHarvestFetcher.close(); | |||
| } | |||
| } | |||
| final getHarvestBloc = GetHarvestBloc(); | |||
| @@ -396,8 +396,15 @@ class _EditActionHarvestScreenState extends State<EditActionHarvestScreen> { | |||
| IconButton( | |||
| icon: Icon(Icons.ac_unit), | |||
| onPressed: () { | |||
| Get.to(EditActionPackingScreen( | |||
| cropId: widget.cropId)); | |||
| if (_harvest.id != null) { | |||
| Get.to(EditActionPackingScreen( | |||
| cropId: widget.cropId, | |||
| harvestId: _harvest.id, | |||
| )); | |||
| } else { | |||
| Get.to(EditActionPackingScreen( | |||
| cropId: widget.cropId)); | |||
| } | |||
| }) | |||
| ], | |||
| ); | |||
| @@ -1,5 +1,6 @@ | |||
| import 'dart:convert'; | |||
| import 'package:farm_tpf/custom_model/Harvest.dart'; | |||
| import 'package:farm_tpf/custom_model/Packing.dart'; | |||
| import 'package:farm_tpf/data/api/app_exception.dart'; | |||
| import 'package:farm_tpf/data/repository/repository.dart'; | |||
| @@ -7,6 +8,7 @@ import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; | |||
| import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; | |||
| import 'package:farm_tpf/presentation/screens/actions/bloc_get_harvest.dart'; | |||
| import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart'; | |||
| import 'package:farm_tpf/utils/const_common.dart'; | |||
| import 'package:farm_tpf/utils/const_string.dart'; | |||
| @@ -51,6 +53,8 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| TextEditingController _removedQuantityController = TextEditingController(); | |||
| TextEditingController _descriptionController = TextEditingController(); | |||
| List<Harvest> _harvests = List<Harvest>(); | |||
| Harvest harvestValue; | |||
| String executeTimeView; | |||
| DateTime executeTime = DateTime.now(); | |||
| List<String> filePaths = List<String>(); | |||
| @@ -65,6 +69,18 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| _packing.executeDate = "$parsedExecuteDate"; | |||
| executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime); | |||
| _packing.cropId = widget.cropId; | |||
| if (!widget.isEdit) { | |||
| getHarvestBloc.getHarvests((data) { | |||
| _harvests = data; | |||
| for (var item in _harvests) { | |||
| if (item.id == widget.harvestId) { | |||
| harvestValue = item; | |||
| break; | |||
| } | |||
| } | |||
| }, (err) {}); | |||
| } | |||
| } | |||
| _validateInputs() async { | |||
| @@ -134,6 +150,41 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| } | |||
| } | |||
| List<DropdownMenuItem<Harvest>> _buildDropMenu(List<Harvest> actions) { | |||
| return actions | |||
| .map((action) => DropdownMenuItem<Harvest>( | |||
| child: Text("Lần thu hoạch " + action.id.toString()), | |||
| value: action, | |||
| )) | |||
| .toList(); | |||
| } | |||
| Widget _dropdownHarvest() { | |||
| return StreamBuilder( | |||
| stream: getHarvestBloc.actions, | |||
| builder: (context, AsyncSnapshot<dynamic> snapshot) { | |||
| if (snapshot.hasData) { | |||
| return DropdownButtonFormField<Harvest>( | |||
| value: harvestValue, | |||
| hint: Text("Mã thu hoạch"), | |||
| onChanged: (Harvest newValue) { | |||
| setState(() { | |||
| harvestValue = newValue; | |||
| _packing.harvestId = newValue.id; | |||
| }); | |||
| }, | |||
| validator: (value) => value == null ? "Mã thu hoạch" : null, | |||
| isExpanded: true, | |||
| items: _buildDropMenu(_harvests)); | |||
| } else { | |||
| return Center( | |||
| child: CircularProgressIndicator(), | |||
| ); | |||
| } | |||
| }, | |||
| ); | |||
| } | |||
| Widget _btnExecuteTimePicker() { | |||
| return FlatButton( | |||
| padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||
| @@ -327,6 +378,17 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| _descriptionController.text = | |||
| _packing.description ?? ""; | |||
| //select harvest | |||
| getHarvestBloc.getHarvests((data) { | |||
| _harvests = data; | |||
| for (var item in _harvests) { | |||
| if (item.id == _packing.harvestId) { | |||
| harvestValue = item; | |||
| break; | |||
| } | |||
| } | |||
| }, (err) {}); | |||
| try { | |||
| executeTime = | |||
| DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") | |||
| @@ -364,6 +426,10 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| SizedBox( | |||
| height: 8.0, | |||
| ), | |||
| _dropdownHarvest(), | |||
| SizedBox( | |||
| height: 8.0, | |||
| ), | |||
| _l1Field(), | |||
| SizedBox( | |||
| height: 8.0, | |||
| @@ -10,6 +10,7 @@ import 'package:farm_tpf/presentation/screens/actions/environment_update/sc_edit | |||
| 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/packing/sc_edit_action_packing.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'; | |||
| @@ -413,6 +414,12 @@ class ItemInfinityWidget extends StatelessWidget { | |||
| activityId: item.id, | |||
| isEdit: true, | |||
| )); | |||
| } else if (item.activityTypeName == "ACTIVE_TYPE_PACKING") { | |||
| Get.to(EditActionPackingScreen( | |||
| cropId: item.cropId, | |||
| activityId: item.id, | |||
| isEdit: true, | |||
| )); | |||
| } | |||
| }); | |||
| } | |||