add validation in faq and discount page

This commit is contained in:
sma
2024-03-01 17:04:51 +06:30
parent a81fca5070
commit 791f15f6d3
2 changed files with 70 additions and 36 deletions

View File

@@ -30,6 +30,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
bool _isNew = false;
String customerName = '';
String customerId = '';
final _discountFormKey = GlobalKey<FormState>();
@override
void initState() {
@@ -49,14 +50,30 @@ class _DiscountEditorState extends State<DiscountEditor> {
@override
Widget build(BuildContext context) {
final codeBox = InputText(
labelTextKey: 'discount.code',
iconData: FontAwesomeIcons.algolia,
controller: _codeController);
labelTextKey: 'discount.code',
iconData: FontAwesomeIcons.algolia,
controller: _codeController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
return "Please insert code";
}
return null;
},
);
final amountBox = InputText(
labelTextKey: 'discount.amount',
iconData: FontAwesomeIcons.moneyBill,
controller: _amountController);
labelTextKey: 'discount.amount',
iconData: FontAwesomeIcons.moneyBill,
controller: _amountController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
return "Please insert amount";
}
return null;
},
);
final statusBox = DisplayText(
text: _statusController.text,
@@ -100,39 +117,45 @@ class _DiscountEditorState extends State<DiscountEditor> {
onPressed: _delete)
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
codeBox,
amountBox,
SizedBox(height: 7),
customerBox,
SizedBox(height: 7),
widget.discount == null
? Container()
: Container(
padding: EdgeInsets.only(top: 5),
child: statusBox,
),
],
body: Form(
key: _discountFormKey,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
codeBox,
amountBox,
SizedBox(height: 7),
customerBox,
SizedBox(height: 7),
widget.discount == null
? Container()
: Container(
padding: EdgeInsets.only(top: 5),
child: statusBox,
),
],
),
),
),
fcsButton(context, getLocalString(context, "btn.save"),
callack: _save),
SizedBox(
height: 30,
)
],
fcsButton(context, getLocalString(context, "btn.save"),
callack: _save),
SizedBox(
height: 30,
)
],
),
),
)),
);
}
_save() async {
if (!_discountFormKey.currentState!.validate()) {
return null;
}
setState(() {
_isLoading = true;
});