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