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

ThousandsFormatter( ThousandsFormatter(
formatter: NumberFormat("#,###.####", "es"), allowFraction: true), formatter: NumberFormat("#,###.####", "es"), allowFraction: true),
], ],
decoration: InputDecoration(labelText: hintValue),
decoration: InputDecoration(
labelText: hintValue,
errorStyle: TextStyle(height: 0),
),
validator: validator ?? validator: validator ??
(String value) { (String value) {
return Validators.validNumberOrEmpty(value, label_invalid_number); return Validators.validNumberOrEmpty(value, label_invalid_number);

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

import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:farm_tpf/utils/formatter.dart'; import 'package:farm_tpf/utils/formatter.dart';
import 'package:intl/intl.dart';
import 'package:pattern_formatter/pattern_formatter.dart';


import '../util_action.dart'; import '../util_action.dart';


final changeButton = Get.put(ChangeButtonInForm()); final changeButton = Get.put(ChangeButtonInForm());
final changeSelectedDevice = Get.put(ChangeDevice()); final changeSelectedDevice = Get.put(ChangeDevice());
final changeFormField = Get.put(ChangeFieldFormSupply()); final changeFormField = Get.put(ChangeFieldFormSupply());
GlobalKey<FormState> _formSupplyKey = GlobalKey();


@override @override
void initState() { void initState() {
} }
}); });
}, },
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,
),
],
),
],
));
}));
}); });
} }


return WidgetTextFormFieldNumber( return WidgetTextFormFieldNumber(
hintValue: "Tổng lượng sử dụng *", hintValue: "Tổng lượng sử dụng *",
textController: _quantityController, textController: _quantityController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "");
},
onChanged: (value) { onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value) && if (!Validators.stringNotNullOrEmpty(value) &&
!Validators.stringNotNullOrEmpty(_howToUseController.text) && !Validators.stringNotNullOrEmpty(_howToUseController.text) &&
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)), borderRadius: new BorderRadius.circular(8.0)),
onPressed: () { 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( Utils.showSnackBarWarning(
message: "Vui lòng nhập vật tư và số lượng"); 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( child: Text(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)), borderRadius: new BorderRadius.circular(8.0)),
onPressed: () { 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( Utils.showSnackBarWarning(
message: "Vui lòng nhập vật tư và số lượng"); 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( child: Text(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
color: Colors.white, color: Colors.white,
border: Border.all(color: COLOR_CONST.DEFAULT)), 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

final changeButton = Get.put(ChangeButtonInForm()); final changeButton = Get.put(ChangeButtonInForm());
final changeSelectedDevice = Get.put(ChangeDevice()); final changeSelectedDevice = Get.put(ChangeDevice());
final changeFormField = Get.put(ChangeFieldFormSupply()); final changeFormField = Get.put(ChangeFieldFormSupply());
GlobalKey<FormState> _formSupplyKey = GlobalKey();


@override @override
void initState() { void initState() {
} }
}); });
}, },
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,
),
],
),
],
));
}));
}); });
} }


return WidgetTextFormFieldNumber( return WidgetTextFormFieldNumber(
hintValue: "Tổng lượng sử dụng *", hintValue: "Tổng lượng sử dụng *",
textController: _quantityController, textController: _quantityController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "");
},
onChanged: (value) { onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value) && if (!Validators.stringNotNullOrEmpty(value) &&
!Validators.stringNotNullOrEmpty(_howToUseController.text) && !Validators.stringNotNullOrEmpty(_howToUseController.text) &&
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)), borderRadius: new BorderRadius.circular(8.0)),
onPressed: () { 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( Utils.showSnackBarWarning(
message: "Vui lòng nhập vật tư và số lượng"); 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( child: Text(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)), borderRadius: new BorderRadius.circular(8.0)),
onPressed: () { 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( Utils.showSnackBarWarning(
message: "Vui lòng nhập vật tư và số lượng"); 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( child: Text(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
color: Colors.white, color: Colors.white,
border: Border.all(color: COLOR_CONST.DEFAULT)), 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

final changeButton = Get.put(ChangeButtonInForm()); final changeButton = Get.put(ChangeButtonInForm());
final changeSelectedDevice = Get.put(ChangeDevice()); final changeSelectedDevice = Get.put(ChangeDevice());
final changeFormField = Get.put(ChangeFieldFormSupply()); final changeFormField = Get.put(ChangeFieldFormSupply());
GlobalKey<FormState> _formSupplyKey = GlobalKey();


@override @override
void initState() { void initState() {
} }
}); });
}, },
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,
),
],
),
],
));
}));
}); });
} }


return WidgetTextFormFieldNumber( return WidgetTextFormFieldNumber(
hintValue: "Tổng lượng sử dụng *", hintValue: "Tổng lượng sử dụng *",
textController: _quantityController, textController: _quantityController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "");
},
onChanged: (value) { onChanged: (value) {
if (!Validators.stringNotNullOrEmpty(value) && if (!Validators.stringNotNullOrEmpty(value) &&
!Validators.stringNotNullOrEmpty(_howToUseController.text) && !Validators.stringNotNullOrEmpty(_howToUseController.text) &&
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)), borderRadius: new BorderRadius.circular(8.0)),
onPressed: () { 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( Utils.showSnackBarWarning(
message: "Vui lòng nhập vật tư và số lượng"); 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( child: Text(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)), borderRadius: new BorderRadius.circular(8.0)),
onPressed: () { 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( Utils.showSnackBarWarning(
message: "Vui lòng nhập vật tư và số lượng"); 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( child: Text(
} }


Widget _formEdit() { 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() { _resetForm() {

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

int selectedSupplyId; int selectedSupplyId;
String selectedSupplyName; String selectedSupplyName;
String unit; String unit;
bool isValid;


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


unit = unitName; unit = unitName;
update(); update();
} }

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

Loading…
Cancel
Save