From 59949858012665eeeb29a181ca4a97fd3e084eac Mon Sep 17 00:00:00 2001 From: Matthew Patrick Date: Thu, 12 May 2022 11:03:12 +0700 Subject: [PATCH] checkout_form - Fixed error handling on forms --- lib/components/checkout_form.dart | 98 ++++++++++--------------------- 1 file changed, 31 insertions(+), 67 deletions(-) diff --git a/lib/components/checkout_form.dart b/lib/components/checkout_form.dart index 5601ff4..bea550b 100644 --- a/lib/components/checkout_form.dart +++ b/lib/components/checkout_form.dart @@ -16,79 +16,41 @@ final _formKey = GlobalKey(); class _CheckoutFormState extends State { 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 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 { context, MaterialPageRoute( builder: (context) => const Payment())); + } else if (statusCode == 999) { + showAlertDialog(context); } }); },