Browse Source

update flow upload media

master
daivph 5 years ago
parent
commit
35527f6e54
36 changed files with 277 additions and 213 deletions
  1. +1
    -1
      ios/Flutter/.last_build_id
  2. +4
    -1
      lib/custom_model/CropStatus.dart
  3. +3
    -0
      lib/custom_model/Dung.dart
  4. +3
    -0
      lib/custom_model/End.dart
  5. +3
    -0
      lib/custom_model/Harvest.dart
  6. +3
    -0
      lib/custom_model/HarvestProcess.dart
  7. +3
    -0
      lib/custom_model/Nursery.dart
  8. +3
    -0
      lib/custom_model/Other.dart
  9. +3
    -0
      lib/custom_model/Packing.dart
  10. +3
    -0
      lib/custom_model/Plant.dart
  11. +3
    -0
      lib/custom_model/RequestDisease.dart
  12. +3
    -0
      lib/custom_model/RequestEnvironment.dart
  13. +3
    -0
      lib/custom_model/RequestGeneralModel.dart
  14. +3
    -0
      lib/custom_model/Sell.dart
  15. +3
    -0
      lib/custom_model/Spraying.dart
  16. +3
    -0
      lib/custom_model/UseWater.dart
  17. +25
    -20
      lib/presentation/custom_widgets/widget_media_picker.dart
  18. +12
    -2
      lib/presentation/custom_widgets/widget_show_video.dart
  19. +10
    -12
      lib/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart
  20. +10
    -11
      lib/presentation/screens/actions/disease/sc_edit_action_disease.dart
  21. +11
    -10
      lib/presentation/screens/actions/dung/sc_edit_action_dung.dart
  22. +10
    -11
      lib/presentation/screens/actions/end/sc_edit_action_end.dart
  23. +11
    -12
      lib/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart
  24. +10
    -11
      lib/presentation/screens/actions/harvest/sc_edit_action_harvest.dart
  25. +10
    -11
      lib/presentation/screens/actions/harvest_process/sc_edit_action_harvest_process.dart
  26. +13
    -31
      lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart
  27. +10
    -11
      lib/presentation/screens/actions/other/sc_edit_action_other.dart
  28. +10
    -11
      lib/presentation/screens/actions/packing/sc_edit_action_packing.dart
  29. +12
    -10
      lib/presentation/screens/actions/plant/sc_edit_action_plant.dart
  30. +10
    -11
      lib/presentation/screens/actions/sell/sc_edit_action_sell.dart
  31. +11
    -10
      lib/presentation/screens/actions/spraying/sc_edit_action_spraying.dart
  32. +7
    -15
      lib/presentation/screens/actions/state_management_helper/change_file_controller.dart
  33. +10
    -11
      lib/presentation/screens/actions/use_water/sc_edit_action_user_water.dart
  34. +15
    -0
      lib/presentation/screens/actions/util_action.dart
  35. +22
    -1
      pubspec.lock
  36. +1
    -0
      pubspec.yaml

+ 1
- 1
ios/Flutter/.last_build_id View File

48197743e3d78b3769f70bac9a76e7e0
5729eb498eaeb9c64784fcfc80bbb33b

+ 4
- 1
lib/custom_model/CropStatus.dart View File

String description; String description;
String executeBy; String executeBy;
String media; String media;
List<String> mediaDel;


CropStatus( CropStatus(
{this.id, {this.id,
this.internodeLength, this.internodeLength,
this.description, this.description,
this.executeBy, this.executeBy,
this.media});
this.media,
this.mediaDel});


CropStatus.fromJson(Map<String, dynamic> json) { CropStatus.fromJson(Map<String, dynamic> json) {
id = json['id']; id = json['id'];
data['description'] = this.description; data['description'] = this.description;
data['executeBy'] = this.executeBy; data['executeBy'] = this.executeBy;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
return data; return data;
} }
} }

+ 3
- 0
lib/custom_model/Dung.dart View File

String weatherConditions; String weatherConditions;
String purpose; String purpose;
String executeBy; String executeBy;
List<String> mediaDel;
List<SuppliesUsing> suppliesUsing; List<SuppliesUsing> suppliesUsing;


Dung( Dung(
this.weatherConditions, this.weatherConditions,
this.purpose, this.purpose,
this.executeBy, this.executeBy,
this.mediaDel,
this.suppliesUsing}); this.suppliesUsing});


Dung.fromJson(Map<String, dynamic> json) { Dung.fromJson(Map<String, dynamic> json) {
data['weatherConditions'] = this.weatherConditions; data['weatherConditions'] = this.weatherConditions;
data['purpose'] = this.purpose; data['purpose'] = this.purpose;
data['executeBy'] = this.executeBy; data['executeBy'] = this.executeBy;
data['media_del'] = this.mediaDel;
if (this.suppliesUsing != null) { if (this.suppliesUsing != null) {
data['suppliesUsing'] = data['suppliesUsing'] =
this.suppliesUsing.map((v) => v.toJson()).toList(); this.suppliesUsing.map((v) => v.toJson()).toList();

+ 3
- 0
lib/custom_model/End.dart View File

String executeDate; String executeDate;
String description; String description;
String createdByName; String createdByName;
List<String> mediaDel;
String media; String media;


End( End(
this.executeDate, this.executeDate,
this.description, this.description,
this.createdByName, this.createdByName,
this.mediaDel,
this.media}); this.media});


End.fromJson(Map<String, dynamic> json) { End.fromJson(Map<String, dynamic> json) {
data['description'] = this.description; data['description'] = this.description;
data['createdByName'] = this.createdByName; data['createdByName'] = this.createdByName;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
return data; return data;
} }
} }

+ 3
- 0
lib/custom_model/Harvest.dart View File

String description; String description;
String executeBy; String executeBy;
String media; String media;
List<String> mediaDel;
num collectedQuantityLv1; num collectedQuantityLv1;
num collectedQuantityLv2; num collectedQuantityLv2;
num collectedQuantityLv3; num collectedQuantityLv3;
this.description, this.description,
this.executeBy, this.executeBy,
this.media, this.media,
this.mediaDel,
this.collectedQuantityLv1, this.collectedQuantityLv1,
this.collectedQuantityLv2, this.collectedQuantityLv2,
this.collectedQuantityLv3, this.collectedQuantityLv3,
data['description'] = this.description; data['description'] = this.description;
data['executeBy'] = this.executeBy; data['executeBy'] = this.executeBy;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['collectedQuantityLv1'] = this.collectedQuantityLv1; data['collectedQuantityLv1'] = this.collectedQuantityLv1;
data['collectedQuantityLv2'] = this.collectedQuantityLv2; data['collectedQuantityLv2'] = this.collectedQuantityLv2;
data['collectedQuantityLv3'] = this.collectedQuantityLv3; data['collectedQuantityLv3'] = this.collectedQuantityLv3;

+ 3
- 0
lib/custom_model/HarvestProcess.dart View File

String description; String description;
String executeBy; String executeBy;
String media; String media;
List<String> mediaDel;
num quantityLv1; num quantityLv1;
num quantityLv2; num quantityLv2;
num quantityLv3; num quantityLv3;
this.description, this.description,
this.executeBy, this.executeBy,
this.media, this.media,
this.mediaDel,
this.quantityLv1, this.quantityLv1,
this.quantityLv2, this.quantityLv2,
this.quantityLv3, this.quantityLv3,
data['description'] = this.description; data['description'] = this.description;
data['executeBy'] = this.executeBy; data['executeBy'] = this.executeBy;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['quantityLv1'] = this.quantityLv1; data['quantityLv1'] = this.quantityLv1;
data['quantityLv2'] = this.quantityLv2; data['quantityLv2'] = this.quantityLv2;
data['quantityLv3'] = this.quantityLv3; data['quantityLv3'] = this.quantityLv3;

+ 3
- 0
lib/custom_model/Nursery.dart View File

String description; String description;
String executeBy; String executeBy;
String media; String media;
List<String> mediaDel;
String seedName; String seedName;
num substratesId; num substratesId;
String substrateName; String substrateName;
this.description, this.description,
this.executeBy, this.executeBy,
this.media, this.media,
this.mediaDel,
this.seedName, this.seedName,
this.substratesId, this.substratesId,
this.substrateName, this.substrateName,
data['description'] = this.description; data['description'] = this.description;
data['executeBy'] = this.executeBy; data['executeBy'] = this.executeBy;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['seedName'] = this.seedName; data['seedName'] = this.seedName;
data['substratesId'] = this.substratesId; data['substratesId'] = this.substratesId;
data['substrateName'] = this.substrateName; data['substrateName'] = this.substrateName;

+ 3
- 0
lib/custom_model/Other.dart View File

int cropId; int cropId;
int activityId; int activityId;
String media; String media;
List<String> mediaDel;
String executeDate; String executeDate;
String description; String description;
String createdByName; String createdByName;
this.cropId, this.cropId,
this.activityId, this.activityId,
this.media, this.media,
this.mediaDel,
this.executeDate, this.executeDate,
this.description, this.description,
this.createdByName, this.createdByName,
data['cropId'] = this.cropId; data['cropId'] = this.cropId;
data['activityId'] = this.activityId; data['activityId'] = this.activityId;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['executeDate'] = this.executeDate; data['executeDate'] = this.executeDate;
data['description'] = this.description; data['description'] = this.description;
data['createdByName'] = this.createdByName; data['createdByName'] = this.createdByName;

+ 3
- 0
lib/custom_model/Packing.dart View File

String description; String description;
String executeBy; String executeBy;
String media; String media;
List<String> mediaDel;
num quantityLv1; num quantityLv1;
num quantityLv2; num quantityLv2;
num quantityLv3; num quantityLv3;
this.description, this.description,
this.executeBy, this.executeBy,
this.media, this.media,
this.mediaDel,
this.quantityLv1, this.quantityLv1,
this.quantityLv2, this.quantityLv2,
this.quantityLv3, this.quantityLv3,
data['description'] = this.description; data['description'] = this.description;
data['executeBy'] = this.executeBy; data['executeBy'] = this.executeBy;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['quantityLv1'] = this.quantityLv1; data['quantityLv1'] = this.quantityLv1;
data['quantityLv2'] = this.quantityLv2; data['quantityLv2'] = this.quantityLv2;
data['quantityLv3'] = this.quantityLv3; data['quantityLv3'] = this.quantityLv3;

+ 3
- 0
lib/custom_model/Plant.dart View File

String density; String density;
num quantity; num quantity;
String media; String media;
List<String> mediaDel;
List<SuppliesUsing> suppliesUsing; List<SuppliesUsing> suppliesUsing;


Plant( Plant(
this.density, this.density,
this.quantity, this.quantity,
this.media, this.media,
this.mediaDel,
this.suppliesUsing}); this.suppliesUsing});


Plant.fromJson(Map<String, dynamic> json) { Plant.fromJson(Map<String, dynamic> json) {
data['density'] = this.density; data['density'] = this.density;
data['quantity'] = this.quantity; data['quantity'] = this.quantity;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
if (this.suppliesUsing != null) { if (this.suppliesUsing != null) {
data['suppliesUsing'] = data['suppliesUsing'] =
this.suppliesUsing.map((v) => v.toJson()).toList(); this.suppliesUsing.map((v) => v.toJson()).toList();

+ 3
- 0
lib/custom_model/RequestDisease.dart View File

int cropId; int cropId;
String executeDate; String executeDate;
String description; String description;
List<String> mediaDel;
List<ObjectUpdateDetail> objectUpdateDetail; List<ObjectUpdateDetail> objectUpdateDetail;


RequestDisease( RequestDisease(
this.cropId, this.cropId,
this.executeDate, this.executeDate,
this.description, this.description,
this.mediaDel,
this.objectUpdateDetail}); this.objectUpdateDetail});


RequestDisease.fromJson(Map<String, dynamic> json) { RequestDisease.fromJson(Map<String, dynamic> json) {
data['activityId'] = this.activityId; data['activityId'] = this.activityId;
data['executeDate'] = this.executeDate; data['executeDate'] = this.executeDate;
data['description'] = this.description; data['description'] = this.description;
data['media_del'] = this.mediaDel;
if (this.objectUpdateDetail != null) { if (this.objectUpdateDetail != null) {
data['objectUpdateDetail'] = data['objectUpdateDetail'] =
this.objectUpdateDetail.map((v) => v.toJson()).toList(); this.objectUpdateDetail.map((v) => v.toJson()).toList();

+ 3
- 0
lib/custom_model/RequestEnvironment.dart View File

int cropId; int cropId;
String executeDate; String executeDate;
String description; String description;
List<String> mediaDel;
List<EnvDetail> envDetail; List<EnvDetail> envDetail;


RequestEnvironment( RequestEnvironment(
this.cropId, this.cropId,
this.executeDate, this.executeDate,
this.description, this.description,
this.mediaDel,
this.envDetail}); this.envDetail});


RequestEnvironment.fromJson(Map<String, dynamic> json) { RequestEnvironment.fromJson(Map<String, dynamic> json) {
data['cropId'] = this.cropId; data['cropId'] = this.cropId;
data['executeDate'] = this.executeDate; data['executeDate'] = this.executeDate;
data['description'] = this.description; data['description'] = this.description;
data['media_del'] = this.mediaDel;
if (this.envDetail != null) { if (this.envDetail != null) {
data['envDetail'] = this.envDetail.map((v) => v.toJson()).toList(); data['envDetail'] = this.envDetail.map((v) => v.toJson()).toList();
} }

+ 3
- 0
lib/custom_model/RequestGeneralModel.dart View File

int activityId; int activityId;
String executeDate; String executeDate;
String description; String description;
List<String> mediaDel;
List<ObjectUpdateDetail> objectUpdateDetail; List<ObjectUpdateDetail> objectUpdateDetail;


RequestGeneralModel( RequestGeneralModel(
this.activityId, this.activityId,
this.executeDate, this.executeDate,
this.description, this.description,
this.mediaDel,
this.objectUpdateDetail}); this.objectUpdateDetail});


RequestGeneralModel.fromJson(Map<String, dynamic> json) { RequestGeneralModel.fromJson(Map<String, dynamic> json) {
data['activityId'] = this.activityId; data['activityId'] = this.activityId;
data['executeDate'] = this.executeDate; data['executeDate'] = this.executeDate;
data['description'] = this.description; data['description'] = this.description;
data['media_del'] = this.mediaDel;
if (this.objectUpdateDetail != null) { if (this.objectUpdateDetail != null) {
data['objectUpdateDetail'] = data['objectUpdateDetail'] =
this.objectUpdateDetail.map((v) => v.toJson()).toList(); this.objectUpdateDetail.map((v) => v.toJson()).toList();

+ 3
- 0
lib/custom_model/Sell.dart View File

String description; String description;
String executeBy; String executeBy;
String media; String media;
List<String> mediaDel;
num quantityLv1; num quantityLv1;
num quantityLv2; num quantityLv2;
num quantityLv3; num quantityLv3;
this.description, this.description,
this.executeBy, this.executeBy,
this.media, this.media,
this.mediaDel,
this.quantityLv1, this.quantityLv1,
this.quantityLv2, this.quantityLv2,
this.quantityLv3, this.quantityLv3,
data['description'] = this.description; data['description'] = this.description;
data['executeBy'] = this.executeBy; data['executeBy'] = this.executeBy;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['quantityLv1'] = this.quantityLv1; data['quantityLv1'] = this.quantityLv1;
data['quantityLv2'] = this.quantityLv2; data['quantityLv2'] = this.quantityLv2;
data['quantityLv3'] = this.quantityLv3; data['quantityLv3'] = this.quantityLv3;

+ 3
- 0
lib/custom_model/Spraying.dart View File

int activityId; int activityId;
int cropId; int cropId;
String media; String media;
List<String> mediaDel;
String executeDate; String executeDate;
num quarantinePeriod; num quarantinePeriod;
String resultAt; String resultAt;
this.activityId, this.activityId,
this.cropId, this.cropId,
this.media, this.media,
this.mediaDel,
this.executeDate, this.executeDate,
this.quarantinePeriod, this.quarantinePeriod,
this.resultAt, this.resultAt,
data['activityId'] = this.activityId; data['activityId'] = this.activityId;
data['cropId'] = this.cropId; data['cropId'] = this.cropId;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['executeDate'] = this.executeDate; data['executeDate'] = this.executeDate;
data['quarantinePeriod'] = this.quarantinePeriod; data['quarantinePeriod'] = this.quarantinePeriod;
data['resultAt'] = this.resultAt; data['resultAt'] = this.resultAt;

+ 3
- 0
lib/custom_model/UseWater.dart View File

int cropId; int cropId;
String executeDate; String executeDate;
String media; String media;
List<String> mediaDel;
String waterType; String waterType;
num amount; num amount;
String description; String description;
this.cropId, this.cropId,
this.executeDate, this.executeDate,
this.media, this.media,
this.mediaDel,
this.waterType, this.waterType,
this.amount, this.amount,
this.description, this.description,
data['cropId'] = this.cropId; data['cropId'] = this.cropId;
data['executeDate'] = this.executeDate; data['executeDate'] = this.executeDate;
data['media'] = this.media; data['media'] = this.media;
data['media_del'] = this.mediaDel;
data['waterType'] = this.waterType; data['waterType'] = this.waterType;
data['amount'] = this.amount; data['amount'] = this.amount;
data['description'] = this.description; data['description'] = this.description;

+ 25
- 20
lib/presentation/custom_widgets/widget_media_picker.dart View File

import 'dart:io'; import 'dart:io';


import 'package:cached_network_image/cached_network_image.dart';
import 'package:farm_tpf/custom_model/Media.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/camera_helper.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_show_video.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_show_video.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';


import 'bloc/media_helper_bloc.dart'; import 'bloc/media_helper_bloc.dart';
import 'hoz_list_view.dart'; import 'hoz_list_view.dart';


class WidgetMediaPicker extends StatefulWidget { class WidgetMediaPicker extends StatefulWidget {
final List<Media> currentItems; 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}); WidgetMediaPicker({this.currentItems, @required this.onChangeFiles});
@override @override
_WidgetMediaPickerState createState() => _WidgetMediaPickerState(); _WidgetMediaPickerState createState() => _WidgetMediaPickerState();


class _WidgetMediaPickerState extends State<WidgetMediaPicker> { class _WidgetMediaPickerState extends State<WidgetMediaPicker> {
List<Media> currentItems = []; List<Media> currentItems = [];
List<String> files = new List<String>();
List<String> addNewFilePaths = new List<String>();
List<String> deleteFilePaths = new List<String>();


@override @override
void initState() { void initState() {
..isServerFile = false ..isServerFile = false
..pathFile = filePath; ..pathFile = filePath;
currentItems.add(newMedia); currentItems.add(newMedia);
files.add(filePath);
addNewFilePaths.add(filePath);
BlocProvider.of<MediaHelperBloc>(context) BlocProvider.of<MediaHelperBloc>(context)
..add(ChangeListMedia(items: currentItems)); ..add(ChangeListMedia(items: currentItems));
widget.onChangeFiles(files);
widget.onChangeFiles(addNewFilePaths, deleteFilePaths);
} }
print("Kích thước: $lengthFileInBytes bytes");
}); });
} }
}); });
..isServerFile = false ..isServerFile = false
..pathFile = compressFile.path; ..pathFile = compressFile.path;
currentItems.add(newMedia); currentItems.add(newMedia);
files.add(compressFile.path);
addNewFilePaths.add(compressFile.path);
BlocProvider.of<MediaHelperBloc>(context) BlocProvider.of<MediaHelperBloc>(context)
..add(ChangeListMedia(items: currentItems)); ..add(ChangeListMedia(items: currentItems));
widget.onChangeFiles(files);
widget.onChangeFiles(addNewFilePaths, deleteFilePaths);
} }
}); });
} }
..isServerFile = false ..isServerFile = false
..pathFile = filePath; ..pathFile = filePath;
currentItems.add(newMedia); currentItems.add(newMedia);
files.add(filePath);
addNewFilePaths.add(filePath);
BlocProvider.of<MediaHelperBloc>(context) BlocProvider.of<MediaHelperBloc>(context)
..add(ChangeListMedia(items: currentItems)); ..add(ChangeListMedia(items: currentItems));
widget.onChangeFiles(files);
widget.onChangeFiles(addNewFilePaths, deleteFilePaths);
} }
} }
}), }),
return BlocBuilder<MediaHelperBloc, MediaHelperState>( return BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) { builder: (context, state) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
files = [];
currentItems.forEach((element) {
files.add(element.pathFile);
});
widget.onChangeFiles(files);

return WrapContentHozListView( return WrapContentHozListView(
itemBuilder: (context, index) { itemBuilder: (context, index) {
var item = currentItems[index]; var item = currentItems[index];
return _WidgetItemMedia( return _WidgetItemMedia(
item: item, item: item,
deleteImage: (item) { deleteImage: (item) {
files.remove(item.pathFile);
if (item.isServerFile) {
var url =
item.pathFile.replaceAll(ConstCommon.baseImageUrl, '');
deleteFilePaths.add(url);
}
currentItems.remove(item); currentItems.remove(item);
widget.onChangeFiles(files);
widget.onChangeFiles(addNewFilePaths, deleteFilePaths);
BlocProvider.of<MediaHelperBloc>(context) BlocProvider.of<MediaHelperBloc>(context)
.add(ChangeListMedia(items: currentItems)); .add(ChangeListMedia(items: currentItems));
}); });
child: item.isVideo child: item.isVideo
? VideoWidget( ? VideoWidget(
pathFile: item.pathFile, pathFile: item.pathFile,
isServerFile: item.isServerFile,
play: false, play: false,
) )
: Container( : Container(
border: Border.all(color: Colors.grey), border: Border.all(color: Colors.grey),
borderRadius: borderRadius:
BorderRadius.all(Radius.circular(8.0))), 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( Positioned(
top: -14, top: -14,

+ 12
- 2
lib/presentation/custom_widgets/widget_show_video.dart View File



class VideoWidget extends StatefulWidget { class VideoWidget extends StatefulWidget {
final bool play; final bool play;
final bool isServerFile;
final String pathFile; 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); : super(key: key);


@override @override
@override @override
void initState() { void initState() {
super.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((_) { _initializeVideoPlayerFuture = videoPlayerController.initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
videoPlayerController.play(); videoPlayerController.play();

+ 10
- 12
lib/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
//Create request general model //Create request general model
try { try {
RequestGeneralModel generalModel = RequestGeneralModel() RequestGeneralModel generalModel = RequestGeneralModel()
..name = "KHA_NANG_SINH_CHOI" ..name = "KHA_NANG_SINH_CHOI"
..index = _cropStatus.abilityProduceBuds); ..index = _cropStatus.abilityProduceBuds);
generalModel.objectUpdateDetail = generalDetail; generalModel.objectUpdateDetail = generalDetail;
generalModel.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityCropStatus = jsonEncode(generalModel.toJson()).toString(); var activityCropStatus = jsonEncode(generalModel.toJson()).toString();
//ADD NEW //ADD NEW
if (_cropStatus.activityId == null) { if (_cropStatus.activityId == null) {
.format(executeTime); .format(executeTime);
//Show media //Show media
if (_cropStatus.media != null) { 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) { } else if (state is ActionDetailInitial) {
print("init"); print("init");
state.items.length.toString()); state.items.length.toString());
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 10
- 11
lib/presentation/screens/actions/disease/sc_edit_action_disease.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
//Create request general model //Create request general model
try { try {
RequestDisease requestDisease = RequestDisease() RequestDisease requestDisease = RequestDisease()
..name = "BIEN_PHAP_XU_LY" ..name = "BIEN_PHAP_XU_LY"
..index = _disease.treatmentMeasures); ..index = _disease.treatmentMeasures);
requestDisease.objectUpdateDetail = generalDetail; requestDisease.objectUpdateDetail = generalDetail;
requestDisease.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityDisease = jsonEncode(requestDisease.toJson()).toString(); var activityDisease = jsonEncode(requestDisease.toJson()).toString();
//ADD NEW //ADD NEW
if (_disease.activityId == null) { if (_disease.activityId == null) {
.format(executeTime); .format(executeTime);
//Show media //Show media
if (_disease.media != null) { 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 ActionDetailInitial) {
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 11
- 10
lib/presentation/screens/actions/dung/sc_edit_action_dung.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
List<SuppliesUsing> newSups = []; List<SuppliesUsing> newSups = [];
suppliesUsing.forEach((sup) { suppliesUsing.forEach((sup) {
var newSup = sup; var newSup = sup;
newSups.add(newSup); newSups.add(newSup);
}); });
_dung.suppliesUsing = newSups; _dung.suppliesUsing = newSups;
_dung.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityDung = jsonEncode(_dung.toJson()).toString(); var activityDung = jsonEncode(_dung.toJson()).toString();
//ADD NEW //ADD NEW
if (_dung.activityId == null) { if (_dung.activityId == null) {
.format(executeTime); .format(executeTime);
//Show media //Show media
if (_dung.media != null) { 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 //list supply
suppliesUsing = _dung.suppliesUsing; suppliesUsing = _dung.suppliesUsing;
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>() Get.find<ChangeFileController>()
.addAllFile(filePaths);
.change(newPathFiles,
deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 10
- 11
lib/presentation/screens/actions/end/sc_edit_action_end.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
try { try {
_end.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityEnd = jsonEncode(_end.toJson()).toString(); var activityEnd = jsonEncode(_end.toJson()).toString();
//ADD NEW //ADD NEW
if (_end.activityId == null) { if (_end.activityId == null) {
} catch (_) {} } catch (_) {}
//Show media //Show media
if (_end.media != null) { 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 ActionDetailInitial) {
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 11
- 12
lib/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
//Create request general model //Create request general model
try { try {
RequestEnvironment requestEnvironment = RequestEnvironment() RequestEnvironment requestEnvironment = RequestEnvironment()
..name = "LLN" ..name = "LLN"
..index = _environment.lln); ..index = _environment.lln);
requestEnvironment.envDetail = envDetail; requestEnvironment.envDetail = envDetail;
requestEnvironment.mediaDel =
Get.find<ChangeFileController>().deleteFiles;
var activityEnvironmentUpdate = var activityEnvironmentUpdate =
jsonEncode(requestEnvironment.toJson()).toString(); jsonEncode(requestEnvironment.toJson()).toString();
//ADD NEW //ADD NEW
.format(executeTime); .format(executeTime);
//Show media //Show media
if (_environment.media != null) { 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) { } else if (state is ActionDetailInitial) {
print("init"); print("init");
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 10
- 11
lib/presentation/screens/actions/harvest/sc_edit_action_harvest.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
try { try {
_harvest.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityHarvest = jsonEncode(_harvest.toJson()).toString(); var activityHarvest = jsonEncode(_harvest.toJson()).toString();
//ADD NEW //ADD NEW
if (_harvest.activityId == null) { if (_harvest.activityId == null) {
} catch (_) {} } catch (_) {}
//Show media //Show media
if (_harvest.media != null) { 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 ActionDetailInitial) {
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 10
- 11
lib/presentation/screens/actions/harvest_process/sc_edit_action_harvest_process.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
List<SuppliesUsing> newSups = []; List<SuppliesUsing> newSups = [];
suppliesUsing.forEach((sup) { suppliesUsing.forEach((sup) {
var newSup = sup; var newSup = sup;
newSups.add(newSup); newSups.add(newSup);
}); });
_harvestProcess.suppliesUsing = newSups; _harvestProcess.suppliesUsing = newSups;
_harvestProcess.mediaDel = Get.find<ChangeFileController>().deleteFiles;
try { try {
var activityHarvestProcess = var activityHarvestProcess =
jsonEncode(_harvestProcess.toJson()).toString(); jsonEncode(_harvestProcess.toJson()).toString();
} catch (_) {} } catch (_) {}
//Show media //Show media
if (_harvestProcess.media != null) { 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 //list supply
suppliesUsing = _harvestProcess.suppliesUsing; suppliesUsing = _harvestProcess.suppliesUsing;
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 13
- 31
lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart View File

import 'package:pattern_formatter/pattern_formatter.dart'; import 'package:pattern_formatter/pattern_formatter.dart';
import 'package:farm_tpf/utils/formatter.dart'; import 'package:farm_tpf/utils/formatter.dart';


import '../util_action.dart';

class EditActionNurseryScreen extends StatefulWidget { class EditActionNurseryScreen extends StatefulWidget {
final int cropId; final int cropId;
final bool isEdit; final bool isEdit;
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
_nursery.nurseryDetail = currentNurseryDetail; _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(); var activityNursery = jsonEncode(_nursery.toJson()).toString();
//ADD NEW //ADD NEW
if (_nursery.activityId == null) { if (_nursery.activityId == null) {
.format(executeTime); .format(executeTime);
//Show media //Show media
if (_nursery.media != null) { 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 //Show worker
if (_nursery.nurseryDetail.length > 0) { if (_nursery.nurseryDetail.length > 0) {
state.items.length.toString()); state.items.length.toString());
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>() Get.find<ChangeFileController>()
.addAllFile(filePaths);
.change(newPathFiles,
deletePathFiles);
}); });
} else { } else {
return Center( return Center(
_executeByController.dispose(); _executeByController.dispose();
super.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;
}
} }

+ 10
- 11
lib/presentation/screens/actions/other/sc_edit_action_other.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
try { try {
_other.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityOther = jsonEncode(_other.toJson()).toString(); var activityOther = jsonEncode(_other.toJson()).toString();
//ADD NEW //ADD NEW
if (_other.activityId == null) { if (_other.activityId == null) {
} catch (_) {} } catch (_) {}
//Show media //Show media
if (_other.media != null) { 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 ActionDetailInitial) {
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 10
- 11
lib/presentation/screens/actions/packing/sc_edit_action_packing.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
try { try {
_packing.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityPacking = jsonEncode(_packing.toJson()).toString(); var activityPacking = jsonEncode(_packing.toJson()).toString();
//ADD NEW //ADD NEW
if (_packing.activityId == null) { if (_packing.activityId == null) {
} catch (_) {} } catch (_) {}
//Show media //Show media
if (_packing.media != null) { 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 ActionDetailInitial) {
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 12
- 10
lib/presentation/screens/actions/plant/sc_edit_action_plant.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
List<SuppliesUsing> newSups = []; List<SuppliesUsing> newSups = [];
suppliesUsing.forEach((sup) { suppliesUsing.forEach((sup) {
var newSup = sup; var newSup = sup;
newSups.add(newSup); newSups.add(newSup);
}); });
_plant.suppliesUsing = newSups; _plant.suppliesUsing = newSups;
_plant.mediaDel = Get.find<ChangeFileController>().deleteFiles;
print("plant: ${_plant.mediaDel[0]}");
var activityPlant = jsonEncode(_plant.toJson()).toString(); var activityPlant = jsonEncode(_plant.toJson()).toString();
//ADD NEW //ADD NEW
if (_plant.activityId == null) { if (_plant.activityId == null) {
.format(executeTime); .format(executeTime);
//Show media //Show media
if (_plant.media != null) { 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 //list supply
suppliesUsing = _plant.suppliesUsing; suppliesUsing = _plant.suppliesUsing;
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>() Get.find<ChangeFileController>()
.addAllFile(filePaths);
.change(newPathFiles,
deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 10
- 11
lib/presentation/screens/actions/sell/sc_edit_action_sell.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
try { try {
_sell.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activitySell = jsonEncode(_sell.toJson()).toString(); var activitySell = jsonEncode(_sell.toJson()).toString();
//ADD NEW //ADD NEW
if (_sell.activityId == null) { if (_sell.activityId == null) {
} catch (_) {} } catch (_) {}
//Show media //Show media
if (_sell.media != null) { 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 ActionDetailInitial) {
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 11
- 10
lib/presentation/screens/actions/spraying/sc_edit_action_spraying.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
List<SuppliesUsing> newSups = []; List<SuppliesUsing> newSups = [];
suppliesUsing.forEach((sup) { suppliesUsing.forEach((sup) {
var newSup = sup; var newSup = sup;
newSups.add(newSup); newSups.add(newSup);
}); });
_spraying.suppliesUsing = newSups; _spraying.suppliesUsing = newSups;
_spraying.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activitySpraying = jsonEncode(_spraying.toJson()).toString(); var activitySpraying = jsonEncode(_spraying.toJson()).toString();
//ADD NEW //ADD NEW
if (_spraying.activityId == null) { if (_spraying.activityId == null) {


//Show media //Show media
if (_spraying.media != null) { 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 //list supply
suppliesUsing = _spraying.suppliesUsing; suppliesUsing = _spraying.suppliesUsing;
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>() Get.find<ChangeFileController>()
.addAllFile(filePaths);
.change(newPathFiles,
deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 7
- 15
lib/presentation/screens/actions/state_management_helper/change_file_controller.dart View File

import 'package:get/get.dart'; import 'package:get/get.dart';


class ChangeFileController extends GetxController { class ChangeFileController extends GetxController {
List<String> files;
List<String> newFiles;
List<String> deleteFiles;
void initValue() { void initValue() {
files = [];
newFiles = [];
deleteFiles = [];
update(); 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(); update();
} }
} }

+ 10
- 11
lib/presentation/screens/actions/use_water/sc_edit_action_user_water.dart View File

if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
filePaths = Get.find<ChangeFileController>().newFiles;
//Create request general model //Create request general model
try { try {
_useWater.waterType = changeRadio.selectedWaterType.waterTypeName; _useWater.waterType = changeRadio.selectedWaterType.waterTypeName;
_useWater.mediaDel = Get.find<ChangeFileController>().deleteFiles;
var activityUseWater = jsonEncode(_useWater.toJson()).toString(); var activityUseWater = jsonEncode(_useWater.toJson()).toString();
//ADD NEW //ADD NEW
if (_useWater.activityId == null) { if (_useWater.activityId == null) {


//Show media //Show media
if (_useWater.media != null) { 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 ActionDetailInitial) {
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
if (state is MediaHelperSuccess) { if (state is MediaHelperSuccess) {
return WidgetMediaPicker( return WidgetMediaPicker(
currentItems: state.items, currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
}); });
} else { } else {
return Center( return Center(

+ 15
- 0
lib/presentation/screens/actions/util_action.dart View File

return medias; 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}) { static num convertUnit({num inputValue, String oldUnit, String newUnit}) {
num result = inputValue; num result = inputValue;
if (newUnit.isEmpty || newUnit == oldUnit) { if (newUnit.isEmpty || newUnit == oldUnit) {

+ 22
- 1
pubspec.lock View File

url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "7.1.0" 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: camera:
dependency: "direct main" dependency: "direct main"
description: description:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.5" 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: flutter_cache_manager:
dependency: "direct main" dependency: "direct main"
description: description:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.1" 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: package_config:
dependency: transitive dependency: transitive
description: description:
version: "2.2.1" version: "2.2.1"
sdks: sdks:
dart: ">=2.10.0-110 <2.11.0" dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.16.0 <2.0.0"
flutter: ">=1.20.0 <2.0.0"

+ 1
- 0
pubspec.yaml View File

http_parser: ^3.1.4 http_parser: ^3.1.4
rflutter_alert: ^1.1.0 rflutter_alert: ^1.1.0
badges: ^1.1.1 badges: ^1.1.1
cached_network_image: ^2.3.2+1


camera: ^0.5.8+5 camera: ^0.5.8+5
path_provider: ^1.6.14 path_provider: ^1.6.14

Loading…
Cancel
Save