| @@ -26,7 +26,6 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| final changeSelectedSupply = Get.put(ChangeSupply()); | |||
| final changeSupplyUsing = Get.put(ChangeSupplyUsing()); | |||
| final changeUnit = Get.put(ChangeUnit()); | |||
| final changeQuantity = Get.put(ChangeValueQuantity()); | |||
| final changeButton = Get.put(ChangeButtonInForm()); | |||
| @override | |||
| @@ -35,7 +34,6 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| changeSelectedSupply.initValue(); | |||
| changeSupplyUsing.init(widget.currentItems); | |||
| changeUnit.initValue(); | |||
| changeQuantity.changeQuantity(""); | |||
| changeButton.resetValue(); | |||
| } | |||
| @@ -64,12 +62,12 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| ..tbSuppliesName = editedSupplyUsing.supplyName | |||
| ..unit = editedSupplyUsing.supplyUnit; | |||
| changeSelectedSupply.change(editedSupply); | |||
| changeQuantity.changeQuantity(editedSupplyUsing.quantity | |||
| .formatNumtoStringDecimal()); | |||
| changeUnit | |||
| .updateListByUnitName(editedSupplyUsing.supplyUnit); | |||
| changeUnit.updateSelected(editedSupplyUsing.supplyUnit); | |||
| _dosageController.text = editedSupplyUsing.dosage; | |||
| _quantityController.text = editedSupplyUsing.quantity | |||
| .formatNumtoStringDecimal(); | |||
| }, | |||
| child: Card( | |||
| child: Stack( | |||
| @@ -182,8 +180,7 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| .toList(), | |||
| onChanged: (value) { | |||
| var currentQuantity = _quantityController.text; | |||
| changeQuantity.changeQuantity(currentQuantity); | |||
| num assignValue = changeQuantity.quantity.parseDoubleThousand(); | |||
| num assignValue = currentQuantity.parseDoubleThousand(); | |||
| if (assignValue != null) { | |||
| var oldSelected = data.selectedUnit; | |||
| if (oldSelected == value) { | |||
| @@ -193,8 +190,7 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| oldUnit: oldSelected, | |||
| newUnit: value); | |||
| } | |||
| changeQuantity | |||
| .changeQuantity(assignValue.formatNumtoStringDecimal()); | |||
| _quantityController.text = assignValue.formatNumtoStringDecimal(); | |||
| } | |||
| changeUnit.updateSelected(value); | |||
| }, | |||
| @@ -203,22 +199,21 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| } | |||
| _quantityField() { | |||
| return GetBuilder<ChangeValueQuantity>(builder: (_) { | |||
| WidgetsBinding.instance.addPostFrameCallback((timeStamp) { | |||
| var quantityValue = changeQuantity.quantity; | |||
| _quantityController.text = quantityValue; | |||
| }); | |||
| return TextFormField( | |||
| keyboardType: TextInputType.numberWithOptions(decimal: true), | |||
| inputFormatters: [ | |||
| ThousandsFormatter( | |||
| formatter: NumberFormat("#,###.##", "es"), allowFraction: true) | |||
| ], | |||
| decoration: InputDecoration(labelText: "Tổng lượng sử dụng"), | |||
| controller: _quantityController, | |||
| ); | |||
| }); | |||
| return TextFormField( | |||
| keyboardType: TextInputType.numberWithOptions(decimal: true), | |||
| inputFormatters: [ | |||
| ThousandsFormatter( | |||
| formatter: NumberFormat("#,###.##", "es"), allowFraction: true) | |||
| ], | |||
| decoration: InputDecoration(labelText: "Tổng lượng sử dụng"), | |||
| controller: _quantityController, | |||
| onSaved: (newValue) { | |||
| print(newValue); | |||
| }, | |||
| onChanged: (v) { | |||
| print(v); | |||
| }, | |||
| ); | |||
| } | |||
| _buttonInForm() { | |||
| @@ -246,14 +241,14 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| borderRadius: new BorderRadius.circular(8.0)), | |||
| onPressed: () { | |||
| var currentSupply = changeSelectedSupply.currentSupply; | |||
| changeQuantity.changeQuantity(_quantityController.text); | |||
| var quantityWithCurrentSupplyUnit = | |||
| UtilAction.convertUnit( | |||
| inputValue: | |||
| changeQuantity.quantity.parseDoubleThousand(), | |||
| oldUnit: changeUnit.selectedUnit, | |||
| newUnit: changeSelectedSupply.currentSupply.unit); | |||
| if (currentSupply.id != null) { | |||
| var quantityWithCurrentSupplyUnit = | |||
| UtilAction.convertUnit( | |||
| inputValue: _quantityController.text | |||
| .parseDoubleThousand(), | |||
| oldUnit: changeUnit.selectedUnit, | |||
| newUnit: | |||
| changeSelectedSupply.currentSupply.unit); | |||
| SuppliesUsing newSup = SuppliesUsing() | |||
| ..dosage = _dosageController.text | |||
| ..quantity = quantityWithCurrentSupplyUnit | |||
| @@ -279,10 +274,9 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| onPressed: () { | |||
| var currentSupply = changeSelectedSupply.currentSupply; | |||
| if (currentSupply.id != null) { | |||
| changeQuantity.changeQuantity(_quantityController.text); | |||
| var quantityWithCurrentSupplyUnit = | |||
| UtilAction.convertUnit( | |||
| inputValue: changeQuantity.quantity | |||
| inputValue: _quantityController.text | |||
| .parseDoubleThousand(), | |||
| oldUnit: changeUnit.selectedUnit, | |||
| newUnit: | |||
| @@ -368,7 +362,6 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { | |||
| _quantityController.text = ""; | |||
| changeUnit.initValue(); | |||
| changeSelectedSupply.initValue(); | |||
| changeQuantity.changeQuantity(""); | |||
| } | |||
| _hidenKeyboard(BuildContext context) { | |||
| @@ -418,14 +411,6 @@ class ChangeUnit extends GetxController { | |||
| } | |||
| } | |||
| class ChangeValueQuantity extends GetxController { | |||
| String quantity = ""; | |||
| void changeQuantity(String newQuantity) { | |||
| quantity = newQuantity; | |||
| update(); | |||
| } | |||
| } | |||
| class ChangeButtonInForm extends GetxController { | |||
| bool isEdit; | |||
| void resetValue() { | |||