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.

198 lines
7.7KB

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