| class RequestActivity { | |||||
| int tbActivityTypeId; | |||||
| int tbCropId; | |||||
| int totalCost; | |||||
| String executeDate; | |||||
| String externalTable; | |||||
| String description; | |||||
| List<TbObjectUpdateDTOList> tbObjectUpdateDTOList; | |||||
| List<TbSuppliesUsingDetailsDTOs> tbSuppliesUsingDetailsDTOs; | |||||
| RequestActivity( | |||||
| {this.tbActivityTypeId, | |||||
| this.tbCropId, | |||||
| this.totalCost, | |||||
| this.executeDate, | |||||
| this.externalTable, | |||||
| this.description, | |||||
| this.tbObjectUpdateDTOList, | |||||
| this.tbSuppliesUsingDetailsDTOs}); | |||||
| RequestActivity.fromJson(Map<String, dynamic> json) { | |||||
| tbActivityTypeId = json['tbActivityTypeId']; | |||||
| tbCropId = json['tbCropId']; | |||||
| totalCost = json['totalCost']; | |||||
| executeDate = json['executeDate']; | |||||
| externalTable = json['externalTable']; | |||||
| description = json['description']; | |||||
| if (json['tbObjectUpdateDTOList'] != null) { | |||||
| tbObjectUpdateDTOList = new List<TbObjectUpdateDTOList>(); | |||||
| json['tbObjectUpdateDTOList'].forEach((v) { | |||||
| tbObjectUpdateDTOList.add(new TbObjectUpdateDTOList.fromJson(v)); | |||||
| }); | |||||
| } | |||||
| if (json['tbSuppliesUsingDetailsDTOs'] != null) { | |||||
| tbSuppliesUsingDetailsDTOs = new List<TbSuppliesUsingDetailsDTOs>(); | |||||
| json['tbSuppliesUsingDetailsDTOs'].forEach((v) { | |||||
| tbSuppliesUsingDetailsDTOs | |||||
| .add(new TbSuppliesUsingDetailsDTOs.fromJson(v)); | |||||
| }); | |||||
| } | |||||
| } | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['tbActivityTypeId'] = this.tbActivityTypeId; | |||||
| data['tbCropId'] = this.tbCropId; | |||||
| data['totalCost'] = this.totalCost; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['externalTable'] = this.externalTable; | |||||
| data['description'] = this.description; | |||||
| if (this.tbObjectUpdateDTOList != null) { | |||||
| data['tbObjectUpdateDTOList'] = | |||||
| this.tbObjectUpdateDTOList.map((v) => v.toJson()).toList(); | |||||
| } | |||||
| if (this.tbSuppliesUsingDetailsDTOs != null) { | |||||
| data['tbSuppliesUsingDetailsDTOs'] = | |||||
| this.tbSuppliesUsingDetailsDTOs.map((v) => v.toJson()).toList(); | |||||
| } | |||||
| return data; | |||||
| } | |||||
| } | |||||
| class TbObjectUpdateDTOList { | |||||
| int tbObjectParameterId; | |||||
| String index; | |||||
| TbObjectUpdateDTOList({this.tbObjectParameterId, this.index}); | |||||
| TbObjectUpdateDTOList.fromJson(Map<String, dynamic> json) { | |||||
| tbObjectParameterId = json['tbObjectParameterId']; | |||||
| index = json['index']; | |||||
| } | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['tbObjectParameterId'] = this.tbObjectParameterId; | |||||
| data['index'] = this.index; | |||||
| return data; | |||||
| } | |||||
| } | |||||
| class TbSuppliesUsingDetailsDTOs { | |||||
| int tbSuppliesInWarehouseId; | |||||
| String dosage; | |||||
| int quantity; | |||||
| int tbEquipmentOfCustomerId; | |||||
| String howToUse; | |||||
| TbSuppliesUsingDetailsDTOs( | |||||
| {this.tbSuppliesInWarehouseId, | |||||
| this.dosage, | |||||
| this.quantity, | |||||
| this.tbEquipmentOfCustomerId, | |||||
| this.howToUse}); | |||||
| TbSuppliesUsingDetailsDTOs.fromJson(Map<String, dynamic> json) { | |||||
| tbSuppliesInWarehouseId = json['tbSuppliesInWarehouseId']; | |||||
| dosage = json['dosage']; | |||||
| quantity = json['quantity']; | |||||
| tbEquipmentOfCustomerId = json['tbEquipmentOfCustomerId']; | |||||
| howToUse = json['howToUse']; | |||||
| } | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['tbSuppliesInWarehouseId'] = this.tbSuppliesInWarehouseId; | |||||
| data['dosage'] = this.dosage; | |||||
| data['quantity'] = this.quantity; | |||||
| data['tbEquipmentOfCustomerId'] = this.tbEquipmentOfCustomerId; | |||||
| data['howToUse'] = this.howToUse; | |||||
| return data; | |||||
| } | |||||
| } |
| import 'package:farm_tpf/custom_model/NurseryDetail.dart'; | |||||
| import 'package:get/get_state_manager/get_state_manager.dart'; | |||||
| class ChangeWorker extends GetxController { | |||||
| List<NurseryDetail> currentItems; | |||||
| NurseryDetail currentItem; | |||||
| int currentIndex; | |||||
| void init(List<NurseryDetail> initItems) { | |||||
| currentItems = initItems ?? []; | |||||
| currentItem = NurseryDetail(); | |||||
| currentIndex = -1; | |||||
| update(); | |||||
| } | |||||
| void changeIndexEdit(int index) { | |||||
| currentIndex = index; | |||||
| update(); | |||||
| } | |||||
| void changeInitList(List<NurseryDetail> initListWorkers) { | |||||
| currentItems = initListWorkers; | |||||
| update(); | |||||
| } | |||||
| void addSupply(NurseryDetail nurseryDetail) { | |||||
| currentItems.insert(0, nurseryDetail); | |||||
| currentItem = NurseryDetail(); | |||||
| update(); | |||||
| } | |||||
| void deleteSupply(int index) { | |||||
| currentItems.removeAt(index); | |||||
| currentItem = NurseryDetail(); | |||||
| update(); | |||||
| } | |||||
| void editSupply(int index, NurseryDetail supplyUsing) { | |||||
| var newSup = supplyUsing; | |||||
| newSup.id = currentItems[index].id; | |||||
| currentItems[index] = newSup; | |||||
| currentItem = NurseryDetail(); | |||||
| update(); | |||||
| } | |||||
| } |
| import 'package:farm_tpf/custom_model/NurseryDetail.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/actions/controller/ChangeWorker.dart'; | |||||
| import 'package:farm_tpf/utils/const_string.dart'; | |||||
| import 'package:farm_tpf/utils/validators.dart'; | |||||
| import 'package:flutter/material.dart'; | |||||
| import 'package:get/get.dart'; | |||||
| import 'package:get/get_state_manager/get_state_manager.dart'; | |||||
| class WidgetWorker extends StatefulWidget { | |||||
| @override | |||||
| _WidgetWorkerState createState() => _WidgetWorkerState(); | |||||
| } | |||||
| class _WidgetWorkerState extends State<WidgetWorker> { | |||||
| GlobalKey<FormState> _formWorkerKey = GlobalKey(); | |||||
| TextEditingController _workerNameController = TextEditingController(); | |||||
| TextEditingController _trayNumberController = TextEditingController(); | |||||
| ChangeWorker controller; | |||||
| @override | |||||
| void initState() { | |||||
| super.initState(); | |||||
| controller = Get.put(ChangeWorker()); | |||||
| controller.init([]); | |||||
| } | |||||
| Widget _buildListWorker() { | |||||
| return GetBuilder<ChangeWorker>(builder: (data) { | |||||
| if (data.currentItems.length == 0) { | |||||
| return Container(); | |||||
| } else { | |||||
| return Container( | |||||
| height: 70, | |||||
| child: ListView.builder( | |||||
| physics: ClampingScrollPhysics(), | |||||
| scrollDirection: Axis.horizontal, | |||||
| shrinkWrap: true, | |||||
| itemCount: data?.currentItems?.length ?? 0, | |||||
| itemBuilder: (context, index) { | |||||
| return GestureDetector( | |||||
| onTap: () { | |||||
| print("edit worker"); | |||||
| }, | |||||
| child: Card( | |||||
| child: Stack( | |||||
| alignment: Alignment.bottomCenter, | |||||
| overflow: Overflow.visible, | |||||
| children: <Widget>[ | |||||
| Positioned( | |||||
| child: ClipRRect( | |||||
| borderRadius: BorderRadius.circular(8), | |||||
| child: Container( | |||||
| padding: EdgeInsets.all(4), | |||||
| width: 120, | |||||
| child: Column( | |||||
| mainAxisAlignment: MainAxisAlignment.center, | |||||
| children: [ | |||||
| SizedBox( | |||||
| height: 12.0, | |||||
| ), | |||||
| Flexible( | |||||
| child: Text( | |||||
| data.currentItems[index].workerName ?? | |||||
| '', | |||||
| overflow: TextOverflow.ellipsis, | |||||
| maxLines: 1), | |||||
| ), | |||||
| Validators.stringNotNullOrEmpty( | |||||
| data.currentItems[index].trayNumber) | |||||
| ? Flexible( | |||||
| child: Text(data.currentItems[index] | |||||
| .trayNumber ?? | |||||
| '')) | |||||
| : SizedBox() | |||||
| ], | |||||
| ), | |||||
| ), | |||||
| )), | |||||
| Positioned( | |||||
| top: -10, | |||||
| right: -10, | |||||
| child: IconButton( | |||||
| icon: Icon( | |||||
| Icons.cancel, | |||||
| color: Colors.redAccent, | |||||
| ), | |||||
| onPressed: () { | |||||
| controller.deleteSupply(index); | |||||
| print("Delete worker"); | |||||
| }), | |||||
| ) | |||||
| ], | |||||
| ))); | |||||
| })); | |||||
| } | |||||
| }); | |||||
| } | |||||
| @override | |||||
| Widget build(BuildContext context) { | |||||
| return GetBuilder<ChangeWorker>(builder: (data) { | |||||
| return Container( | |||||
| child: Form( | |||||
| key: _formWorkerKey, | |||||
| child: Column( | |||||
| children: [ | |||||
| Container( | |||||
| width: double.infinity, | |||||
| height: 16, | |||||
| color: Colors.grey[200], | |||||
| ), | |||||
| SizedBox( | |||||
| height: 8.0, | |||||
| ), | |||||
| Padding( | |||||
| padding: const EdgeInsets.all(8.0), | |||||
| child: Align( | |||||
| alignment: Alignment.centerLeft, | |||||
| child: Text( | |||||
| 'Người thực hiện', | |||||
| style: TextStyle(color: Colors.black54, fontSize: 14), | |||||
| ), | |||||
| ), | |||||
| ), | |||||
| _buildListWorker(), | |||||
| Container( | |||||
| padding: EdgeInsets.all(8.0), | |||||
| margin: EdgeInsets.all(8), | |||||
| decoration: BoxDecoration( | |||||
| shape: BoxShape.rectangle, | |||||
| borderRadius: BorderRadius.circular(10), | |||||
| color: Colors.white, | |||||
| border: Border.all(color: Colors.grey[300])), | |||||
| child: Column( | |||||
| children: [ | |||||
| TextFormField( | |||||
| keyboardType: TextInputType.text, | |||||
| controller: _workerNameController, | |||||
| decoration: InputDecoration(labelText: "Tên công nhân *"), | |||||
| validator: (value) { | |||||
| return Validators.validateNotNullOrEmpty( | |||||
| value, label_validate_input_empty); | |||||
| }, | |||||
| onSaved: (newValue) {}, | |||||
| ), | |||||
| TextFormField( | |||||
| keyboardType: TextInputType.text, | |||||
| controller: _trayNumberController, | |||||
| decoration: InputDecoration(labelText: "Ươm khây số"), | |||||
| onSaved: (newValue) {}, | |||||
| ), | |||||
| ], | |||||
| ), | |||||
| ), | |||||
| Container( | |||||
| margin: EdgeInsets.all(8), | |||||
| child: FlatButton( | |||||
| onPressed: () { | |||||
| if (_formWorkerKey.currentState.validate()) { | |||||
| _formWorkerKey.currentState.save(); | |||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _workerNameController.text)) { | |||||
| NurseryDetail _nurseryDetail = NurseryDetail() | |||||
| ..workerName = _workerNameController.text | |||||
| ..trayNumber = _trayNumberController.text; | |||||
| controller.addSupply(_nurseryDetail); | |||||
| _workerNameController.clear(); | |||||
| _trayNumberController.clear(); | |||||
| } else { | |||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập tên công nhân"); | |||||
| } | |||||
| } else { | |||||
| // | |||||
| if (!Validators.stringNotNullOrEmpty( | |||||
| _workerNameController.text)) { | |||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập tên công nhân"); | |||||
| } | |||||
| } | |||||
| }, | |||||
| child: Text( | |||||
| "+ Thêm người thực hiện", | |||||
| style: TextStyle(color: Colors.blue), | |||||
| )), | |||||
| ), | |||||
| ], | |||||
| ), | |||||
| )); | |||||
| }); | |||||
| } | |||||
| } |
| import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | import 'package:keyboard_dismisser/keyboard_dismisser.dart'; | ||||
| import 'dung/widget_dung_supply.dart'; | import 'dung/widget_dung_supply.dart'; | ||||
| import 'nursery/widget_worker.dart'; | |||||
| import 'plant/widget_plant_supply.dart'; | import 'plant/widget_plant_supply.dart'; | ||||
| import 'spraying/widget_spraying_supply.dart'; | import 'spraying/widget_spraying_supply.dart'; | ||||
| import 'state_management_helper/change_file_controller.dart'; | import 'state_management_helper/change_file_controller.dart'; | ||||
| Widget generateSupply(String activityType) { | Widget generateSupply(String activityType) { | ||||
| switch (activityType) { | switch (activityType) { | ||||
| case 'ACTIVE_TYPE_NURSERY': | case 'ACTIVE_TYPE_NURSERY': | ||||
| return Container(); | |||||
| return WidgetWorker(); | |||||
| break; | break; | ||||
| case 'ACTIVE_TYPE_PLANTING': | case 'ACTIVE_TYPE_PLANTING': | ||||
| return Column( | return Column( |