Browse Source

update plant action

master
daivph 5 years ago
parent
commit
e46833b68b
1 changed files with 27 additions and 42 deletions
  1. +27
    -42
      lib/presentation/screens/actions/plant/widget_plant_supply.dart

+ 27
- 42
lib/presentation/screens/actions/plant/widget_plant_supply.dart View File

final changeSelectedSupply = Get.put(ChangeSupply()); final changeSelectedSupply = Get.put(ChangeSupply());
final changeSupplyUsing = Get.put(ChangeSupplyUsing()); final changeSupplyUsing = Get.put(ChangeSupplyUsing());
final changeUnit = Get.put(ChangeUnit()); final changeUnit = Get.put(ChangeUnit());
final changeQuantity = Get.put(ChangeValueQuantity());
final changeButton = Get.put(ChangeButtonInForm()); final changeButton = Get.put(ChangeButtonInForm());


@override @override
changeSelectedSupply.initValue(); changeSelectedSupply.initValue();
changeSupplyUsing.init(widget.currentItems); changeSupplyUsing.init(widget.currentItems);
changeUnit.initValue(); changeUnit.initValue();
changeQuantity.changeQuantity("");
changeButton.resetValue(); changeButton.resetValue();
} }


..tbSuppliesName = editedSupplyUsing.supplyName ..tbSuppliesName = editedSupplyUsing.supplyName
..unit = editedSupplyUsing.supplyUnit; ..unit = editedSupplyUsing.supplyUnit;
changeSelectedSupply.change(editedSupply); changeSelectedSupply.change(editedSupply);
changeQuantity.changeQuantity(editedSupplyUsing.quantity
.formatNumtoStringDecimal());
changeUnit changeUnit
.updateListByUnitName(editedSupplyUsing.supplyUnit); .updateListByUnitName(editedSupplyUsing.supplyUnit);
changeUnit.updateSelected(editedSupplyUsing.supplyUnit); changeUnit.updateSelected(editedSupplyUsing.supplyUnit);
_dosageController.text = editedSupplyUsing.dosage; _dosageController.text = editedSupplyUsing.dosage;
_quantityController.text = editedSupplyUsing.quantity
.formatNumtoStringDecimal();
}, },
child: Card( child: Card(
child: Stack( child: Stack(
.toList(), .toList(),
onChanged: (value) { onChanged: (value) {
var currentQuantity = _quantityController.text; var currentQuantity = _quantityController.text;
changeQuantity.changeQuantity(currentQuantity);
num assignValue = changeQuantity.quantity.parseDoubleThousand();
num assignValue = currentQuantity.parseDoubleThousand();
if (assignValue != null) { if (assignValue != null) {
var oldSelected = data.selectedUnit; var oldSelected = data.selectedUnit;
if (oldSelected == value) { if (oldSelected == value) {
oldUnit: oldSelected, oldUnit: oldSelected,
newUnit: value); newUnit: value);
} }
changeQuantity
.changeQuantity(assignValue.formatNumtoStringDecimal());
_quantityController.text = assignValue.formatNumtoStringDecimal();
} }
changeUnit.updateSelected(value); changeUnit.updateSelected(value);
}, },
} }


_quantityField() { _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() { _buttonInForm() {
borderRadius: new BorderRadius.circular(8.0)), borderRadius: new BorderRadius.circular(8.0)),
onPressed: () { onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply; 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) { if (currentSupply.id != null) {
var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit(
inputValue: _quantityController.text
.parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit,
newUnit:
changeSelectedSupply.currentSupply.unit);
SuppliesUsing newSup = SuppliesUsing() SuppliesUsing newSup = SuppliesUsing()
..dosage = _dosageController.text ..dosage = _dosageController.text
..quantity = quantityWithCurrentSupplyUnit ..quantity = quantityWithCurrentSupplyUnit
onPressed: () { onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply; var currentSupply = changeSelectedSupply.currentSupply;
if (currentSupply.id != null) { if (currentSupply.id != null) {
changeQuantity.changeQuantity(_quantityController.text);
var quantityWithCurrentSupplyUnit = var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit( UtilAction.convertUnit(
inputValue: changeQuantity.quantity
inputValue: _quantityController.text
.parseDoubleThousand(), .parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit, oldUnit: changeUnit.selectedUnit,
newUnit: newUnit:
_quantityController.text = ""; _quantityController.text = "";
changeUnit.initValue(); changeUnit.initValue();
changeSelectedSupply.initValue(); changeSelectedSupply.initValue();
changeQuantity.changeQuantity("");
} }


_hidenKeyboard(BuildContext context) { _hidenKeyboard(BuildContext context) {
} }
} }


class ChangeValueQuantity extends GetxController {
String quantity = "";
void changeQuantity(String newQuantity) {
quantity = newQuantity;
update();
}
}

class ChangeButtonInForm extends GetxController { class ChangeButtonInForm extends GetxController {
bool isEdit; bool isEdit;
void resetValue() { void resetValue() {

Loading…
Cancel
Save