add validation in input form field
This commit is contained in:
@@ -24,6 +24,7 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
bool _isLoading = false;
|
||||
late CargoType _cargo;
|
||||
bool _isNew = false;
|
||||
final _cargoFormKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -47,11 +48,26 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
final typeBox = InputText(
|
||||
labelTextKey: 'cargo.type',
|
||||
iconData: Icons.text_format,
|
||||
controller: _descController);
|
||||
controller: _descController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value){
|
||||
if(value==null || value.isEmpty){
|
||||
return "Please insert cargo type";
|
||||
}
|
||||
return null;
|
||||
},);
|
||||
final rateBox = InputText(
|
||||
labelTextKey: 'cargo.rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _rateController);
|
||||
labelTextKey: 'cargo.rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _rateController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert rate";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
@@ -78,23 +94,26 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
typeBox,
|
||||
rateBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
body: Form(
|
||||
key: _cargoFormKey,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
typeBox,
|
||||
rateBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -102,8 +121,7 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
if (_rateController.text == "") {
|
||||
showMsgDialog(context, "Error", "Please insert rate");
|
||||
if (!_cargoFormKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
|
||||
@@ -26,6 +26,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
bool _isLoading = false;
|
||||
CargoType _custom = new CargoType();
|
||||
bool _isNew = false;
|
||||
final _customFormKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -50,16 +51,39 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
final productBox = InputText(
|
||||
labelTextKey: 'rate.cutom.product_type',
|
||||
iconData: FontAwesomeIcons.weightHanging,
|
||||
controller: _productController);
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
controller: _productController,
|
||||
validator: (value){
|
||||
if(value==null || value.isEmpty){
|
||||
return "Please insert product type";
|
||||
}
|
||||
return null;
|
||||
},);
|
||||
final feeBox = InputText(
|
||||
labelTextKey: 'rate.custom.fee',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _feeController);
|
||||
labelTextKey: 'rate.custom.fee',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _feeController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert fee";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final shipmentRateBox = InputText(
|
||||
labelTextKey: 'rate.custom.shipment_rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _shipmentRateController);
|
||||
labelTextKey: 'rate.custom.shipment_rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _shipmentRateController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert shipment rate";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
@@ -86,24 +110,27 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
productBox,
|
||||
feeBox,
|
||||
shipmentRateBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
body: Form(
|
||||
key: _customFormKey,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
productBox,
|
||||
feeBox,
|
||||
shipmentRateBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -111,13 +138,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
if (_feeController.text == "") {
|
||||
showMsgDialog(context, "Error", "Please insert fee");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_shipmentRateController.text == "") {
|
||||
showMsgDialog(context, "Error", "Please insert shipment rate");
|
||||
if (!_customFormKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
bool _isLoading = false;
|
||||
bool _isNew = false;
|
||||
DiscountByWeight _discountByWeight = new DiscountByWeight();
|
||||
final _discountFormKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -46,13 +47,29 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final weightBox = InputText(
|
||||
labelTextKey: 'rate.discount.weight',
|
||||
iconData: FontAwesomeIcons.weightHanging,
|
||||
controller: _weightController);
|
||||
labelTextKey: 'rate.discount.weight',
|
||||
iconData: FontAwesomeIcons.weightHanging,
|
||||
controller: _weightController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please inset weight";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
final discountRateBox = InputText(
|
||||
labelTextKey: 'rate.discount.rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _discountController);
|
||||
labelTextKey: 'rate.discount.rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _discountController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert discount rate";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -80,23 +97,26 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
weightBox,
|
||||
discountRateBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
body: Form(
|
||||
key: _discountFormKey,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
weightBox,
|
||||
discountRateBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -104,13 +124,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
if (_weightController.text == "") {
|
||||
showMsgDialog(context, "Error", "Please insert weight");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_discountController.text == "") {
|
||||
showMsgDialog(context, "Error", "Please insert discount rate");
|
||||
if (!_discountFormKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user