|
|
|
@@ -1,6 +1,8 @@ |
|
|
|
import 'package:farm_tpf/custom_model/SuppliesUsing.dart'; |
|
|
|
import 'package:farm_tpf/custom_model/Supply.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/WidgetErrorTextField.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_text_form_field.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/controller/ChangeFieldInForm.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/controller/ChangeFormButton.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/controller/ChangeSupplyUsing.dart'; |
|
|
|
@@ -10,6 +12,7 @@ import 'package:farm_tpf/presentation/screens/actions/util_action.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/resources/sc_resource_helper.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_common.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_string.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_style.dart'; |
|
|
|
import 'package:farm_tpf/utils/validators.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
@@ -32,6 +35,7 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { |
|
|
|
final changeUnit = Get.put(ChangeUnit()); |
|
|
|
final changeButton = Get.put(ChangeButtonInForm()); |
|
|
|
final changeFormField = Get.put(ChangeFieldFormSupply()); |
|
|
|
GlobalKey<FormState> _formSupplyKey = GlobalKey(); |
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
@@ -137,6 +141,7 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { |
|
|
|
|
|
|
|
Widget _btnSelectSubstrates() { |
|
|
|
return GetBuilder<ChangeSupply>(builder: (data) { |
|
|
|
var isValid = changeSelectedSupply.isValid; |
|
|
|
return FlatButton( |
|
|
|
padding: |
|
|
|
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), |
|
|
|
@@ -164,27 +169,52 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
child: Container( |
|
|
|
padding: EdgeInsets.only( |
|
|
|
top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
border: kBorderTextField, |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
GetBuilder<ChangeSupply>( |
|
|
|
builder: (_) => Expanded( |
|
|
|
child: Text( |
|
|
|
changeSelectedSupply.selectedSupplyName ?? |
|
|
|
"Hoá chất xử lý", |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 14.0, color: Colors.black87)))), |
|
|
|
Icon( |
|
|
|
Icons.arrow_drop_down, |
|
|
|
color: Colors.grey, |
|
|
|
), |
|
|
|
], |
|
|
|
))); |
|
|
|
child: GetBuilder<ChangeSupply>(builder: (_) { |
|
|
|
var isValid = changeSelectedSupply.isValid; |
|
|
|
return Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.only( |
|
|
|
top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
border: Border( |
|
|
|
bottom: BorderSide( |
|
|
|
width: 1, |
|
|
|
color: isValid ? Colors.grey : Colors.red[900])), |
|
|
|
), |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
'Hoá chất xử lý *', |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 13, |
|
|
|
fontWeight: FontWeight.normal, |
|
|
|
color: |
|
|
|
isValid ? Colors.black54 : Colors.red[600]), |
|
|
|
), |
|
|
|
Row( |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
changeSelectedSupply.selectedSupplyName ?? |
|
|
|
"Hoá chất xử lý", |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 14.0, |
|
|
|
color: Colors.black87))), |
|
|
|
Icon( |
|
|
|
Icons.arrow_drop_down, |
|
|
|
color: Colors.grey, |
|
|
|
), |
|
|
|
], |
|
|
|
) |
|
|
|
], |
|
|
|
)), |
|
|
|
isValid ? SizedBox() : WidgetErrorTextField() |
|
|
|
], |
|
|
|
); |
|
|
|
})); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -221,8 +251,12 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { |
|
|
|
|
|
|
|
_quantityField() { |
|
|
|
return WidgetTextFormFieldNumber( |
|
|
|
hintValue: "Tổng lượng sử dụng", |
|
|
|
hintValue: "Tổng lượng sử dụng *", |
|
|
|
textController: _quantityController, |
|
|
|
validator: (String value) { |
|
|
|
return Validators.validateNotNullOrEmpty( |
|
|
|
value, label_validate_input_empty); |
|
|
|
}, |
|
|
|
onChanged: (value) { |
|
|
|
if (!Validators.stringNotNullOrEmpty(value) && |
|
|
|
!Validators.stringNotNullOrEmpty(_dosageController.text) && |
|
|
|
@@ -255,27 +289,44 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { |
|
|
|
? Expanded( |
|
|
|
child: FlatButton( |
|
|
|
onPressed: () { |
|
|
|
var currentSupply = changeSelectedSupply.currentSupply; |
|
|
|
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 |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.editSupply( |
|
|
|
changeSupplyUsing.currentIndex, newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
if (_formSupplyKey.currentState.validate()) { |
|
|
|
_formSupplyKey.currentState.save(); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
var currentSupply = |
|
|
|
changeSelectedSupply.currentSupply; |
|
|
|
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 |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.editSupply( |
|
|
|
changeSupplyUsing.currentIndex, newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
} |
|
|
|
} else { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập hoá chất và số lượng"); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
@@ -286,26 +337,44 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { |
|
|
|
: Expanded( |
|
|
|
child: FlatButton( |
|
|
|
onPressed: () { |
|
|
|
var currentSupply = changeSelectedSupply.currentSupply; |
|
|
|
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 |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.addSupply(newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
if (_formSupplyKey.currentState.validate()) { |
|
|
|
_formSupplyKey.currentState.save(); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
var currentSupply = |
|
|
|
changeSelectedSupply.currentSupply; |
|
|
|
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 |
|
|
|
..tbSuppliesInWarehouseId = currentSupply.id |
|
|
|
..suppliesInWarehouseId = currentSupply.id |
|
|
|
..supplyName = currentSupply.tbSuppliesName |
|
|
|
..supplyUnit = currentSupply.unit |
|
|
|
..unit = currentSupply.unit; |
|
|
|
changeSupplyUsing.addSupply(newSup); |
|
|
|
_resetForm(); |
|
|
|
_hidenKeyboard(context); |
|
|
|
} |
|
|
|
} else { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: "Vui lòng nhập hoá chất và số lượng"); |
|
|
|
if (changeSelectedSupply.selectedSupplyId <= 0) { |
|
|
|
changeSelectedSupply.changeValid(false); |
|
|
|
} else { |
|
|
|
changeSelectedSupply.changeValid(true); |
|
|
|
} |
|
|
|
// |
|
|
|
} |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
@@ -327,56 +396,52 @@ class _WidgetPlantSupplyState extends State<WidgetPlantSupply> { |
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
|
color: Colors.white, |
|
|
|
border: Border.all(color: Colors.grey[300])), |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Hoá chất xử lý", |
|
|
|
style: TextStyle(color: Colors.black54, fontSize: 13.0), |
|
|
|
child: Form( |
|
|
|
key: _formSupplyKey, |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
_btnSelectSubstrates(), |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _dosageController, |
|
|
|
decoration: InputDecoration(labelText: "Liều lượng"), |
|
|
|
onSaved: (newValue) {}, |
|
|
|
onChanged: (value) { |
|
|
|
if (!Validators.stringNotNullOrEmpty( |
|
|
|
_quantityController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty(value) && |
|
|
|
Get.find<ChangeSupply>().selectedSupplyId <= 0) { |
|
|
|
changeFormField.change(false); |
|
|
|
} else { |
|
|
|
changeFormField.change(true); |
|
|
|
} |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
_btnSelectSubstrates(), |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _dosageController, |
|
|
|
decoration: InputDecoration(labelText: "Liều lượng"), |
|
|
|
onSaved: (newValue) {}, |
|
|
|
onChanged: (value) { |
|
|
|
if (!Validators.stringNotNullOrEmpty( |
|
|
|
_quantityController.text) && |
|
|
|
!Validators.stringNotNullOrEmpty(value) && |
|
|
|
Get.find<ChangeSupply>().selectedSupplyId <= 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(), |
|
|
|
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(), |
|
|
|
)), |
|
|
|
]), |
|
|
|
_buttonInForm() |
|
|
|
], |
|
|
|
SizedBox( |
|
|
|
width: 16.0, |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
flex: 1, |
|
|
|
child: Align( |
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
child: _dropdownUnitTypes(), |
|
|
|
)), |
|
|
|
]), |
|
|
|
_buttonInForm() |
|
|
|
], |
|
|
|
), |
|
|
|
)); |
|
|
|
} |
|
|
|
|