You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
11KB

  1. import 'package:farm_tpf/custom_model/CropPlot.dart';
  2. import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
  3. import 'package:farm_tpf/presentation/screens/plot_detail/bloc_plot_information.dart';
  4. import 'package:farm_tpf/utils/const_color.dart';
  5. import 'package:farm_tpf/utils/const_string.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:get/get.dart';
  8. import 'package:keyboard_dismisser/keyboard_dismisser.dart';
  9. import 'package:farm_tpf/utils/formatter.dart';
  10. class PlotInformationScreen extends StatefulWidget {
  11. final int cropId;
  12. PlotInformationScreen({@required this.cropId});
  13. @override
  14. _PlotInformationScreenState createState() => _PlotInformationScreenState();
  15. }
  16. class _PlotInformationScreenState extends State<PlotInformationScreen> {
  17. final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  18. GlobalKey<FormState> _formKey = GlobalKey();
  19. TextEditingController _statusController = TextEditingController();
  20. TextEditingController _houseNameController = TextEditingController();
  21. TextEditingController _codeController = TextEditingController();
  22. TextEditingController _supplyNameController = TextEditingController();
  23. TextEditingController _seedingDateController = TextEditingController();
  24. TextEditingController _timeSoakSeedController = TextEditingController();
  25. TextEditingController _timeNurserySeedController = TextEditingController();
  26. TextEditingController _quantityPlantController = TextEditingController();
  27. TextEditingController _currentPlantController = TextEditingController();
  28. TextEditingController _timeEndGrowController = TextEditingController();
  29. TextEditingController _mainTechnicianController = TextEditingController();
  30. TextEditingController _areaController = TextEditingController();
  31. TextEditingController _descriptionController = TextEditingController();
  32. bool _autoValidate = false;
  33. TbCropDTO _crop = TbCropDTO();
  34. final controller = Get.put(DescriptionChangeControler());
  35. @override
  36. void initState() {
  37. super.initState();
  38. getPlotInfoBloc.getPlotInfo(widget.cropId, (data) {
  39. var result = data as CropPlot;
  40. _crop = result.tbCropDTO;
  41. var statusCrop;
  42. switch (_crop.status) {
  43. case "STATUS_ARE_ACTIVE":
  44. statusCrop = plot_status_active;
  45. break;
  46. case "STATUS_FINISHED":
  47. statusCrop = plot_status_end;
  48. break;
  49. default:
  50. statusCrop = plot_status_unknown;
  51. }
  52. _statusController.text = statusCrop;
  53. _houseNameController.text = _crop.netHouseName.toString();
  54. _codeController.text = _crop.code.toString();
  55. _supplyNameController.text = _crop.suppliesName.toString();
  56. _areaController.text = _crop.areaM2.formatNumtoStringDecimal();
  57. _crop.description = "";
  58. }, (err) {});
  59. }
  60. _validateInputs() async {
  61. if (_formKey.currentState.validate()) {
  62. _formKey.currentState.save();
  63. } else {
  64. _autoValidate = true;
  65. }
  66. }
  67. Widget _statusField() {
  68. return TextFormField(
  69. controller: _statusController,
  70. decoration: InputDecoration(labelText: "Trạng thái"),
  71. );
  72. }
  73. Widget _houseNameField() {
  74. return TextFormField(
  75. controller: _houseNameController,
  76. decoration: InputDecoration(labelText: "Nhà màng"),
  77. );
  78. }
  79. Widget _codeField() {
  80. return TextFormField(
  81. controller: _codeController,
  82. decoration: InputDecoration(labelText: "Mã lô"),
  83. );
  84. }
  85. Widget _supplyNameField() {
  86. return TextFormField(
  87. controller: _supplyNameController,
  88. decoration: InputDecoration(labelText: "Giống"),
  89. );
  90. }
  91. Widget _seedingDateField() {
  92. return TextFormField(
  93. controller: _seedingDateController,
  94. decoration: InputDecoration(labelText: "Ngày gieo trồng"),
  95. );
  96. }
  97. Widget _timeSoakSeedField() {
  98. return TextFormField(
  99. controller: _timeSoakSeedController,
  100. decoration: InputDecoration(labelText: "Thời gian ngâm hạt"),
  101. );
  102. }
  103. Widget _timeNurserySeedField() {
  104. return TextFormField(
  105. controller: _timeNurserySeedController,
  106. decoration: InputDecoration(labelText: "Thời gian vô khây ươm"),
  107. );
  108. }
  109. Widget _quantityPlantField() {
  110. return TextFormField(
  111. controller: _quantityPlantController,
  112. decoration: InputDecoration(labelText: "Số lượng cây trồng"),
  113. );
  114. }
  115. Widget _currentPlantField() {
  116. return TextFormField(
  117. controller: _currentPlantController,
  118. decoration: InputDecoration(labelText: "Số lượng cây hiện tại"),
  119. );
  120. }
  121. Widget _timeEndGrowField() {
  122. return TextFormField(
  123. controller: _timeEndGrowController,
  124. decoration: InputDecoration(labelText: "Ngày kết thúc canh tác"),
  125. );
  126. }
  127. Widget _mainTechnicianField() {
  128. return TextFormField(
  129. controller: _mainTechnicianController,
  130. decoration: InputDecoration(labelText: "Kỹ sư trực tiếp"),
  131. );
  132. }
  133. Widget _areaField() {
  134. return TextFormField(
  135. controller: _areaController,
  136. decoration: InputDecoration(labelText: "Diện tích (m\u00B2)"),
  137. );
  138. }
  139. Widget _descriptionField() {
  140. return TextFormField(
  141. keyboardType: TextInputType.text,
  142. controller: _descriptionController,
  143. decoration: InputDecoration(labelText: "Ghi chú"),
  144. onSaved: (newValue) {
  145. _crop.description = newValue;
  146. },
  147. onChanged: (newValue) {
  148. controller.changeValue(_crop.description, newValue);
  149. },
  150. );
  151. }
  152. _actionAppBar() {
  153. return <Widget>[
  154. GetBuilder<DescriptionChangeControler>(
  155. builder: (_) {
  156. return IconButton(
  157. icon: Icon(
  158. Icons.done,
  159. ),
  160. disabledColor: Colors.grey,
  161. onPressed: controller.isChanged == false ? null : () {},
  162. );
  163. },
  164. )
  165. ];
  166. }
  167. @override
  168. Widget build(BuildContext context) => KeyboardDismisser(
  169. gestures: [
  170. GestureType.onTap,
  171. GestureType.onPanUpdateDownDirection,
  172. ],
  173. child: Container(
  174. color: COLOR_CONST.ITEM_BG,
  175. child: SafeArea(
  176. top: false,
  177. bottom: true,
  178. child: Scaffold(
  179. key: _scaffoldKey,
  180. appBar: AppBar(
  181. centerTitle: true,
  182. title: Text("Thông tin lô"),
  183. actions: _actionAppBar()),
  184. body: KeyboardDismisser(
  185. child: StreamBuilder(
  186. stream: getPlotInfoBloc.actions,
  187. builder: (BuildContext context,
  188. AsyncSnapshot<dynamic> snapshot) {
  189. if (snapshot.hasData) {
  190. return Form(
  191. key: _formKey,
  192. autovalidate: _autoValidate,
  193. child: SingleChildScrollView(
  194. padding: EdgeInsets.all(8.0),
  195. child: Column(
  196. children: <Widget>[
  197. _statusField(),
  198. SizedBox(
  199. height: 4.0,
  200. ),
  201. _houseNameField(),
  202. SizedBox(
  203. height: 4.0,
  204. ),
  205. _codeField(),
  206. SizedBox(
  207. height: 4.0,
  208. ),
  209. _supplyNameField(),
  210. SizedBox(
  211. height: 4.0,
  212. ),
  213. _seedingDateField(),
  214. SizedBox(
  215. height: 4.0,
  216. ),
  217. _timeSoakSeedField(),
  218. SizedBox(
  219. height: 4.0,
  220. ),
  221. _timeNurserySeedField(),
  222. SizedBox(
  223. height: 4.0,
  224. ),
  225. _quantityPlantField(),
  226. SizedBox(
  227. height: 4.0,
  228. ),
  229. _currentPlantField(),
  230. SizedBox(
  231. height: 4.0,
  232. ),
  233. _timeEndGrowField(),
  234. SizedBox(
  235. height: 4.0,
  236. ),
  237. _mainTechnicianField(),
  238. SizedBox(
  239. height: 4.0,
  240. ),
  241. _areaField(),
  242. SizedBox(
  243. height: 4.0,
  244. ),
  245. _descriptionField()
  246. ],
  247. ),
  248. ));
  249. } else if (snapshot.hasError) {
  250. return Center(
  251. child: Text(snapshot.error.toString()),
  252. );
  253. } else {
  254. return LoadingListPage();
  255. }
  256. }))))));
  257. }
  258. class DescriptionChangeControler extends GetxController {
  259. bool isChanged = false;
  260. void changeValue(String oldValue, String newValue) {
  261. if (oldValue != newValue) {
  262. isChanged = true;
  263. } else {
  264. isChanged = false;
  265. }
  266. update();
  267. }
  268. }