|
|
|
@@ -4,10 +4,13 @@ import 'package:farm_tpf/custom_model/Disease.dart'; |
|
|
|
import 'package:farm_tpf/custom_model/RequestDisease.dart'; |
|
|
|
import 'package:farm_tpf/data/api/app_exception.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/button_widget.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_field_time_picker.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_text_field_description.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_text_form_field.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; |
|
|
|
@@ -223,9 +226,7 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { |
|
|
|
} |
|
|
|
|
|
|
|
Widget _descriptionField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
decoration: InputDecoration(labelText: "Ghi chú"), |
|
|
|
return TextFieldDescriptionWidget( |
|
|
|
controller: _descriptionController, |
|
|
|
onSaved: (newValue) { |
|
|
|
_disease.description = newValue; |
|
|
|
@@ -243,27 +244,6 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
_actionAppBar() { |
|
|
|
IconButton iconButton; |
|
|
|
if (1 == 1) { |
|
|
|
iconButton = IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.done, |
|
|
|
color: Colors.black, |
|
|
|
), |
|
|
|
onPressed: () { |
|
|
|
FocusScopeNode currentFocus = FocusScope.of(context); |
|
|
|
if (!currentFocus.hasPrimaryFocus) { |
|
|
|
currentFocus.unfocus(); |
|
|
|
} |
|
|
|
_validateInputs(); |
|
|
|
}, |
|
|
|
); |
|
|
|
return <Widget>[iconButton]; |
|
|
|
} |
|
|
|
return <Widget>[Container()]; |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) => KeyboardDismisser( |
|
|
|
gestures: [ |
|
|
|
@@ -271,11 +251,22 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { |
|
|
|
GestureType.onPanUpdateDownDirection, |
|
|
|
], |
|
|
|
child: Scaffold( |
|
|
|
backgroundColor: Colors.white, |
|
|
|
key: _scaffoldKey, |
|
|
|
appBar: AppBar( |
|
|
|
centerTitle: true, |
|
|
|
title: Text(plot_action_disease), |
|
|
|
actions: _actionAppBar()), |
|
|
|
appBar: AppBarWidget( |
|
|
|
isBack: true, |
|
|
|
action: InkWell( |
|
|
|
child: Text( |
|
|
|
'Huỷ', |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.red, fontWeight: FontWeight.normal), |
|
|
|
), |
|
|
|
onTap: () { |
|
|
|
if (Get.isSnackbarOpen) Get.back(); |
|
|
|
Get.back(); |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
body: KeyboardDismisser( |
|
|
|
child: MultiBlocProvider( |
|
|
|
providers: [ |
|
|
|
@@ -294,113 +285,155 @@ class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { |
|
|
|
child: Form( |
|
|
|
key: _formKey, |
|
|
|
autovalidate: _autoValidate, |
|
|
|
child: SingleChildScrollView( |
|
|
|
padding: EdgeInsets.all(8.0), |
|
|
|
child: BlocConsumer<ActionDetailBloc, ActionDetailState>( |
|
|
|
listener: (context, state) async { |
|
|
|
if (state is ActionDetailFailure) { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
} else if (state is ActionDetailSuccess) { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
print(state.item); |
|
|
|
_disease = Disease.fromJson(state.item); |
|
|
|
_disease.activityId = widget.activityId; |
|
|
|
_typesOfPestController.text = |
|
|
|
_disease.typesOfPest ?? ""; |
|
|
|
_harmLevelController.text = |
|
|
|
_disease.harmLevel ?? ""; |
|
|
|
_treePercentController.text = _disease.treePercent |
|
|
|
.formatStringToStringDecimal(); |
|
|
|
_locationController.text = _disease.location ?? ""; |
|
|
|
_naturalEnemyController.text = |
|
|
|
_disease.naturalEnemy ?? ""; |
|
|
|
_treatmentMeasuresController.text = |
|
|
|
_disease.treatmentMeasures ?? ""; |
|
|
|
_descriptionController.text = |
|
|
|
_disease.description ?? ""; |
|
|
|
_executeByController.text = _disease.executeBy; |
|
|
|
child: SafeArea( |
|
|
|
child: SingleChildScrollView( |
|
|
|
child: |
|
|
|
BlocConsumer<ActionDetailBloc, ActionDetailState>( |
|
|
|
listener: (context, state) async { |
|
|
|
if (state is ActionDetailFailure) { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
} else if (state is ActionDetailSuccess) { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
print(state.item); |
|
|
|
_disease = Disease.fromJson(state.item); |
|
|
|
_disease.activityId = widget.activityId; |
|
|
|
_typesOfPestController.text = |
|
|
|
_disease.typesOfPest ?? ""; |
|
|
|
_harmLevelController.text = |
|
|
|
_disease.harmLevel ?? ""; |
|
|
|
_treePercentController.text = _disease.treePercent |
|
|
|
.formatStringToStringDecimal(); |
|
|
|
_locationController.text = |
|
|
|
_disease.location ?? ""; |
|
|
|
_naturalEnemyController.text = |
|
|
|
_disease.naturalEnemy ?? ""; |
|
|
|
_treatmentMeasuresController.text = |
|
|
|
_disease.treatmentMeasures ?? ""; |
|
|
|
_descriptionController.text = |
|
|
|
_disease.description ?? ""; |
|
|
|
_executeByController.text = _disease.executeBy; |
|
|
|
|
|
|
|
Get.find<ChangeDateTimePicker>().change(_disease |
|
|
|
.executeDate |
|
|
|
.convertStringServerDateTimeToLocalDateTime()); |
|
|
|
//Show media |
|
|
|
if (Validators.stringNotNullOrEmpty( |
|
|
|
_disease.media)) { |
|
|
|
BlocProvider.of<MediaHelperBloc>(context).add( |
|
|
|
ChangeListMedia( |
|
|
|
items: UtilAction.convertFilePathToMedia( |
|
|
|
_disease.media))); |
|
|
|
Get.find<ChangeDateTimePicker>().change(_disease |
|
|
|
.executeDate |
|
|
|
.convertStringServerDateTimeToLocalDateTime()); |
|
|
|
//Show media |
|
|
|
if (Validators.stringNotNullOrEmpty( |
|
|
|
_disease.media)) { |
|
|
|
BlocProvider.of<MediaHelperBloc>(context).add( |
|
|
|
ChangeListMedia( |
|
|
|
items: |
|
|
|
UtilAction.convertFilePathToMedia( |
|
|
|
_disease.media))); |
|
|
|
} |
|
|
|
} else if (state is ActionDetailInitial) { |
|
|
|
} else if (state is ActionDetailLoading) { |
|
|
|
LoadingDialog.showLoadingDialog(context); |
|
|
|
} |
|
|
|
} else if (state is ActionDetailInitial) { |
|
|
|
} else if (state is ActionDetailLoading) { |
|
|
|
LoadingDialog.showLoadingDialog(context); |
|
|
|
} |
|
|
|
}, |
|
|
|
builder: (context, state) { |
|
|
|
return Column( |
|
|
|
children: <Widget>[ |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Ngày thực hiện *", |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.black54, fontSize: 13.0), |
|
|
|
}, |
|
|
|
builder: (context, state) { |
|
|
|
return Column( |
|
|
|
children: [ |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.all(8.0), |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: |
|
|
|
CrossAxisAlignment.start, |
|
|
|
children: <Widget>[ |
|
|
|
Text( |
|
|
|
plot_action_disease, |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.w500, |
|
|
|
fontSize: 22), |
|
|
|
), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Ngày thực hiện *", |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.black54, |
|
|
|
fontSize: 13.0), |
|
|
|
), |
|
|
|
), |
|
|
|
_btnExecuteTimePicker(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_typeOfPestField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_harmLevelField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_treePercentField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_locationField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_naturalEnemyField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_treatmentMeasuresField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_descriptionField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_executeByField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
height: 16, |
|
|
|
color: Colors.grey[200], |
|
|
|
), |
|
|
|
BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
|
builder: (context, state) { |
|
|
|
if (state is MediaHelperSuccess) { |
|
|
|
return WidgetMediaPicker( |
|
|
|
currentItems: state.items, |
|
|
|
onChangeFiles: (newPathFiles, |
|
|
|
deletePathFiles) async { |
|
|
|
Get.find<ChangeFileController>() |
|
|
|
.change(newPathFiles, |
|
|
|
deletePathFiles); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return Center( |
|
|
|
child: CircularProgressIndicator()); |
|
|
|
} |
|
|
|
}), |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.all(8.0), |
|
|
|
child: ButtonWidget( |
|
|
|
title: 'CẬP NHẬT', |
|
|
|
onPressed: () { |
|
|
|
FocusScopeNode currentFocus = |
|
|
|
FocusScope.of(context); |
|
|
|
if (!currentFocus.hasPrimaryFocus) { |
|
|
|
currentFocus.unfocus(); |
|
|
|
} |
|
|
|
_validateInputs(); |
|
|
|
}), |
|
|
|
), |
|
|
|
), |
|
|
|
_btnExecuteTimePicker(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_typeOfPestField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_harmLevelField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_treePercentField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_locationField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_naturalEnemyField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_treatmentMeasuresField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_descriptionField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_executeByField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
BlocBuilder<MediaHelperBloc, MediaHelperState>( |
|
|
|
builder: (context, state) { |
|
|
|
if (state is MediaHelperSuccess) { |
|
|
|
return WidgetMediaPicker( |
|
|
|
currentItems: state.items, |
|
|
|
onChangeFiles: (newPathFiles, |
|
|
|
deletePathFiles) async { |
|
|
|
Get.find<ChangeFileController>().change( |
|
|
|
newPathFiles, deletePathFiles); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return Center( |
|
|
|
child: CircularProgressIndicator()); |
|
|
|
} |
|
|
|
}), |
|
|
|
], |
|
|
|
); |
|
|
|
}, |
|
|
|
], |
|
|
|
); |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
)), |
|
|
|
)))); |