Browse Source

fix Bug #7893

master
daivph 5 years ago
parent
commit
3bc540ccb6
5 changed files with 638 additions and 479 deletions
  1. +4
    -1
      lib/presentation/custom_widgets/widget_text_form_field.dart
  2. +207
    -158
      lib/presentation/screens/actions/dung/widget_dung_supply.dart
  3. +206
    -156
      lib/presentation/screens/actions/harvest_process/widget_harvest_process_supply.dart
  4. +214
    -164
      lib/presentation/screens/actions/spraying/widget_spraying_supply.dart
  5. +7
    -0
      lib/presentation/screens/actions/state_management_helper/change_supply.dart

+ 4
- 1
lib/presentation/custom_widgets/widget_text_form_field.dart View File

@@ -27,7 +27,10 @@ class WidgetTextFormFieldNumber extends StatelessWidget {
ThousandsFormatter(
formatter: NumberFormat("#,###.####", "es"), allowFraction: true),
],
decoration: InputDecoration(labelText: hintValue),
decoration: InputDecoration(
labelText: hintValue,
errorStyle: TextStyle(height: 0),
),
validator: validator ??
(String value) {
return Validators.validNumberOrEmpty(value, label_invalid_number);

+ 207
- 158
lib/presentation/screens/actions/dung/widget_dung_supply.dart View File

@@ -18,8 +18,6 @@ import 'package:farm_tpf/utils/validators.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:farm_tpf/utils/formatter.dart';
import 'package:intl/intl.dart';
import 'package:pattern_formatter/pattern_formatter.dart';

import '../util_action.dart';

@@ -41,6 +39,7 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> {
final changeButton = Get.put(ChangeButtonInForm());
final changeSelectedDevice = Get.put(ChangeDevice());
final changeFormField = Get.put(ChangeFieldFormSupply());
GlobalKey<FormState> _formSupplyKey = GlobalKey();

@override
void initState() {
@@ -194,27 +193,44 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> {
}
});
},
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 ??
"Tên thương mại",
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 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(
'Tên thương mại *',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.normal,
color: isValid ? Colors.black54 : Colors.red[600]),
),
Row(
children: [
Expanded(
child: Text(
changeSelectedSupply.selectedSupplyName ??
"Tên thương mại",
style: TextStyle(
fontSize: 14.0, color: Colors.black87))),
Icon(
Icons.arrow_drop_down,
color: Colors.grey,
),
],
),
],
));
}));
});
}

@@ -296,6 +312,9 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> {
return WidgetTextFormFieldNumber(
hintValue: "Tổng lượng sử dụng *",
textController: _quantityController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "");
},
onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value) &&
!Validators.stringNotNullOrEmpty(_howToUseController.text) &&
@@ -334,38 +353,54 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> {
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
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)) {
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 {
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(
@@ -377,37 +412,54 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> {
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
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)) {
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 {
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(
@@ -428,85 +480,82 @@ class _WidgetDungSupplyState extends State<WidgetDungSupply> {
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border.all(color: COLOR_CONST.DEFAULT)),
child: Column(
children: [
Container(
width: double.infinity,
child: Text(
"Tên thương mại *",
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 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);
}
},
),
),
_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(),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Container(
height: 70,
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()
],
),
));
}


+ 206
- 156
lib/presentation/screens/actions/harvest_process/widget_harvest_process_supply.dart View File

@@ -42,6 +42,7 @@ class _WidgetHarvestProcessSupplyState
final changeButton = Get.put(ChangeButtonInForm());
final changeSelectedDevice = Get.put(ChangeDevice());
final changeFormField = Get.put(ChangeFieldFormSupply());
GlobalKey<FormState> _formSupplyKey = GlobalKey();

@override
void initState() {
@@ -194,27 +195,44 @@ class _WidgetHarvestProcessSupplyState
}
});
},
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 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,
),
],
),
],
));
}));
});
}

@@ -296,6 +314,9 @@ class _WidgetHarvestProcessSupplyState
return WidgetTextFormFieldNumber(
hintValue: "Tổng lượng sử dụng *",
textController: _quantityController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "");
},
onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value) &&
!Validators.stringNotNullOrEmpty(_howToUseController.text) &&
@@ -334,38 +355,54 @@ class _WidgetHarvestProcessSupplyState
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
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)) {
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 {
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(
@@ -377,37 +414,53 @@ class _WidgetHarvestProcessSupplyState
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
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)) {
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 {
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(
@@ -428,85 +481,82 @@ class _WidgetHarvestProcessSupplyState
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border.all(color: COLOR_CONST.DEFAULT)),
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 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);
}
},
),
),
_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(),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Container(
height: 70,
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()
],
),
));
}


+ 214
- 164
lib/presentation/screens/actions/spraying/widget_spraying_supply.dart View File

@@ -40,6 +40,7 @@ class _WidgetSprayingSupplyState extends State<WidgetSprayingSupply> {
final changeButton = Get.put(ChangeButtonInForm());
final changeSelectedDevice = Get.put(ChangeDevice());
final changeFormField = Get.put(ChangeFieldFormSupply());
GlobalKey<FormState> _formSupplyKey = GlobalKey();

@override
void initState() {
@@ -192,27 +193,44 @@ class _WidgetSprayingSupplyState extends State<WidgetSprayingSupply> {
}
});
},
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 ??
"Tên thương mại",
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 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(
'Tên thương mại *',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.normal,
color: isValid ? Colors.black54 : Colors.red[600]),
),
Row(
children: [
Expanded(
child: Text(
changeSelectedSupply.selectedSupplyName ??
"Tên thương mại",
style: TextStyle(
fontSize: 14.0, color: Colors.black87))),
Icon(
Icons.arrow_drop_down,
color: Colors.grey,
),
],
),
],
));
}));
});
}

@@ -294,6 +312,9 @@ class _WidgetSprayingSupplyState extends State<WidgetSprayingSupply> {
return WidgetTextFormFieldNumber(
hintValue: "Tổng lượng sử dụng *",
textController: _quantityController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "");
},
onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value) &&
!Validators.stringNotNullOrEmpty(_howToUseController.text) &&
@@ -332,38 +353,54 @@ class _WidgetSprayingSupplyState extends State<WidgetSprayingSupply> {
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
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)) {
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 {
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(
@@ -375,37 +412,53 @@ class _WidgetSprayingSupplyState extends State<WidgetSprayingSupply> {
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
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)) {
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 {
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(
@@ -419,93 +472,90 @@ class _WidgetSprayingSupplyState extends State<WidgetSprayingSupply> {
}

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: COLOR_CONST.DEFAULT)),
child: Column(
children: [
Container(
width: double.infinity,
child: Text(
"Tên thương mại *",
style: TextStyle(color: Colors.black54, fontSize: 13.0),
return Form(
key: _formSupplyKey,
child: Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border.all(color: COLOR_CONST.DEFAULT)),
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);
}
},
),
),
_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(),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Container(
height: 70,
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() {

+ 7
- 0
lib/presentation/screens/actions/state_management_helper/change_supply.dart View File

@@ -6,12 +6,14 @@ class ChangeSupply extends GetxController {
int selectedSupplyId;
String selectedSupplyName;
String unit;
bool isValid;

void initValue() {
currentSupply = Supply();
selectedSupplyName = "";
selectedSupplyId = -1;
unit = "";
isValid = true;
update();
}

@@ -29,4 +31,9 @@ class ChangeSupply extends GetxController {
unit = unitName;
update();
}

void changeValid(bool valid) {
isValid = valid;
update();
}
}

Loading…
Cancel
Save