|
|
|
@@ -331,232 +331,237 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> { |
|
|
|
|
|
|
|
_buttonInForm() { |
|
|
|
return GetBuilder<ChangeButtonInForm>(builder: (_) { |
|
|
|
return Align( |
|
|
|
alignment: Alignment.centerRight, |
|
|
|
child: Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
_.isEdit |
|
|
|
? OutlineButton( |
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
borderRadius: new BorderRadius.circular(8.0)), |
|
|
|
child: Text("Huỷ"), |
|
|
|
onPressed: () { |
|
|
|
changeButton.resetValue(); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
}) |
|
|
|
: SizedBox(), |
|
|
|
_.isEdit |
|
|
|
? FlatButton( |
|
|
|
color: AppColors.DEFAULT, |
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
borderRadius: new BorderRadius.circular(8.0)), |
|
|
|
onPressed: () { |
|
|
|
if (_formSupplyKey.currentState.validate()) { |
|
|
|
_formSupplyKey.currentState.save(); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
return Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
_.isEdit |
|
|
|
? OutlineButton( |
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
borderRadius: new BorderRadius.circular(8.0)), |
|
|
|
child: Text("Huỷ"), |
|
|
|
onPressed: () { |
|
|
|
changeButton.resetValue(); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
}) |
|
|
|
: SizedBox(), |
|
|
|
_.isEdit |
|
|
|
? Expanded( |
|
|
|
child: FlatButton( |
|
|
|
onPressed: () { |
|
|
|
if (_formSupplyKey.currentState.validate()) { |
|
|
|
_formSupplyKey.currentState.save(); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
var currentSupply = |
|
|
|
changeSelectedSupply.currentSupply; |
|
|
|
var currentDevice = |
|
|
|
changeSelectedDevice.currentDevice; |
|
|
|
var currentQuantity = |
|
|
|
_quantityController.text.parseDoubleThousand(); |
|
|
|
if (currentSupply.id != null && |
|
|
|
(currentQuantity ?? 0) > 0) { |
|
|
|
var quantityWithCurrentSupplyUnit = |
|
|
|
UtilAction.convertUnit( |
|
|
|
inputValue: currentQuantity, |
|
|
|
oldUnit: changeUnit.selectedUnit, |
|
|
|
newUnit: changeSelectedSupply |
|
|
|
.currentSupply.unit); |
|
|
|
SuppliesUsing newSup = SuppliesUsing() |
|
|
|
..dosage = _dosageController.text |
|
|
|
..howToUse = _howToUseController.text |
|
|
|
..quantity = quantityWithCurrentSupplyUnit |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..tbEquipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentName = currentDevice.name |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.editSupply( |
|
|
|
changeSupplyUsing.currentIndex, newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
} else if (currentSupply.id == null || |
|
|
|
((currentQuantity ?? 0) <= 0)) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập vật tư và số lượng"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
var currentSupply = changeSelectedSupply.currentSupply; |
|
|
|
var currentDevice = changeSelectedDevice.currentDevice; |
|
|
|
var currentQuantity = |
|
|
|
_quantityController.text.parseDoubleThousand(); |
|
|
|
if (currentSupply.id != null && |
|
|
|
(currentQuantity ?? 0) > 0) { |
|
|
|
var quantityWithCurrentSupplyUnit = |
|
|
|
UtilAction.convertUnit( |
|
|
|
inputValue: currentQuantity, |
|
|
|
oldUnit: changeUnit.selectedUnit, |
|
|
|
newUnit: |
|
|
|
changeSelectedSupply.currentSupply.unit); |
|
|
|
SuppliesUsing newSup = SuppliesUsing() |
|
|
|
..dosage = _dosageController.text |
|
|
|
..howToUse = _howToUseController.text |
|
|
|
..quantity = quantityWithCurrentSupplyUnit |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..tbEquipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentName = currentDevice.name |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.editSupply( |
|
|
|
changeSupplyUsing.currentIndex, newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
} else if (currentSupply.id == null || |
|
|
|
((currentQuantity ?? 0) <= 0)) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập vật tư và số lượng"); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập vật tư và số lượng"); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
"Sửa", |
|
|
|
style: TextStyle(color: Colors.white), |
|
|
|
)) |
|
|
|
: FlatButton( |
|
|
|
color: AppColors.DEFAULT, |
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
borderRadius: new BorderRadius.circular(8.0)), |
|
|
|
onPressed: () { |
|
|
|
if (_formSupplyKey.currentState.validate()) { |
|
|
|
_formSupplyKey.currentState.save(); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
"Sửa phân bón", |
|
|
|
style: TextStyle(color: Colors.blue), |
|
|
|
)), |
|
|
|
) |
|
|
|
: Expanded( |
|
|
|
child: FlatButton( |
|
|
|
onPressed: () { |
|
|
|
if (_formSupplyKey.currentState.validate()) { |
|
|
|
_formSupplyKey.currentState.save(); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
var currentSupply = |
|
|
|
changeSelectedSupply.currentSupply; |
|
|
|
var currentDevice = |
|
|
|
changeSelectedDevice.currentDevice; |
|
|
|
var currentQuantity = |
|
|
|
_quantityController.text.parseDoubleThousand(); |
|
|
|
if (currentSupply.id != null && |
|
|
|
(currentQuantity ?? 0) > 0) { |
|
|
|
var quantityWithCurrentSupplyUnit = |
|
|
|
UtilAction.convertUnit( |
|
|
|
inputValue: currentQuantity, |
|
|
|
oldUnit: changeUnit.selectedUnit, |
|
|
|
newUnit: changeSelectedSupply |
|
|
|
.currentSupply.unit); |
|
|
|
SuppliesUsing newSup = SuppliesUsing() |
|
|
|
..dosage = _dosageController.text |
|
|
|
..howToUse = _howToUseController.text |
|
|
|
..quantity = quantityWithCurrentSupplyUnit |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..tbEquipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentName = currentDevice.name |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.addSupply(newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
} else if (currentSupply.id == null || |
|
|
|
((currentQuantity ?? 0) <= 0)) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập vật tư và số lượng"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
var currentSupply = changeSelectedSupply.currentSupply; |
|
|
|
var currentDevice = changeSelectedDevice.currentDevice; |
|
|
|
var currentQuantity = |
|
|
|
_quantityController.text.parseDoubleThousand(); |
|
|
|
if (currentSupply.id != null && |
|
|
|
(currentQuantity ?? 0) > 0) { |
|
|
|
var quantityWithCurrentSupplyUnit = |
|
|
|
UtilAction.convertUnit( |
|
|
|
inputValue: currentQuantity, |
|
|
|
oldUnit: changeUnit.selectedUnit, |
|
|
|
newUnit: |
|
|
|
changeSelectedSupply.currentSupply.unit); |
|
|
|
SuppliesUsing newSup = SuppliesUsing() |
|
|
|
..dosage = _dosageController.text |
|
|
|
..howToUse = _howToUseController.text |
|
|
|
..quantity = quantityWithCurrentSupplyUnit |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..tbEquipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentOfCustomerId = currentDevice.id |
|
|
|
..equipmentName = currentDevice.name |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.addSupply(newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
} else if (currentSupply.id == null || |
|
|
|
((currentQuantity ?? 0) <= 0)) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập vật tư và số lượng"); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
// |
|
|
|
} |
|
|
|
} else { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập vật tư và số lượng"); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
// |
|
|
|
} |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
"Thêm", |
|
|
|
style: TextStyle(color: Colors.white), |
|
|
|
)) |
|
|
|
], |
|
|
|
), |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
"+ Thêm phân bón", |
|
|
|
style: TextStyle(color: Colors.blue), |
|
|
|
)), |
|
|
|
) |
|
|
|
], |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _formEdit() { |
|
|
|
return Container( |
|
|
|
padding: EdgeInsets.all(8.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
shape: BoxShape.rectangle, |
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
|
color: Colors.white, |
|
|
|
border: Border.all(color: AppColors.DEFAULT)), |
|
|
|
child: Form( |
|
|
|
key: _formSupplyKey, |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
_btnSelectSubstrates(), |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _dosageController, |
|
|
|
decoration: InputDecoration(labelText: "Liều lượng sử dụng"), |
|
|
|
onSaved: (newValue) {}, |
|
|
|
onChanged: (value) { |
|
|
|
if (!Validators.stringNotNullOrEmpty( |
|
|
|
_quantityController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty( |
|
|
|
_howToUseController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty(value) && |
|
|
|
Get.find<ChangeSupply>().selectedSupplyId <= 0 && |
|
|
|
changeSelectedDevice.selectedDeviceId <= 0) { |
|
|
|
changeFormField.change(false); |
|
|
|
} else { |
|
|
|
changeFormField.change(true); |
|
|
|
} |
|
|
|
}, |
|
|
|
), |
|
|
|
Row( |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
flex: 2, |
|
|
|
child: Container( |
|
|
|
height: 70, |
|
|
|
child: _quantityField(), |
|
|
|
return Form( |
|
|
|
key: _formSupplyKey, |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.all(8.0), |
|
|
|
margin: EdgeInsets.all(8.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
shape: BoxShape.rectangle, |
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
|
color: Colors.white, |
|
|
|
border: Border.all(color: Colors.grey[300])), |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
_btnSelectSubstrates(), |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _dosageController, |
|
|
|
decoration: InputDecoration(labelText: "Liều lượng sử dụng"), |
|
|
|
onSaved: (newValue) {}, |
|
|
|
onChanged: (value) { |
|
|
|
if (!Validators.stringNotNullOrEmpty( |
|
|
|
_quantityController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty( |
|
|
|
_howToUseController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty(value) && |
|
|
|
Get.find<ChangeSupply>().selectedSupplyId <= 0 && |
|
|
|
changeSelectedDevice.selectedDeviceId <= 0) { |
|
|
|
changeFormField.change(false); |
|
|
|
} else { |
|
|
|
changeFormField.change(true); |
|
|
|
} |
|
|
|
}, |
|
|
|
), |
|
|
|
Row( |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
flex: 2, |
|
|
|
child: Container( |
|
|
|
height: 82, |
|
|
|
child: _quantityField(), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox( |
|
|
|
width: 16.0, |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
flex: 1, |
|
|
|
child: Align( |
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
child: _dropdownUnitTypes(), |
|
|
|
)), |
|
|
|
]), |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Thiết bị", |
|
|
|
style: TextStyle(color: Colors.black54, fontSize: 13.0), |
|
|
|
SizedBox( |
|
|
|
width: 16.0, |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
flex: 1, |
|
|
|
child: Align( |
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
child: _dropdownUnitTypes(), |
|
|
|
)), |
|
|
|
]), |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Thiết bị", |
|
|
|
style: TextStyle(color: Colors.black54, fontSize: 13.0), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
_btnSelectDevice(), |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _howToUseController, |
|
|
|
decoration: InputDecoration(labelText: "Phương pháp sử dụng"), |
|
|
|
onSaved: (newValue) {}, |
|
|
|
onChanged: (value) { |
|
|
|
if (!Validators.stringNotNullOrEmpty( |
|
|
|
_quantityController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty(value) && |
|
|
|
!Validators.stringNotNullOrEmpty( |
|
|
|
_dosageController.text) && |
|
|
|
Get.find<ChangeSupply>().selectedSupplyId <= 0 && |
|
|
|
changeSelectedDevice.selectedDeviceId <= 0) { |
|
|
|
changeFormField.change(false); |
|
|
|
} else { |
|
|
|
changeFormField.change(true); |
|
|
|
} |
|
|
|
}, |
|
|
|
), |
|
|
|
_buttonInForm() |
|
|
|
], |
|
|
|
_btnSelectDevice(), |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _howToUseController, |
|
|
|
decoration: InputDecoration(labelText: "Phương pháp sử dụng"), |
|
|
|
onSaved: (newValue) {}, |
|
|
|
onChanged: (value) { |
|
|
|
if (!Validators.stringNotNullOrEmpty( |
|
|
|
_quantityController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty(value) && |
|
|
|
!Validators.stringNotNullOrEmpty( |
|
|
|
_dosageController.text) && |
|
|
|
Get.find<ChangeSupply>().selectedSupplyId <= 0 && |
|
|
|
changeSelectedDevice.selectedDeviceId <= 0) { |
|
|
|
changeFormField.change(false); |
|
|
|
} else { |
|
|
|
changeFormField.change(true); |
|
|
|
} |
|
|
|
}, |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
)); |
|
|
|
_buttonInForm() |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
_resetForm() { |
|
|
|
@@ -582,11 +587,17 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Column( |
|
|
|
children: [ |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_buildListSupply(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_formEdit() |
|
|
|
_formEdit(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
], |
|
|
|
); |
|
|
|
} |