| @@ -1 +1 @@ | |||
| 48197743e3d78b3769f70bac9a76e7e0 | |||
| 5729eb498eaeb9c64784fcfc80bbb33b | |||
| @@ -14,6 +14,7 @@ class CropStatus { | |||
| String description; | |||
| String executeBy; | |||
| String media; | |||
| List<String> mediaDel; | |||
| CropStatus( | |||
| {this.id, | |||
| @@ -30,7 +31,8 @@ class CropStatus { | |||
| this.internodeLength, | |||
| this.description, | |||
| this.executeBy, | |||
| this.media}); | |||
| this.media, | |||
| this.mediaDel}); | |||
| CropStatus.fromJson(Map<String, dynamic> json) { | |||
| id = json['id']; | |||
| @@ -67,6 +69,7 @@ class CropStatus { | |||
| data['description'] = this.description; | |||
| data['executeBy'] = this.executeBy; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| return data; | |||
| } | |||
| } | |||
| @@ -11,6 +11,7 @@ class Dung { | |||
| String weatherConditions; | |||
| String purpose; | |||
| String executeBy; | |||
| List<String> mediaDel; | |||
| List<SuppliesUsing> suppliesUsing; | |||
| Dung( | |||
| @@ -24,6 +25,7 @@ class Dung { | |||
| this.weatherConditions, | |||
| this.purpose, | |||
| this.executeBy, | |||
| this.mediaDel, | |||
| this.suppliesUsing}); | |||
| Dung.fromJson(Map<String, dynamic> json) { | |||
| @@ -57,6 +59,7 @@ class Dung { | |||
| data['weatherConditions'] = this.weatherConditions; | |||
| data['purpose'] = this.purpose; | |||
| data['executeBy'] = this.executeBy; | |||
| data['media_del'] = this.mediaDel; | |||
| if (this.suppliesUsing != null) { | |||
| data['suppliesUsing'] = | |||
| this.suppliesUsing.map((v) => v.toJson()).toList(); | |||
| @@ -5,6 +5,7 @@ class End { | |||
| String executeDate; | |||
| String description; | |||
| String createdByName; | |||
| List<String> mediaDel; | |||
| String media; | |||
| End( | |||
| @@ -14,6 +15,7 @@ class End { | |||
| this.executeDate, | |||
| this.description, | |||
| this.createdByName, | |||
| this.mediaDel, | |||
| this.media}); | |||
| End.fromJson(Map<String, dynamic> json) { | |||
| @@ -35,6 +37,7 @@ class End { | |||
| data['description'] = this.description; | |||
| data['createdByName'] = this.createdByName; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| return data; | |||
| } | |||
| } | |||
| @@ -6,6 +6,7 @@ class Harvest { | |||
| String description; | |||
| String executeBy; | |||
| String media; | |||
| List<String> mediaDel; | |||
| num collectedQuantityLv1; | |||
| num collectedQuantityLv2; | |||
| num collectedQuantityLv3; | |||
| @@ -19,6 +20,7 @@ class Harvest { | |||
| this.description, | |||
| this.executeBy, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.collectedQuantityLv1, | |||
| this.collectedQuantityLv2, | |||
| this.collectedQuantityLv3, | |||
| @@ -47,6 +49,7 @@ class Harvest { | |||
| data['description'] = this.description; | |||
| data['executeBy'] = this.executeBy; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['collectedQuantityLv1'] = this.collectedQuantityLv1; | |||
| data['collectedQuantityLv2'] = this.collectedQuantityLv2; | |||
| data['collectedQuantityLv3'] = this.collectedQuantityLv3; | |||
| @@ -9,6 +9,7 @@ class HarvestProcess { | |||
| String description; | |||
| String executeBy; | |||
| String media; | |||
| List<String> mediaDel; | |||
| num quantityLv1; | |||
| num quantityLv2; | |||
| num quantityLv3; | |||
| @@ -24,6 +25,7 @@ class HarvestProcess { | |||
| this.description, | |||
| this.executeBy, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.quantityLv1, | |||
| this.quantityLv2, | |||
| this.quantityLv3, | |||
| @@ -61,6 +63,7 @@ class HarvestProcess { | |||
| data['description'] = this.description; | |||
| data['executeBy'] = this.executeBy; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['quantityLv1'] = this.quantityLv1; | |||
| data['quantityLv2'] = this.quantityLv2; | |||
| data['quantityLv3'] = this.quantityLv3; | |||
| @@ -8,6 +8,7 @@ class Nursery { | |||
| String description; | |||
| String executeBy; | |||
| String media; | |||
| List<String> mediaDel; | |||
| String seedName; | |||
| num substratesId; | |||
| String substrateName; | |||
| @@ -24,6 +25,7 @@ class Nursery { | |||
| this.description, | |||
| this.executeBy, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.seedName, | |||
| this.substratesId, | |||
| this.substrateName, | |||
| @@ -63,6 +65,7 @@ class Nursery { | |||
| data['description'] = this.description; | |||
| data['executeBy'] = this.executeBy; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['seedName'] = this.seedName; | |||
| data['substratesId'] = this.substratesId; | |||
| data['substrateName'] = this.substrateName; | |||
| @@ -3,6 +3,7 @@ class Other { | |||
| int cropId; | |||
| int activityId; | |||
| String media; | |||
| List<String> mediaDel; | |||
| String executeDate; | |||
| String description; | |||
| String createdByName; | |||
| @@ -13,6 +14,7 @@ class Other { | |||
| this.cropId, | |||
| this.activityId, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.executeDate, | |||
| this.description, | |||
| this.createdByName, | |||
| @@ -35,6 +37,7 @@ class Other { | |||
| data['cropId'] = this.cropId; | |||
| data['activityId'] = this.activityId; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['executeDate'] = this.executeDate; | |||
| data['description'] = this.description; | |||
| data['createdByName'] = this.createdByName; | |||
| @@ -7,6 +7,7 @@ class Packing { | |||
| String description; | |||
| String executeBy; | |||
| String media; | |||
| List<String> mediaDel; | |||
| num quantityLv1; | |||
| num quantityLv2; | |||
| num quantityLv3; | |||
| @@ -21,6 +22,7 @@ class Packing { | |||
| this.description, | |||
| this.executeBy, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.quantityLv1, | |||
| this.quantityLv2, | |||
| this.quantityLv3, | |||
| @@ -51,6 +53,7 @@ class Packing { | |||
| data['description'] = this.description; | |||
| data['executeBy'] = this.executeBy; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['quantityLv1'] = this.quantityLv1; | |||
| data['quantityLv2'] = this.quantityLv2; | |||
| data['quantityLv3'] = this.quantityLv3; | |||
| @@ -10,6 +10,7 @@ class Plant { | |||
| String density; | |||
| num quantity; | |||
| String media; | |||
| List<String> mediaDel; | |||
| List<SuppliesUsing> suppliesUsing; | |||
| Plant( | |||
| @@ -22,6 +23,7 @@ class Plant { | |||
| this.density, | |||
| this.quantity, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.suppliesUsing}); | |||
| Plant.fromJson(Map<String, dynamic> json) { | |||
| @@ -53,6 +55,7 @@ class Plant { | |||
| data['density'] = this.density; | |||
| data['quantity'] = this.quantity; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| if (this.suppliesUsing != null) { | |||
| data['suppliesUsing'] = | |||
| this.suppliesUsing.map((v) => v.toJson()).toList(); | |||
| @@ -4,6 +4,7 @@ class RequestDisease { | |||
| int cropId; | |||
| String executeDate; | |||
| String description; | |||
| List<String> mediaDel; | |||
| List<ObjectUpdateDetail> objectUpdateDetail; | |||
| RequestDisease( | |||
| @@ -12,6 +13,7 @@ class RequestDisease { | |||
| this.cropId, | |||
| this.executeDate, | |||
| this.description, | |||
| this.mediaDel, | |||
| this.objectUpdateDetail}); | |||
| RequestDisease.fromJson(Map<String, dynamic> json) { | |||
| @@ -35,6 +37,7 @@ class RequestDisease { | |||
| data['activityId'] = this.activityId; | |||
| data['executeDate'] = this.executeDate; | |||
| data['description'] = this.description; | |||
| data['media_del'] = this.mediaDel; | |||
| if (this.objectUpdateDetail != null) { | |||
| data['objectUpdateDetail'] = | |||
| this.objectUpdateDetail.map((v) => v.toJson()).toList(); | |||
| @@ -3,6 +3,7 @@ class RequestEnvironment { | |||
| int cropId; | |||
| String executeDate; | |||
| String description; | |||
| List<String> mediaDel; | |||
| List<EnvDetail> envDetail; | |||
| RequestEnvironment( | |||
| @@ -10,6 +11,7 @@ class RequestEnvironment { | |||
| this.cropId, | |||
| this.executeDate, | |||
| this.description, | |||
| this.mediaDel, | |||
| this.envDetail}); | |||
| RequestEnvironment.fromJson(Map<String, dynamic> json) { | |||
| @@ -31,6 +33,7 @@ class RequestEnvironment { | |||
| data['cropId'] = this.cropId; | |||
| data['executeDate'] = this.executeDate; | |||
| data['description'] = this.description; | |||
| data['media_del'] = this.mediaDel; | |||
| if (this.envDetail != null) { | |||
| data['envDetail'] = this.envDetail.map((v) => v.toJson()).toList(); | |||
| } | |||
| @@ -3,6 +3,7 @@ class RequestGeneralModel { | |||
| int activityId; | |||
| String executeDate; | |||
| String description; | |||
| List<String> mediaDel; | |||
| List<ObjectUpdateDetail> objectUpdateDetail; | |||
| RequestGeneralModel( | |||
| @@ -10,6 +11,7 @@ class RequestGeneralModel { | |||
| this.activityId, | |||
| this.executeDate, | |||
| this.description, | |||
| this.mediaDel, | |||
| this.objectUpdateDetail}); | |||
| RequestGeneralModel.fromJson(Map<String, dynamic> json) { | |||
| @@ -31,6 +33,7 @@ class RequestGeneralModel { | |||
| data['activityId'] = this.activityId; | |||
| data['executeDate'] = this.executeDate; | |||
| data['description'] = this.description; | |||
| data['media_del'] = this.mediaDel; | |||
| if (this.objectUpdateDetail != null) { | |||
| data['objectUpdateDetail'] = | |||
| this.objectUpdateDetail.map((v) => v.toJson()).toList(); | |||
| @@ -7,6 +7,7 @@ class Sell { | |||
| String description; | |||
| String executeBy; | |||
| String media; | |||
| List<String> mediaDel; | |||
| num quantityLv1; | |||
| num quantityLv2; | |||
| num quantityLv3; | |||
| @@ -22,6 +23,7 @@ class Sell { | |||
| this.description, | |||
| this.executeBy, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.quantityLv1, | |||
| this.quantityLv2, | |||
| this.quantityLv3, | |||
| @@ -54,6 +56,7 @@ class Sell { | |||
| data['description'] = this.description; | |||
| data['executeBy'] = this.executeBy; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['quantityLv1'] = this.quantityLv1; | |||
| data['quantityLv2'] = this.quantityLv2; | |||
| data['quantityLv3'] = this.quantityLv3; | |||
| @@ -5,6 +5,7 @@ class Spraying { | |||
| int activityId; | |||
| int cropId; | |||
| String media; | |||
| List<String> mediaDel; | |||
| String executeDate; | |||
| num quarantinePeriod; | |||
| String resultAt; | |||
| @@ -19,6 +20,7 @@ class Spraying { | |||
| this.activityId, | |||
| this.cropId, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.executeDate, | |||
| this.quarantinePeriod, | |||
| this.resultAt, | |||
| @@ -54,6 +56,7 @@ class Spraying { | |||
| data['activityId'] = this.activityId; | |||
| data['cropId'] = this.cropId; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['executeDate'] = this.executeDate; | |||
| data['quarantinePeriod'] = this.quarantinePeriod; | |||
| data['resultAt'] = this.resultAt; | |||
| @@ -4,6 +4,7 @@ class UseWater { | |||
| int cropId; | |||
| String executeDate; | |||
| String media; | |||
| List<String> mediaDel; | |||
| String waterType; | |||
| num amount; | |||
| String description; | |||
| @@ -15,6 +16,7 @@ class UseWater { | |||
| this.cropId, | |||
| this.executeDate, | |||
| this.media, | |||
| this.mediaDel, | |||
| this.waterType, | |||
| this.amount, | |||
| this.description, | |||
| @@ -39,6 +41,7 @@ class UseWater { | |||
| data['cropId'] = this.cropId; | |||
| data['executeDate'] = this.executeDate; | |||
| data['media'] = this.media; | |||
| data['media_del'] = this.mediaDel; | |||
| data['waterType'] = this.waterType; | |||
| data['amount'] = this.amount; | |||
| data['description'] = this.description; | |||
| @@ -1,5 +1,6 @@ | |||
| import 'dart:io'; | |||
| import 'package:cached_network_image/cached_network_image.dart'; | |||
| import 'package:farm_tpf/custom_model/Media.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/camera_helper.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_show_video.dart'; | |||
| @@ -12,14 +13,14 @@ import 'package:file_picker/file_picker.dart'; | |||
| import 'package:flutter/cupertino.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:flutter_bloc/flutter_bloc.dart'; | |||
| import 'package:get/get.dart'; | |||
| import 'bloc/media_helper_bloc.dart'; | |||
| import 'hoz_list_view.dart'; | |||
| class WidgetMediaPicker extends StatefulWidget { | |||
| final List<Media> currentItems; | |||
| final Function(List<String> filePaths) onChangeFiles; | |||
| final Function(List<String> addNewFilePaths, List<String> deleteFilePaths) | |||
| onChangeFiles; | |||
| WidgetMediaPicker({this.currentItems, @required this.onChangeFiles}); | |||
| @override | |||
| _WidgetMediaPickerState createState() => _WidgetMediaPickerState(); | |||
| @@ -27,7 +28,8 @@ class WidgetMediaPicker extends StatefulWidget { | |||
| class _WidgetMediaPickerState extends State<WidgetMediaPicker> { | |||
| List<Media> currentItems = []; | |||
| List<String> files = new List<String>(); | |||
| List<String> addNewFilePaths = new List<String>(); | |||
| List<String> deleteFilePaths = new List<String>(); | |||
| @override | |||
| void initState() { | |||
| @@ -123,12 +125,11 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { | |||
| ..isServerFile = false | |||
| ..pathFile = filePath; | |||
| currentItems.add(newMedia); | |||
| files.add(filePath); | |||
| addNewFilePaths.add(filePath); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| ..add(ChangeListMedia(items: currentItems)); | |||
| widget.onChangeFiles(files); | |||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | |||
| } | |||
| print("Kích thước: $lengthFileInBytes bytes"); | |||
| }); | |||
| } | |||
| }); | |||
| @@ -152,10 +153,10 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { | |||
| ..isServerFile = false | |||
| ..pathFile = compressFile.path; | |||
| currentItems.add(newMedia); | |||
| files.add(compressFile.path); | |||
| addNewFilePaths.add(compressFile.path); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| ..add(ChangeListMedia(items: currentItems)); | |||
| widget.onChangeFiles(files); | |||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | |||
| } | |||
| }); | |||
| } | |||
| @@ -178,10 +179,10 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { | |||
| ..isServerFile = false | |||
| ..pathFile = filePath; | |||
| currentItems.add(newMedia); | |||
| files.add(filePath); | |||
| addNewFilePaths.add(filePath); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| ..add(ChangeListMedia(items: currentItems)); | |||
| widget.onChangeFiles(files); | |||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | |||
| } | |||
| } | |||
| }), | |||
| @@ -200,21 +201,19 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> { | |||
| return BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||
| builder: (context, state) { | |||
| if (state is MediaHelperSuccess) { | |||
| files = []; | |||
| currentItems.forEach((element) { | |||
| files.add(element.pathFile); | |||
| }); | |||
| widget.onChangeFiles(files); | |||
| return WrapContentHozListView( | |||
| itemBuilder: (context, index) { | |||
| var item = currentItems[index]; | |||
| return _WidgetItemMedia( | |||
| item: item, | |||
| deleteImage: (item) { | |||
| files.remove(item.pathFile); | |||
| if (item.isServerFile) { | |||
| var url = | |||
| item.pathFile.replaceAll(ConstCommon.baseImageUrl, ''); | |||
| deleteFilePaths.add(url); | |||
| } | |||
| currentItems.remove(item); | |||
| widget.onChangeFiles(files); | |||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: currentItems)); | |||
| }); | |||
| @@ -253,6 +252,7 @@ class _WidgetItemMedia extends StatelessWidget { | |||
| child: item.isVideo | |||
| ? VideoWidget( | |||
| pathFile: item.pathFile, | |||
| isServerFile: item.isServerFile, | |||
| play: false, | |||
| ) | |||
| : Container( | |||
| @@ -263,8 +263,13 @@ class _WidgetItemMedia extends StatelessWidget { | |||
| border: Border.all(color: Colors.grey), | |||
| borderRadius: | |||
| BorderRadius.all(Radius.circular(8.0))), | |||
| child: Image.file(File(item.pathFile), | |||
| width: 100, height: 100), | |||
| child: item.isServerFile | |||
| ? CachedNetworkImage( | |||
| placeholder: (context, url) => | |||
| Icon(Icons.crop_original), | |||
| imageUrl: item.pathFile) | |||
| : Image.file(File(item.pathFile), | |||
| width: 100, height: 100), | |||
| )), | |||
| Positioned( | |||
| top: -14, | |||
| @@ -6,9 +6,14 @@ import 'package:video_player/video_player.dart'; | |||
| class VideoWidget extends StatefulWidget { | |||
| final bool play; | |||
| final bool isServerFile; | |||
| final String pathFile; | |||
| const VideoWidget({Key key, @required this.pathFile, @required this.play}) | |||
| const VideoWidget( | |||
| {Key key, | |||
| @required this.pathFile, | |||
| @required this.play, | |||
| @required this.isServerFile}) | |||
| : super(key: key); | |||
| @override | |||
| @@ -22,7 +27,12 @@ class _VideoWidgetState extends State<VideoWidget> { | |||
| @override | |||
| void initState() { | |||
| super.initState(); | |||
| videoPlayerController = VideoPlayerController.file(File(widget.pathFile)); | |||
| if (widget.isServerFile) { | |||
| videoPlayerController = VideoPlayerController.network(widget.pathFile); | |||
| } else { | |||
| videoPlayerController = VideoPlayerController.file(File(widget.pathFile)); | |||
| } | |||
| _initializeVideoPlayerFuture = videoPlayerController.initialize().then((_) { | |||
| // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. | |||
| videoPlayerController.play(); | |||
| @@ -80,7 +80,7 @@ class _EditActionCropStatusScreenState | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| //Create request general model | |||
| try { | |||
| RequestGeneralModel generalModel = RequestGeneralModel() | |||
| @@ -114,6 +114,7 @@ class _EditActionCropStatusScreenState | |||
| ..name = "KHA_NANG_SINH_CHOI" | |||
| ..index = _cropStatus.abilityProduceBuds); | |||
| generalModel.objectUpdateDetail = generalDetail; | |||
| generalModel.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityCropStatus = jsonEncode(generalModel.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_cropStatus.activityId == null) { | |||
| @@ -420,14 +421,10 @@ class _EditActionCropStatusScreenState | |||
| .format(executeTime); | |||
| //Show media | |||
| if (_cropStatus.media != null) { | |||
| await UtilAction.cacheFiles(_cropStatus.media) | |||
| .then((value) { | |||
| print("then: ${value.length}"); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _cropStatus.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| print("init"); | |||
| @@ -498,9 +495,10 @@ class _EditActionCropStatusScreenState | |||
| state.items.length.toString()); | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -80,7 +80,7 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| //Create request general model | |||
| try { | |||
| RequestDisease requestDisease = RequestDisease() | |||
| @@ -108,6 +108,7 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { | |||
| ..name = "BIEN_PHAP_XU_LY" | |||
| ..index = _disease.treatmentMeasures); | |||
| requestDisease.objectUpdateDetail = generalDetail; | |||
| requestDisease.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityDisease = jsonEncode(requestDisease.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_disease.activityId == null) { | |||
| @@ -364,13 +365,10 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { | |||
| .format(executeTime); | |||
| //Show media | |||
| if (_disease.media != null) { | |||
| await UtilAction.cacheFiles(_disease.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _disease.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| } else if (state is ActionDetailLoading) { | |||
| @@ -429,9 +427,10 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -78,7 +78,7 @@ class _EditActionDungScreenState extends State<EditActionDungScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| List<SuppliesUsing> newSups = []; | |||
| suppliesUsing.forEach((sup) { | |||
| var newSup = sup; | |||
| @@ -87,6 +87,7 @@ class _EditActionDungScreenState extends State<EditActionDungScreen> { | |||
| newSups.add(newSup); | |||
| }); | |||
| _dung.suppliesUsing = newSups; | |||
| _dung.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityDung = jsonEncode(_dung.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_dung.activityId == null) { | |||
| @@ -297,13 +298,11 @@ class _EditActionDungScreenState extends State<EditActionDungScreen> { | |||
| .format(executeTime); | |||
| //Show media | |||
| if (_dung.media != null) { | |||
| await UtilAction.cacheFiles(_dung.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia( | |||
| items: UtilAction | |||
| .convertFilePathToMedia( | |||
| _dung.media))); | |||
| } | |||
| //list supply | |||
| suppliesUsing = _dung.suppliesUsing; | |||
| @@ -366,9 +365,11 @@ class _EditActionDungScreenState extends State<EditActionDungScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| .change(newPathFiles, | |||
| deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -68,8 +68,9 @@ class _EditActionEndScreenState extends State<EditActionEndScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| try { | |||
| _end.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityEnd = jsonEncode(_end.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_end.activityId == null) { | |||
| @@ -240,13 +241,10 @@ class _EditActionEndScreenState extends State<EditActionEndScreen> { | |||
| } catch (_) {} | |||
| //Show media | |||
| if (_end.media != null) { | |||
| await UtilAction.cacheFiles(_end.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _end.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| } else if (state is ActionDetailLoading) { | |||
| @@ -281,9 +279,10 @@ class _EditActionEndScreenState extends State<EditActionEndScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -78,7 +78,7 @@ class _EditActionEnvironmentUpdateState | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| //Create request general model | |||
| try { | |||
| RequestEnvironment requestEnvironment = RequestEnvironment() | |||
| @@ -105,6 +105,8 @@ class _EditActionEnvironmentUpdateState | |||
| ..name = "LLN" | |||
| ..index = _environment.lln); | |||
| requestEnvironment.envDetail = envDetail; | |||
| requestEnvironment.mediaDel = | |||
| Get.find<ChangeFileController>().deleteFiles; | |||
| var activityEnvironmentUpdate = | |||
| jsonEncode(requestEnvironment.toJson()).toString(); | |||
| //ADD NEW | |||
| @@ -398,14 +400,10 @@ class _EditActionEnvironmentUpdateState | |||
| .format(executeTime); | |||
| //Show media | |||
| if (_environment.media != null) { | |||
| await UtilAction.cacheFiles(_environment.media) | |||
| .then((value) { | |||
| print("then: ${value.length}"); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _environment.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| print("init"); | |||
| @@ -462,9 +460,10 @@ class _EditActionEnvironmentUpdateState | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -78,8 +78,9 @@ class _EditActionHarvestScreenState extends State<EditActionHarvestScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| try { | |||
| _harvest.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityHarvest = jsonEncode(_harvest.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_harvest.activityId == null) { | |||
| @@ -320,13 +321,10 @@ class _EditActionHarvestScreenState extends State<EditActionHarvestScreen> { | |||
| } catch (_) {} | |||
| //Show media | |||
| if (_harvest.media != null) { | |||
| await UtilAction.cacheFiles(_harvest.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _harvest.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| } else if (state is ActionDetailLoading) { | |||
| @@ -377,9 +375,10 @@ class _EditActionHarvestScreenState extends State<EditActionHarvestScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -101,7 +101,7 @@ class _EditActionHarvestProcessScreenState | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| List<SuppliesUsing> newSups = []; | |||
| suppliesUsing.forEach((sup) { | |||
| var newSup = sup; | |||
| @@ -110,6 +110,7 @@ class _EditActionHarvestProcessScreenState | |||
| newSups.add(newSup); | |||
| }); | |||
| _harvestProcess.suppliesUsing = newSups; | |||
| _harvestProcess.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| try { | |||
| var activityHarvestProcess = | |||
| jsonEncode(_harvestProcess.toJson()).toString(); | |||
| @@ -400,13 +401,10 @@ class _EditActionHarvestProcessScreenState | |||
| } catch (_) {} | |||
| //Show media | |||
| if (_harvestProcess.media != null) { | |||
| await UtilAction.cacheFiles(_harvestProcess.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _harvestProcess.media))); | |||
| } | |||
| //list supply | |||
| suppliesUsing = _harvestProcess.suppliesUsing; | |||
| @@ -473,9 +471,10 @@ class _EditActionHarvestProcessScreenState | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -34,6 +34,8 @@ import 'package:mime/mime.dart'; | |||
| import 'package:pattern_formatter/pattern_formatter.dart'; | |||
| import 'package:farm_tpf/utils/formatter.dart'; | |||
| import '../util_action.dart'; | |||
| class EditActionNurseryScreen extends StatefulWidget { | |||
| final int cropId; | |||
| final bool isEdit; | |||
| @@ -93,7 +95,8 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| _nursery.nurseryDetail = currentNurseryDetail; | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| _nursery.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityNursery = jsonEncode(_nursery.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_nursery.activityId == null) { | |||
| @@ -555,14 +558,11 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { | |||
| .format(executeTime); | |||
| //Show media | |||
| if (_nursery.media != null) { | |||
| await cacheFiles(_nursery.media) | |||
| .then((value) { | |||
| print("then: ${value.length}"); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia( | |||
| items: UtilAction | |||
| .convertFilePathToMedia( | |||
| _nursery.media))); | |||
| } | |||
| //Show worker | |||
| if (_nursery.nurseryDetail.length > 0) { | |||
| @@ -648,9 +648,11 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { | |||
| state.items.length.toString()); | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| .change(newPathFiles, | |||
| deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -672,24 +674,4 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { | |||
| _executeByController.dispose(); | |||
| super.dispose(); | |||
| } | |||
| Future<List<Media>> cacheFiles(String existedMedias) async { | |||
| var medias = List<Media>(); | |||
| var mediaPathsLocal = List<String>(); | |||
| var mediaPaths = existedMedias.split(";"); | |||
| for (int i = 0; i < mediaPaths.length; i++) { | |||
| var tempFile = await DefaultCacheManager() | |||
| .getSingleFile(ConstCommon.baseImageUrl + mediaPaths[i]); | |||
| print(tempFile.path); | |||
| var isVideo = lookupMimeType(tempFile.path) == "video/mp4"; | |||
| print("file type: " + lookupMimeType(tempFile.path)); | |||
| Media media = Media() | |||
| ..pathFile = tempFile.path | |||
| ..isVideo = isVideo; | |||
| medias.add(media); | |||
| mediaPathsLocal.add(tempFile.path); | |||
| } | |||
| Get.find<ChangeFileController>().addAllFile(filePaths); | |||
| return medias; | |||
| } | |||
| } | |||
| @@ -78,8 +78,9 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| try { | |||
| _other.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityOther = jsonEncode(_other.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_other.activityId == null) { | |||
| @@ -298,13 +299,10 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { | |||
| } catch (_) {} | |||
| //Show media | |||
| if (_other.media != null) { | |||
| await UtilAction.cacheFiles(_other.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _other.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| } else if (state is ActionDetailLoading) { | |||
| @@ -343,9 +341,10 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -96,8 +96,9 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| try { | |||
| _packing.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityPacking = jsonEncode(_packing.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_packing.activityId == null) { | |||
| @@ -383,13 +384,10 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| } catch (_) {} | |||
| //Show media | |||
| if (_packing.media != null) { | |||
| await UtilAction.cacheFiles(_packing.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _packing.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| } else if (state is ActionDetailLoading) { | |||
| @@ -444,9 +442,10 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -78,7 +78,7 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| List<SuppliesUsing> newSups = []; | |||
| suppliesUsing.forEach((sup) { | |||
| var newSup = sup; | |||
| @@ -86,6 +86,8 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> { | |||
| newSups.add(newSup); | |||
| }); | |||
| _plant.suppliesUsing = newSups; | |||
| _plant.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| print("plant: ${_plant.mediaDel[0]}"); | |||
| var activityPlant = jsonEncode(_plant.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_plant.activityId == null) { | |||
| @@ -282,13 +284,11 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> { | |||
| .format(executeTime); | |||
| //Show media | |||
| if (_plant.media != null) { | |||
| await UtilAction.cacheFiles(_plant.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia( | |||
| items: UtilAction | |||
| .convertFilePathToMedia( | |||
| _plant.media))); | |||
| } | |||
| //list supply | |||
| suppliesUsing = _plant.suppliesUsing; | |||
| @@ -347,9 +347,11 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| .change(newPathFiles, | |||
| deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -96,8 +96,9 @@ class _EditActionSellScreenState extends State<EditActionSellScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| try { | |||
| _sell.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activitySell = jsonEncode(_sell.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_sell.activityId == null) { | |||
| @@ -395,13 +396,10 @@ class _EditActionSellScreenState extends State<EditActionSellScreen> { | |||
| } catch (_) {} | |||
| //Show media | |||
| if (_sell.media != null) { | |||
| await UtilAction.cacheFiles(_sell.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _sell.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| } else if (state is ActionDetailLoading) { | |||
| @@ -460,9 +458,10 @@ class _EditActionSellScreenState extends State<EditActionSellScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -81,7 +81,7 @@ class _EditActionSprayingScreenState extends State<EditActionSprayingScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| List<SuppliesUsing> newSups = []; | |||
| suppliesUsing.forEach((sup) { | |||
| var newSup = sup; | |||
| @@ -90,6 +90,7 @@ class _EditActionSprayingScreenState extends State<EditActionSprayingScreen> { | |||
| newSups.add(newSup); | |||
| }); | |||
| _spraying.suppliesUsing = newSups; | |||
| _spraying.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activitySpraying = jsonEncode(_spraying.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_spraying.activityId == null) { | |||
| @@ -347,13 +348,11 @@ class _EditActionSprayingScreenState extends State<EditActionSprayingScreen> { | |||
| //Show media | |||
| if (_spraying.media != null) { | |||
| await UtilAction.cacheFiles(_spraying.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia( | |||
| items: UtilAction | |||
| .convertFilePathToMedia( | |||
| _spraying.media))); | |||
| } | |||
| //list supply | |||
| suppliesUsing = _spraying.suppliesUsing; | |||
| @@ -429,9 +428,11 @@ class _EditActionSprayingScreenState extends State<EditActionSprayingScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| .change(newPathFiles, | |||
| deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -1,25 +1,17 @@ | |||
| import 'package:get/get.dart'; | |||
| class ChangeFileController extends GetxController { | |||
| List<String> files; | |||
| List<String> newFiles; | |||
| List<String> deleteFiles; | |||
| void initValue() { | |||
| files = []; | |||
| newFiles = []; | |||
| deleteFiles = []; | |||
| update(); | |||
| } | |||
| void addAllFile(List<String> filePaths) { | |||
| files = []; | |||
| files = filePaths; | |||
| update(); | |||
| } | |||
| void addFile(String filePath) { | |||
| files.add(filePath); | |||
| update(); | |||
| } | |||
| void deleteFile(String filePath) { | |||
| files.remove(filePath); | |||
| void change(List<String> newPathFiles, List<String> deletePathFiles) { | |||
| newFiles = newPathFiles; | |||
| deleteFiles = deletePathFiles; | |||
| update(); | |||
| } | |||
| } | |||
| @@ -75,10 +75,11 @@ class _EditActionUseWaterScreenState extends State<EditActionUseWaterScreen> { | |||
| if (_formKey.currentState.validate()) { | |||
| _formKey.currentState.save(); | |||
| LoadingDialog.showLoadingDialog(context); | |||
| filePaths = Get.find<ChangeFileController>().files; | |||
| filePaths = Get.find<ChangeFileController>().newFiles; | |||
| //Create request general model | |||
| try { | |||
| _useWater.waterType = changeRadio.selectedWaterType.waterTypeName; | |||
| _useWater.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||
| var activityUseWater = jsonEncode(_useWater.toJson()).toString(); | |||
| //ADD NEW | |||
| if (_useWater.activityId == null) { | |||
| @@ -303,13 +304,10 @@ class _EditActionUseWaterScreenState extends State<EditActionUseWaterScreen> { | |||
| //Show media | |||
| if (_useWater.media != null) { | |||
| await UtilAction.cacheFiles(_useWater.media) | |||
| .then((value) { | |||
| BlocProvider.of<MediaHelperBloc>(context) | |||
| .add(ChangeListMedia(items: value)); | |||
| }).whenComplete(() { | |||
| print("completed"); | |||
| }); | |||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||
| ChangeListMedia( | |||
| items: UtilAction.convertFilePathToMedia( | |||
| _useWater.media))); | |||
| } | |||
| } else if (state is ActionDetailInitial) { | |||
| } else if (state is ActionDetailLoading) { | |||
| @@ -352,9 +350,10 @@ class _EditActionUseWaterScreenState extends State<EditActionUseWaterScreen> { | |||
| if (state is MediaHelperSuccess) { | |||
| return WidgetMediaPicker( | |||
| currentItems: state.items, | |||
| onChangeFiles: (filePaths) async { | |||
| Get.find<ChangeFileController>() | |||
| .addAllFile(filePaths); | |||
| onChangeFiles: (newPathFiles, | |||
| deletePathFiles) async { | |||
| Get.find<ChangeFileController>().change( | |||
| newPathFiles, deletePathFiles); | |||
| }); | |||
| } else { | |||
| return Center( | |||
| @@ -26,6 +26,21 @@ class UtilAction { | |||
| return medias; | |||
| } | |||
| static List<Media> convertFilePathToMedia(String existedMedias) { | |||
| var medias = List<Media>(); | |||
| var mediaPaths = existedMedias.split(";"); | |||
| for (int i = 0; i < mediaPaths.length; i++) { | |||
| var filePath = ConstCommon.baseImageUrl + mediaPaths[i]; | |||
| var isVideo = lookupMimeType(filePath) == "video/mp4"; | |||
| Media media = Media() | |||
| ..pathFile = filePath | |||
| ..isVideo = isVideo | |||
| ..isServerFile = true; | |||
| medias.add(media); | |||
| } | |||
| return medias; | |||
| } | |||
| static num convertUnit({num inputValue, String oldUnit, String newUnit}) { | |||
| num result = inputValue; | |||
| if (newUnit.isEmpty || newUnit == oldUnit) { | |||
| @@ -113,6 +113,13 @@ packages: | |||
| url: "https://pub.dartlang.org" | |||
| source: hosted | |||
| version: "7.1.0" | |||
| cached_network_image: | |||
| dependency: "direct main" | |||
| description: | |||
| name: cached_network_image | |||
| url: "https://pub.dartlang.org" | |||
| source: hosted | |||
| version: "2.3.2+1" | |||
| camera: | |||
| dependency: "direct main" | |||
| description: | |||
| @@ -307,6 +314,13 @@ packages: | |||
| url: "https://pub.dartlang.org" | |||
| source: hosted | |||
| version: "6.0.5" | |||
| flutter_blurhash: | |||
| dependency: transitive | |||
| description: | |||
| name: flutter_blurhash | |||
| url: "https://pub.dartlang.org" | |||
| source: hosted | |||
| version: "0.5.0" | |||
| flutter_cache_manager: | |||
| dependency: "direct main" | |||
| description: | |||
| @@ -499,6 +513,13 @@ packages: | |||
| url: "https://pub.dartlang.org" | |||
| source: hosted | |||
| version: "1.1.1" | |||
| octo_image: | |||
| dependency: transitive | |||
| description: | |||
| name: octo_image | |||
| url: "https://pub.dartlang.org" | |||
| source: hosted | |||
| version: "0.3.0" | |||
| package_config: | |||
| dependency: transitive | |||
| description: | |||
| @@ -877,4 +898,4 @@ packages: | |||
| version: "2.2.1" | |||
| sdks: | |||
| dart: ">=2.10.0-110 <2.11.0" | |||
| flutter: ">=1.16.0 <2.0.0" | |||
| flutter: ">=1.20.0 <2.0.0" | |||
| @@ -39,6 +39,7 @@ dependencies: | |||
| http_parser: ^3.1.4 | |||
| rflutter_alert: ^1.1.0 | |||
| badges: ^1.1.1 | |||
| cached_network_image: ^2.3.2+1 | |||
| camera: ^0.5.8+5 | |||
| path_provider: ^1.6.14 | |||