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.

295 lines
11KB

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