|
|
|
@@ -11,6 +11,8 @@ import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/nursery/bloc/expansion_list_bloc.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_supply.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/resources/sc_resource_helper.dart'; |
|
|
|
import 'package:farm_tpf/utils/bloc/bloc/status_add_form_bloc.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
|
@@ -23,7 +25,6 @@ import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart'; |
|
|
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; |
|
|
|
import 'package:fluttertoast/fluttertoast.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:get/state_manager.dart'; |
|
|
|
import 'package:intl/intl.dart'; |
|
|
|
@@ -49,7 +50,6 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
bool _autoValidate = false; |
|
|
|
Nursery _nursery = Nursery(); |
|
|
|
var pref = LocalPref(); |
|
|
|
FlutterToast flutterToast; |
|
|
|
TextEditingController _substrateController = TextEditingController(); |
|
|
|
TextEditingController _seedLengthController = TextEditingController(); |
|
|
|
TextEditingController _quantityController = TextEditingController(); |
|
|
|
@@ -60,7 +60,6 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
String executeTimeView; |
|
|
|
DateTime executeTime = DateTime.now(); |
|
|
|
List<NurseryDetail> currentNurseryDetail = List<NurseryDetail>(); |
|
|
|
ExpansionListBloc _bloc; |
|
|
|
int currentIndexUpdate = -1; |
|
|
|
bool isResetForm = true; |
|
|
|
final changeSupply = Get.put(ChangeSupply()); |
|
|
|
@@ -74,7 +73,6 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
changeSupply.initValue(); |
|
|
|
changeFileController.initValue(); |
|
|
|
_nursery.nurseryDetail = new List<NurseryDetail>(); |
|
|
|
flutterToast = FlutterToast(context); |
|
|
|
//UPDATE |
|
|
|
if (_nursery.id != null) { |
|
|
|
try { |
|
|
|
@@ -124,7 +122,7 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
_repository.updateNursery((value) { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
Get.back(); |
|
|
|
Get.snackbar(label_add_success, "Hoạt động ươm", |
|
|
|
Get.snackbar(label_update_success, "Hoạt động ươm", |
|
|
|
snackPosition: SnackPosition.BOTTOM); |
|
|
|
}, (error) { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
@@ -182,14 +180,14 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
))); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _btnSelectSeed() { |
|
|
|
Widget _btnSelectSubstrates() { |
|
|
|
return FlatButton( |
|
|
|
padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), |
|
|
|
onPressed: () { |
|
|
|
Navigator.of(context) |
|
|
|
.push(MaterialPageRoute( |
|
|
|
builder: (_) => ResourceHelperScreen( |
|
|
|
titleName: "Gía thể", |
|
|
|
titleName: "Giá thể", |
|
|
|
type: ConstCommon.supplyTypeSubStrate, |
|
|
|
selectedId: Get.find<ChangeSupply>().selectedSupplyId), |
|
|
|
fullscreenDialog: false)) |
|
|
|
@@ -404,7 +402,7 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
itemBuilder: (context, index) { |
|
|
|
return GestureDetector( |
|
|
|
onTap: () { |
|
|
|
print("Show preview image or video"); |
|
|
|
print("edit worker"); |
|
|
|
currentIndexUpdate = index; |
|
|
|
context.bloc<StatusAddFormBloc>().add(Changed( |
|
|
|
status: CRUDStatus.edit, |
|
|
|
@@ -453,7 +451,7 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
color: Colors.redAccent, |
|
|
|
), |
|
|
|
onPressed: () { |
|
|
|
print("On tap delete media"); |
|
|
|
print("Delete worker"); |
|
|
|
context.bloc<ExpansionListBloc>().add( |
|
|
|
DeleteItem( |
|
|
|
index: index, |
|
|
|
@@ -548,10 +546,26 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
print("success"); |
|
|
|
print(state.item); |
|
|
|
_nursery = Nursery.fromJson(state.item); |
|
|
|
_seedLengthController.text = |
|
|
|
_nursery.seedLength.toString(); |
|
|
|
_seedLengthController.text = _nursery |
|
|
|
.seedLength |
|
|
|
.formatNumtoStringDecimal(); |
|
|
|
_quantityController.text = _nursery.quantity |
|
|
|
.formatNumtoStringDecimal(); |
|
|
|
_seedIncubationTimeController.text = _nursery |
|
|
|
.seedIncubationTime |
|
|
|
.formatNumtoStringDecimal(); |
|
|
|
_descriptionController.text = |
|
|
|
_nursery.description; |
|
|
|
try { |
|
|
|
executeTime = |
|
|
|
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") |
|
|
|
.parse(_nursery.executeDate); |
|
|
|
} catch (_) {} |
|
|
|
executeTimeView = |
|
|
|
DateFormat("dd/MM/yyyy HH:mm") |
|
|
|
.format(executeTime); |
|
|
|
//Show media |
|
|
|
if (_nursery.media.isNotEmpty) { |
|
|
|
if (_nursery.media != null) { |
|
|
|
await cacheFiles(_nursery.media) |
|
|
|
.then((value) { |
|
|
|
print("then: ${value.length}"); |
|
|
|
@@ -567,6 +581,11 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
.add(AddNew( |
|
|
|
items: _nursery.nurseryDetail)); |
|
|
|
} |
|
|
|
//change subStrates |
|
|
|
if (_nursery.substratesId != null) { |
|
|
|
Get.find<ChangeSupply>() |
|
|
|
.changeById(_nursery.substratesId); |
|
|
|
} |
|
|
|
} else if (state is ActionDetailInitial) { |
|
|
|
print("init"); |
|
|
|
} else if (state is ActionDetailLoading) { |
|
|
|
@@ -593,13 +612,13 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Tên giống", |
|
|
|
"Loại giá thể", |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.black54, |
|
|
|
fontSize: 13.0), |
|
|
|
), |
|
|
|
), |
|
|
|
_btnSelectSeed(), |
|
|
|
_btnSelectSubstrates(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
@@ -679,44 +698,3 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
return medias; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class ChangeSupply extends GetxController { |
|
|
|
Supply currentSupply; |
|
|
|
int selectedSupplyId; |
|
|
|
|
|
|
|
void initValue() { |
|
|
|
currentSupply = Supply(); |
|
|
|
selectedSupplyId = -1; |
|
|
|
update(); |
|
|
|
} |
|
|
|
|
|
|
|
void change(Supply supply) { |
|
|
|
currentSupply = supply; |
|
|
|
selectedSupplyId = supply.id; |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class ChangeFileController extends GetxController { |
|
|
|
List<String> files; |
|
|
|
void initValue() { |
|
|
|
files = []; |
|
|
|
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); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |