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.

216 lines
8.6KB

  1. import 'package:farm_tpf/custom_model/action_form/RequestActivity.dart';
  2. import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart';
  3. import 'package:farm_tpf/presentation/screens/actions/controller/ChangeFieldInForm.dart';
  4. import 'package:farm_tpf/presentation/screens/actions/controller/ChangeWorker.dart';
  5. import 'package:farm_tpf/utils/const_string.dart';
  6. import 'package:farm_tpf/utils/validators.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:get/get.dart';
  9. import 'package:get/get_state_manager/get_state_manager.dart';
  10. class WidgetWorker extends StatefulWidget {
  11. final Function(List<TbNurseryDetailsDTO>) onChangeWorkers;
  12. const WidgetWorker({@required this.onChangeWorkers});
  13. @override
  14. _WidgetWorkerState createState() => _WidgetWorkerState();
  15. }
  16. class _WidgetWorkerState extends State<WidgetWorker> {
  17. GlobalKey<FormState> _formWorkerKey = GlobalKey();
  18. TextEditingController _workerNameController = TextEditingController();
  19. TextEditingController _trayNumberController = TextEditingController();
  20. ChangeWorker controller;
  21. final changeFormField = Get.put(ChangeFieldFormSupply());
  22. @override
  23. void initState() {
  24. super.initState();
  25. controller = Get.put(ChangeWorker());
  26. controller.init([]);
  27. changeFormField.init();
  28. }
  29. Widget _buildListWorker() {
  30. return GetBuilder<ChangeWorker>(builder: (data) {
  31. widget.onChangeWorkers(data.currentItems ?? []);
  32. if (data.currentItems?.length == 0 || data.currentItems == null) {
  33. return Container();
  34. } else {
  35. return Container(
  36. height: 70,
  37. child: ListView.builder(
  38. physics: ClampingScrollPhysics(),
  39. scrollDirection: Axis.horizontal,
  40. shrinkWrap: true,
  41. itemCount: data?.currentItems?.length ?? 0,
  42. itemBuilder: (context, index) {
  43. return GestureDetector(
  44. onTap: () {
  45. print("edit worker");
  46. },
  47. child: Card(
  48. child: Stack(
  49. alignment: Alignment.bottomCenter,
  50. overflow: Overflow.visible,
  51. children: <Widget>[
  52. Positioned(
  53. child: ClipRRect(
  54. borderRadius: BorderRadius.circular(8),
  55. child: Container(
  56. padding: EdgeInsets.all(4),
  57. width: 120,
  58. child: Column(
  59. mainAxisAlignment: MainAxisAlignment.center,
  60. children: [
  61. SizedBox(
  62. height: 12.0,
  63. ),
  64. Flexible(
  65. child: Text(
  66. data.currentItems[index].workerName ??
  67. '',
  68. overflow: TextOverflow.ellipsis,
  69. maxLines: 1),
  70. ),
  71. Validators.stringNotNullOrEmpty(
  72. data.currentItems[index].trayNumber)
  73. ? Flexible(
  74. child: Text(data.currentItems[index]
  75. .trayNumber ??
  76. ''))
  77. : SizedBox()
  78. ],
  79. ),
  80. ),
  81. )),
  82. Positioned(
  83. top: -10,
  84. right: -10,
  85. child: IconButton(
  86. icon: Icon(
  87. Icons.cancel,
  88. color: Colors.redAccent,
  89. ),
  90. onPressed: () {
  91. controller.deleteNurseryDetail(index);
  92. print("Delete worker");
  93. }),
  94. )
  95. ],
  96. )));
  97. }));
  98. }
  99. });
  100. }
  101. @override
  102. Widget build(BuildContext context) {
  103. return GetBuilder<ChangeWorker>(builder: (data) {
  104. return Container(
  105. child: Form(
  106. key: _formWorkerKey,
  107. child: Column(
  108. children: [
  109. Container(
  110. width: double.infinity,
  111. height: 16,
  112. color: Colors.grey[200],
  113. ),
  114. SizedBox(
  115. height: 8.0,
  116. ),
  117. Padding(
  118. padding: const EdgeInsets.all(8.0),
  119. child: Align(
  120. alignment: Alignment.centerLeft,
  121. child: Text(
  122. 'Người thực hiện',
  123. style: TextStyle(color: Colors.black54, fontSize: 14),
  124. ),
  125. ),
  126. ),
  127. _buildListWorker(),
  128. Container(
  129. padding: EdgeInsets.all(8.0),
  130. margin: EdgeInsets.all(8),
  131. decoration: BoxDecoration(
  132. shape: BoxShape.rectangle,
  133. borderRadius: BorderRadius.circular(10),
  134. color: Colors.white,
  135. border: Border.all(color: Colors.grey[300])),
  136. child: Column(
  137. children: [
  138. TextFormField(
  139. keyboardType: TextInputType.text,
  140. controller: _workerNameController,
  141. decoration: InputDecoration(labelText: "Tên công nhân *"),
  142. validator: (value) {
  143. return Validators.validateNotNullOrEmpty(
  144. value, label_validate_input_empty);
  145. },
  146. onSaved: (newValue) {},
  147. onChanged: (value) {
  148. if (!Validators.stringNotNullOrEmpty(value)) {
  149. changeFormField.change(false);
  150. } else {
  151. changeFormField.change(true);
  152. }
  153. },
  154. ),
  155. TextFormField(
  156. keyboardType: TextInputType.text,
  157. controller: _trayNumberController,
  158. decoration: InputDecoration(labelText: "Ươm khây số"),
  159. onSaved: (newValue) {},
  160. onChanged: (value) {
  161. if (!Validators.stringNotNullOrEmpty(value)) {
  162. changeFormField.change(false);
  163. } else {
  164. changeFormField.change(true);
  165. }
  166. },
  167. ),
  168. ],
  169. ),
  170. ),
  171. Container(
  172. margin: EdgeInsets.all(8),
  173. child: FlatButton(
  174. onPressed: () {
  175. if (_formWorkerKey.currentState.validate()) {
  176. _formWorkerKey.currentState.save();
  177. if (Validators.stringNotNullOrEmpty(
  178. _workerNameController.text)) {
  179. TbNurseryDetailsDTO _nurseryDetail =
  180. TbNurseryDetailsDTO()
  181. ..workerName = _workerNameController.text
  182. ..trayNumber = _trayNumberController.text;
  183. controller.addNurseryDetail(_nurseryDetail);
  184. _workerNameController.clear();
  185. _trayNumberController.clear();
  186. changeFormField.change(false);
  187. } else {
  188. Utils.showSnackBarWarning(
  189. message: "Vui lòng nhập tên công nhân");
  190. }
  191. } else {
  192. //
  193. if (!Validators.stringNotNullOrEmpty(
  194. _workerNameController.text)) {
  195. Utils.showSnackBarWarning(
  196. message: "Vui lòng nhập tên công nhân");
  197. }
  198. }
  199. },
  200. child: Text(
  201. "+ Thêm người thực hiện",
  202. style: TextStyle(color: Colors.blue),
  203. )),
  204. ),
  205. ],
  206. ),
  207. ));
  208. });
  209. }
  210. }