checkout_form - Fixed error handling on forms
This commit is contained in:
parent
34f43c3124
commit
5994985801
1 changed files with 31 additions and 67 deletions
|
@ -16,79 +16,41 @@ final _formKey = GlobalKey<FormBuilderState>();
|
|||
|
||||
class _CheckoutFormState extends State<CheckoutForm> {
|
||||
Future submitForm(BuildContext context) async {
|
||||
if (_formKey.currentState!.fields["First Name"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["Last Name"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["Phone Number"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["Street Address"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["Street Address 2"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey
|
||||
.currentState!.fields["Region"]!.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["Province"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey
|
||||
.currentState!.fields["City"]!.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["District"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["Subdistrict"]!
|
||||
.value ==
|
||||
'' ||
|
||||
_formKey.currentState!.fields["Postal Code"]!
|
||||
.value ==
|
||||
'' ||
|
||||
!(_formKey.currentState!
|
||||
.fields["Shipping Method"]!.value ==
|
||||
'JNE' ||
|
||||
_formKey.currentState!
|
||||
.fields["Shipping Method"]!.value ==
|
||||
'JNT' ||
|
||||
_formKey.currentState!
|
||||
.fields["Shipping Method"]!.value ==
|
||||
if (_formKey.currentState!.fields["First Name"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Last Name"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Phone Number"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Street Address"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Street Address 2"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Region"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Province"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["City"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["District"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Subdistrict"]!.value.isEmpty ||
|
||||
_formKey.currentState!.fields["Postal Code"]!.value.isEmpty ||
|
||||
!(_formKey.currentState!.fields["Shipping Method"]!.value == 'JNE' ||
|
||||
_formKey.currentState!.fields["Shipping Method"]!.value == 'JNT' ||
|
||||
_formKey.currentState!.fields["Shipping Method"]!.value ==
|
||||
'SiCepat')) {
|
||||
showAlertDialog(context);
|
||||
return 400;
|
||||
return 999;
|
||||
} else {
|
||||
var currentCart = await viewCart();
|
||||
var cartData = jsonEncode(currentCart).toString();
|
||||
|
||||
Map<String, dynamic> data = {
|
||||
"firstName": _formKey
|
||||
.currentState!.fields["First Name"]!.value,
|
||||
"lastName": _formKey
|
||||
.currentState!.fields["Last Name"]!.value,
|
||||
"phoneNumber": _formKey
|
||||
.currentState!.fields["Phone Number"]!.value,
|
||||
"streetAddress1": _formKey.currentState!
|
||||
.fields["Street Address"]!.value,
|
||||
"streetAddress2": _formKey.currentState!
|
||||
.fields["Street Address 2"]!.value,
|
||||
"region": _formKey
|
||||
.currentState!.fields["Region"]!.value,
|
||||
"province": _formKey
|
||||
.currentState!.fields["Province"]!.value,
|
||||
"city":
|
||||
_formKey.currentState!.fields["City"]!.value,
|
||||
"district": _formKey
|
||||
.currentState!.fields["District"]!.value,
|
||||
"subDistrict": _formKey
|
||||
.currentState!.fields["Subdistrict"]!.value,
|
||||
"postalCode": _formKey
|
||||
.currentState!.fields["Postal Code"]!.value,
|
||||
"logistic": _formKey.currentState!
|
||||
.fields["Shipping Method"]!.value,
|
||||
"firstName": _formKey.currentState!.fields["First Name"]!.value,
|
||||
"lastName": _formKey.currentState!.fields["Last Name"]!.value,
|
||||
"phoneNumber": _formKey.currentState!.fields["Phone Number"]!.value,
|
||||
"streetAddress1":
|
||||
_formKey.currentState!.fields["Street Address"]!.value,
|
||||
"streetAddress2":
|
||||
_formKey.currentState!.fields["Street Address 2"]!.value,
|
||||
"region": _formKey.currentState!.fields["Region"]!.value,
|
||||
"province": _formKey.currentState!.fields["Province"]!.value,
|
||||
"city": _formKey.currentState!.fields["City"]!.value,
|
||||
"district": _formKey.currentState!.fields["District"]!.value,
|
||||
"subDistrict": _formKey.currentState!.fields["Subdistrict"]!.value,
|
||||
"postalCode": _formKey.currentState!.fields["Postal Code"]!.value,
|
||||
"logistic": _formKey.currentState!.fields["Shipping Method"]!.value,
|
||||
"data": cartData,
|
||||
};
|
||||
|
||||
|
@ -262,6 +224,8 @@ class _CheckoutFormState extends State<CheckoutForm> {
|
|||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const Payment()));
|
||||
} else if (statusCode == 999) {
|
||||
showAlertDialog(context);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue