add validation in deliveryaddress
This commit is contained in:
@@ -31,6 +31,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isNew = true;
|
||||
final _deliveryFormKey=GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -60,12 +61,26 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
final fullName = InputText(
|
||||
labelTextKey: 'delivery_address.full_name',
|
||||
iconData: MaterialCommunityIcons.account_arrow_left,
|
||||
controller: _nameController);
|
||||
controller: _nameController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if(value==null || value.isEmpty){
|
||||
return"Please enter full name";
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
final addressLine1 = InputText(
|
||||
labelTextKey: 'delivery_address.address_line1',
|
||||
iconData: Icons.location_on,
|
||||
controller: _address1Controller);
|
||||
controller: _address1Controller,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if(value==null || value.isEmpty){
|
||||
return"Please enter address";
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
final addressLine2 = InputText(
|
||||
labelTextKey: 'delivery_address.address_line2',
|
||||
@@ -75,18 +90,39 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
final cityBox = InputText(
|
||||
labelTextKey: 'delivery_address.city',
|
||||
iconData: Icons.location_city,
|
||||
controller: _cityController);
|
||||
controller: _cityController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if(value==null || value.isEmpty){
|
||||
return"Please enter city";
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
final regionBox = InputText(
|
||||
labelTextKey: 'delivery_address.state_region',
|
||||
iconData: Entypo.location,
|
||||
controller: _stateController);
|
||||
controller: _stateController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if(value==null || value.isEmpty){
|
||||
return"Please enter state/region";
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
final phoneNumberBox = InputText(
|
||||
labelTextKey: 'delivery_address.phonenumber',
|
||||
iconData: Icons.phone,
|
||||
textInputType: TextInputType.phone,
|
||||
controller: _phoneController);
|
||||
controller: _phoneController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if(value==null || value.isEmpty){
|
||||
return"Please enter phone number";
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
final createBtn = fcsButton(
|
||||
context,
|
||||
@@ -128,24 +164,27 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
onPressed: _delete)
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, right: 10),
|
||||
child: ListView(children: <Widget>[
|
||||
fullName,
|
||||
SizedBox(height: 5),
|
||||
phoneNumberBox,
|
||||
SizedBox(height: 10),
|
||||
addressLine1,
|
||||
SizedBox(height: 5),
|
||||
addressLine2,
|
||||
SizedBox(height: 5),
|
||||
cityBox,
|
||||
SizedBox(height: 5),
|
||||
regionBox,
|
||||
SizedBox(height: 5),
|
||||
_isNew ? createBtn : updateBtn,
|
||||
SizedBox(height: 10)
|
||||
]),
|
||||
body: Form(
|
||||
key: _deliveryFormKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, right: 10),
|
||||
child: ListView(children: <Widget>[
|
||||
fullName,
|
||||
SizedBox(height: 5),
|
||||
phoneNumberBox,
|
||||
SizedBox(height: 10),
|
||||
addressLine1,
|
||||
SizedBox(height: 5),
|
||||
addressLine2,
|
||||
SizedBox(height: 5),
|
||||
cityBox,
|
||||
SizedBox(height: 5),
|
||||
regionBox,
|
||||
SizedBox(height: 5),
|
||||
_isNew ? createBtn : updateBtn,
|
||||
SizedBox(height: 10)
|
||||
]),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
@@ -168,23 +207,26 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
}
|
||||
|
||||
Future<bool> _validate(DeliveryAddress deliveryAddress) async {
|
||||
if (deliveryAddress.addressLine1 == "") {
|
||||
await showMsgDialog(context, "Error", "Invalid address line 1!");
|
||||
if(_deliveryFormKey.currentState!.validate()){
|
||||
return false;
|
||||
}
|
||||
// if (deliveryAddress.addressLine1 == "") {
|
||||
// await showMsgDialog(context, "Error", "Invalid address line 1!");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if (deliveryAddress.city == null) {
|
||||
await showMsgDialog(context, "Error", "Invalid city!");
|
||||
return false;
|
||||
}
|
||||
if (deliveryAddress.state == null) {
|
||||
await showMsgDialog(context, "Error", "Invalid state!");
|
||||
return false;
|
||||
}
|
||||
if (deliveryAddress.phoneNumber == null) {
|
||||
await showMsgDialog(context, "Error", "Invalid phone number!");
|
||||
return false;
|
||||
}
|
||||
// if (deliveryAddress.city == null) {
|
||||
// await showMsgDialog(context, "Error", "Invalid city!");
|
||||
// return false;
|
||||
// }
|
||||
// if (deliveryAddress.state == null) {
|
||||
// await showMsgDialog(context, "Error", "Invalid state!");
|
||||
// return false;
|
||||
// }
|
||||
// if (deliveryAddress.phoneNumber == null) {
|
||||
// await showMsgDialog(context, "Error", "Invalid phone number!");
|
||||
// return false;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -194,6 +236,7 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (widget.user != null) {
|
||||
deliveryAddress.userID = widget.user!.id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user