| import 'package:farm_tpf/custom_model/RequestGeneralModel.dart'; | import 'package:farm_tpf/custom_model/RequestGeneralModel.dart'; | ||||
| import 'package:farm_tpf/data/api/app_exception.dart'; | import 'package:farm_tpf/data/api/app_exception.dart'; | ||||
| import 'package:farm_tpf/data/repository/repository.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/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_field_time_picker.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.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_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_text_form_field.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; | import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; | ||||
| } | } | ||||
| Widget _desciptionField() { | Widget _desciptionField() { | ||||
| return TextFormField( | |||||
| keyboardType: TextInputType.text, | |||||
| decoration: InputDecoration(labelText: "Ghi chú"), | |||||
| controller: _descriptionController, | |||||
| onSaved: (newValue) { | |||||
| _cropStatus.description = newValue; | |||||
| }, | |||||
| ); | |||||
| return TextFieldDescriptionWidget( | |||||
| controller: _descriptionController, | |||||
| onSaved: (newValue) { | |||||
| _cropStatus.description = newValue; | |||||
| }); | |||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| ); | ); | ||||
| } | } | ||||
| _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 | @override | ||||
| Widget build(BuildContext context) => KeyboardDismisser( | Widget build(BuildContext context) => KeyboardDismisser( | ||||
| gestures: [ | gestures: [ | ||||
| ], | ], | ||||
| child: Scaffold( | child: Scaffold( | ||||
| key: _scaffoldKey, | key: _scaffoldKey, | ||||
| appBar: AppBar( | |||||
| centerTitle: true, | |||||
| title: Text(plot_action_crop_status), | |||||
| 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( | body: KeyboardDismisser( | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | autovalidate: _autoValidate, | ||||
| child: SingleChildScrollView( | |||||
| padding: EdgeInsets.all(8.0), | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | |||||
| if (state is ActionDetailFailure) { | |||||
| print("fail"); | |||||
| LoadingDialog.hideLoadingDialog(context); | |||||
| } else if (state is ActionDetailSuccess) { | |||||
| LoadingDialog.hideLoadingDialog(context); | |||||
| print("success"); | |||||
| print(state.item); | |||||
| _cropStatus = CropStatus.fromJson(state.item); | |||||
| _cropStatus.activityId = widget.activityId; | |||||
| _cropRateController.text = _cropStatus.cropRate | |||||
| .formatStringToStringDecimal(); | |||||
| _numTreeController.text = _cropStatus | |||||
| .numberOfTreeToGrow | |||||
| .formatStringToStringDecimal(); | |||||
| _heightOfTreeController.text = _cropStatus | |||||
| .heightOfTree | |||||
| .formatStringToStringDecimal(); | |||||
| _numberOfLeafController.text = _cropStatus | |||||
| .numberOfLeaf | |||||
| .formatStringToStringDecimal(); | |||||
| _leafSizeController.text = _cropStatus.leafSize | |||||
| .formatStringToStringDecimal(); | |||||
| _leafColorController.text = | |||||
| _cropStatus.leafColor ?? ""; | |||||
| _abilityProduceBudsController.text = | |||||
| _cropStatus.abilityProduceBuds ?? ""; | |||||
| _internodeLengthController.text = _cropStatus | |||||
| .internodeLength | |||||
| .formatStringToStringDecimal(); | |||||
| _descriptionController.text = | |||||
| _cropStatus.description ?? ""; | |||||
| _executeByController.text = | |||||
| _cropStatus.executeBy ?? ""; | |||||
| child: SafeArea( | |||||
| child: SingleChildScrollView( | |||||
| child: | |||||
| BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | |||||
| if (state is ActionDetailFailure) { | |||||
| print("fail"); | |||||
| LoadingDialog.hideLoadingDialog(context); | |||||
| } else if (state is ActionDetailSuccess) { | |||||
| LoadingDialog.hideLoadingDialog(context); | |||||
| print("success"); | |||||
| print(state.item); | |||||
| _cropStatus = CropStatus.fromJson(state.item); | |||||
| _cropStatus.activityId = widget.activityId; | |||||
| _cropRateController.text = _cropStatus.cropRate | |||||
| .formatStringToStringDecimal(); | |||||
| _numTreeController.text = _cropStatus | |||||
| .numberOfTreeToGrow | |||||
| .formatStringToStringDecimal(); | |||||
| _heightOfTreeController.text = _cropStatus | |||||
| .heightOfTree | |||||
| .formatStringToStringDecimal(); | |||||
| _numberOfLeafController.text = _cropStatus | |||||
| .numberOfLeaf | |||||
| .formatStringToStringDecimal(); | |||||
| _leafSizeController.text = _cropStatus.leafSize | |||||
| .formatStringToStringDecimal(); | |||||
| _leafColorController.text = | |||||
| _cropStatus.leafColor ?? ""; | |||||
| _abilityProduceBudsController.text = | |||||
| _cropStatus.abilityProduceBuds ?? ""; | |||||
| _internodeLengthController.text = _cropStatus | |||||
| .internodeLength | |||||
| .formatStringToStringDecimal(); | |||||
| _descriptionController.text = | |||||
| _cropStatus.description ?? ""; | |||||
| _executeByController.text = | |||||
| _cropStatus.executeBy ?? ""; | |||||
| Get.find<ChangeDateTimePicker>().change(_cropStatus | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| //Show media | |||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _cropStatus.media)) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||||
| ChangeListMedia( | |||||
| items: UtilAction.convertFilePathToMedia( | |||||
| _cropStatus.media))); | |||||
| Get.find<ChangeDateTimePicker>().change(_cropStatus | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| //Show media | |||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _cropStatus.media)) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||||
| ChangeListMedia( | |||||
| items: | |||||
| UtilAction.convertFilePathToMedia( | |||||
| _cropStatus.media))); | |||||
| } | |||||
| } else if (state is ActionDetailInitial) { | |||||
| print("init"); | |||||
| } else if (state is ActionDetailLoading) { | |||||
| print("loading"); | |||||
| LoadingDialog.showLoadingDialog(context); | |||||
| } | } | ||||
| } else if (state is ActionDetailInitial) { | |||||
| print("init"); | |||||
| } else if (state is ActionDetailLoading) { | |||||
| print("loading"); | |||||
| 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_crop_status, | |||||
| 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, | |||||
| ), | |||||
| _cropRateField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _numTreeField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _hightOfTreeField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _numberOfLeafField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _leafSizeField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _leafColorField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _internodeLengthField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _abilityProduceBudsField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _desciptionField(), | |||||
| 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) { | |||||
| print("length: " + | |||||
| state.items.length.toString()); | |||||
| 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, | |||||
| ), | |||||
| _cropRateField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _numTreeField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _hightOfTreeField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _numberOfLeafField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _leafSizeField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _leafColorField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _internodeLengthField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _abilityProduceBudsField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _desciptionField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| _executeByField(), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | |||||
| print("length: " + | |||||
| state.items.length.toString()); | |||||
| return WidgetMediaPicker( | |||||
| currentItems: state.items, | |||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change( | |||||
| newPathFiles, deletePathFiles); | |||||
| }); | |||||
| } else { | |||||
| return Center( | |||||
| child: CircularProgressIndicator()); | |||||
| } | |||||
| }), | |||||
| ], | |||||
| ); | |||||
| }, | |||||
| ], | |||||
| ); | |||||
| }, | |||||
| ), | |||||
| ), | ), | ||||
| )), | )), | ||||
| )))); | )))); |