This commit is contained in:
2026-07-12 04:33:48 +08:00
parent f8a90ad305
commit e7ce0f7bae
151 changed files with 2765 additions and 2947 deletions

View File

@@ -32,10 +32,9 @@ import '../../utils/utils.dart';
import '../../widgets/general/sliding_up_panel.dart';
class MobileCheckout extends StatefulWidget {
final Key key;
final int businessId;
const MobileCheckout(this.businessId, {this.key,}) : super(key: key);
const MobileCheckout(this.businessId, {Key? key,}) : super(key: key);
@override
State<StatefulWidget> createState() {
@@ -45,17 +44,17 @@ class MobileCheckout extends StatefulWidget {
}
class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
CartInfo cartInfo;
Address shipAddress;
bool canSubmit;
List<ErrorMessage> errorMessages;
List<BookingTime> bookingTimeList;
List<BookingDateTime> bookingDateTimeList;
List<PaymentPlatform> paymentPlatforms;
TextValue durationInTraffic;
int selectedCoupon;
CartInfo? cartInfo;
Address? shipAddress;
bool canSubmit = false;
List<ErrorMessage>? errorMessages;
List<BookingTime>? bookingTimeList;
List<BookingDateTime>? bookingDateTimeList;
List<PaymentPlatform>? paymentPlatforms;
TextValue? durationInTraffic;
int? selectedCoupon;
double couponDiscountAmount = 0;
List<Coupon> coupons;
List<Coupon>? coupons;
int peopleCount = 2;
@@ -63,25 +62,25 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
String orderRemark = '';
int deliveryMethodIndex = 0;
String deliveryMethod;
String? deliveryMethod;
List<ShippingRate> shippingRates = [];
ShippingRate selectedShippingRate;
ShippingRate? selectedShippingRate;
List<String> shippingMethodLabels = [];
List<IconData> shippingMethodIcons = [];
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
int bookingDateIndex;
int bookingTimeIndex;
int paymentPlatformIndex;
int? bookingDateIndex;
int? bookingTimeIndex;
int? paymentPlatformIndex;
GlobalKey slidingUpPanelKey = GlobalKey();
SlidingUpPanel slidingUpPanel;
SlidingUpPanel? slidingUpPanel;
PanelController panelController = PanelController();
Widget panel;
Widget? panel;
double subtotal;
double? subtotal;
TextEditingController newCouponController = TextEditingController();
@@ -102,7 +101,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
);
}
if (cartInfo.businessInfo.deliveryPickup == false && cartInfo.businessInfo.deliveryCanadaPost == false && cartInfo.businessInfo.deliveryStoreDelivery == false) {
if (cartInfo!.businessInfo?.deliveryPickup == false && cartInfo!.businessInfo?.deliveryCanadaPost == false && cartInfo!.businessInfo?.deliveryStoreDelivery == false) {
return Scaffold(
body: Container(
child: Center(
@@ -114,7 +113,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).primaryColor,
backgroundColor: Theme.of(context).primaryColor,
),
child: Text(
S.of(context).ok,
@@ -134,10 +133,10 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
}
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if(errorMessages.length > 0) {
if(errorMessages != null && errorMessages!.length > 0) {
print('error: ${errorMessages.toString()}');
// _scaffoldKey.currentState.showSnackBar(errorSnackBar(errorMessages));
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(errorMessages));
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(errorMessages!));
}
});
@@ -169,7 +168,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
centerTitle: true,
),
body: WillPopScope(
child: slidingUpPanel,
child: slidingUpPanel!,
onWillPop: () async {
if (panelController != null && panelController.isPanelOpen) {
panelController.close();
@@ -197,13 +196,13 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'\$${(cartInfo.totalPrice - couponDiscountAmount).toStringAsFixed(2)}',
'\$${(cartInfo!.totalPrice! - couponDiscountAmount).toStringAsFixed(2)}',
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
cartInfo.businessInfo.isPublic ? SizedBox.shrink() : Container(
cartInfo!.businessInfo!.isPublic ? SizedBox.shrink() : Container(
padding: EdgeInsets.only(top: 2.0, bottom: 2.0, left: 5.0, right: 5.0),
width: 100.0,
color: Colors.red,
@@ -267,7 +266,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
itemCount: 6,
addAutomaticKeepAlives: true,
itemBuilder: (BuildContext context, int position) {
var deliveryTimeInSeconds = cartInfo.businessInfo.shippingTime * 60 + (durationInTraffic != null ? durationInTraffic.value : 0);
var deliveryTimeInSeconds = cartInfo!.businessInfo!.shippingTime * 60 + (durationInTraffic != null ? durationInTraffic!.value : 0);
print('aaa: $deliveryTimeInSeconds');
DateTime now = DateTime.now();
var formatter = DateFormat('H:mm');
@@ -281,7 +280,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
mainAxisSize: MainAxisSize.min,
children: [
Text(
S.of(context).table_token(store.state.tableNumber),
S.of(context).table_token(store.state.tableNumber!),
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
@@ -308,7 +307,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
onChanged: (newValue) {
if (mounted) {
setState(() {
peopleCount = newValue;
peopleCount = newValue!;
});
}
},
@@ -333,7 +332,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
icons: shippingMethodIcons,
onToggle: (index) {
selectedShippingRate = null;
deliveryMethod = getShippingMethod(index);
deliveryMethod = getShippingMethod(index!);
check();
},
initialLabelIndex: deliveryMethodIndex,
@@ -341,7 +340,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
);
switch (position) {
case 0:
if (cartInfo.businessInfo.deliveryPickup) {
if (cartInfo!.businessInfo!.deliveryPickup) {
return Container(
padding: EdgeInsets.only(
top: 16.0, bottom: 16.0, left: 16.0, right: 16.0),
@@ -355,8 +354,8 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
child: Container(
alignment: Alignment.centerLeft,
child: store.state.deviceId != null && store.state.deviceId.isNotEmpty ? (
store.state.tableNumber != null && store.state.tableNumber.isNotEmpty ?
child: store.state.deviceId != null && store.state.deviceId!.isNotEmpty ? (
store.state.tableNumber != null && store.state.tableNumber!.isNotEmpty ?
peopleCountSelection :
SizedBox.shrink()
) : Center(child: toggleSwitch,),
@@ -369,8 +368,8 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
}
break;
case 1:
if (store.state.deviceId != null && store.state.deviceId.isNotEmpty ||
store.state.tableNumber != null && store.state.tableNumber.isNotEmpty) {
if (store.state.deviceId != null && store.state.deviceId!.isNotEmpty ||
store.state.tableNumber != null && store.state.tableNumber!.isNotEmpty) {
return SizedBox.shrink();
}
if (deliveryMethod == 'pickup') {
@@ -389,7 +388,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Container(
margin: EdgeInsets.only(top: 10.0),
child: Text(
cartInfo.businessInfo.name,
cartInfo!.businessInfo!.name,
style: TextStyle(
fontSize: 17.0,
),
@@ -398,7 +397,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Container(
margin: EdgeInsets.only(top: 5.0),
child: Text(
cartInfo.businessInfo.address.addressLine1,
'${cartInfo!.businessInfo?.address.addressLine1}',
style: TextStyle(
fontSize: 14.0,
color: Colors.black45,
@@ -406,9 +405,9 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
),
Container(
child: cartInfo.businessInfo.address.addressLine2 != null
&& cartInfo.businessInfo.address.addressLine2.length > 0 ?
Text(cartInfo.businessInfo.address.addressLine2,
child: cartInfo!.businessInfo?.address.addressLine2 != null
&& cartInfo!.businessInfo!.address.addressLine2!.length > 0 ?
Text('${cartInfo!.businessInfo!.address.addressLine2}',
style: TextStyle(
fontSize: 14.0,
color: Colors.black45,
@@ -417,7 +416,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
Container(
child: Text(
'${cartInfo.businessInfo.address.city}, ${cartInfo.businessInfo.address.state}, ${cartInfo.businessInfo.address.zip}',
'${cartInfo!.businessInfo?.address.city}, ${cartInfo!.businessInfo?.address.state}, ${cartInfo!.businessInfo?.address.zip}',
style: TextStyle(
fontSize: 14.0,
color: Colors.black45,
@@ -427,7 +426,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Container(
margin: EdgeInsets.only(top: 5.0),
child: Text(
'Tel: ${cartInfo.businessInfo.phone}',
'Tel: ${cartInfo!.businessInfo?.phone}',
style: TextStyle(
fontSize: 15.0,
color: Colors.black54,
@@ -469,7 +468,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
children: <Widget>[
Container(
child: Text(
shipAddress != null ? shipAddress.fullAddress : S.of(context).enter_delivery_address,
shipAddress != null ? shipAddress!.fullAddress! : S.of(context).enter_delivery_address,
style: TextStyle(
fontSize: 16.0
),
@@ -480,7 +479,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Container(
padding: EdgeInsets.only(top: 6.0),
child: Text(
shipAddress != null ? shipAddress.contactName + ' ' + shipAddress.phone : '',
shipAddress != null ? shipAddress!.contactName! + ' ' + shipAddress!.phone! : '',
style: TextStyle(
fontSize: 14.0,
color: Colors.black38,
@@ -504,13 +503,13 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
),
onTap: () {
Routes.router.navigateTo(context, '/my-addresses/${cartInfo.businessInfo.id}', replace: true);
Routes.router.navigateTo(context, '/my-addresses/${cartInfo!.businessInfo?.id}', replace: true);
},
);
break;
case 2:
if (deliveryMethod == 'pickup' || store.state.deviceId != null && store.state.deviceId.isNotEmpty ||
store.state.tableNumber != null && store.state.tableNumber.isNotEmpty) {
if (deliveryMethod == 'pickup' || store.state.deviceId != null && store.state.deviceId!.isNotEmpty ||
store.state.tableNumber != null && store.state.tableNumber!.isNotEmpty) {
return SizedBox.shrink();
}
if (deliveryMethod == 'canada-post') {
@@ -553,7 +552,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
alignment: Alignment.centerRight,
child: Text(
selectedShippingRate != null ?
'${selectedShippingRate.name} \$${selectedShippingRate.price.toStringAsFixed(2)}' :
'${selectedShippingRate?.name} \$${selectedShippingRate?.price.toStringAsFixed(2)}' :
S.of(context).please_select,
style: TextStyle(
fontSize: 15.0,
@@ -583,7 +582,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
},
);
}
if (!cartInfo.businessInfo.instanceDelivery) {
if (!cartInfo!.businessInfo!.instanceDelivery) {
return Container(
padding: EdgeInsets.only(left: 16.0, right: 16.0, top: 0.0, bottom: 16.0),
child: Text(S.of(context).no_instance_delivery_desc),
@@ -613,7 +612,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
children: <Widget>[
Container(
child: Text(
bookingTimeList.length > 0 || bookingDateTimeList.length > 0 ? S.of(context).delivery_now : S.of(context).delivery_unavailable,
bookingTimeList!.length > 0 || bookingDateTimeList!.length > 0 ? S.of(context).delivery_now : S.of(context).delivery_unavailable,
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.bold,
@@ -627,9 +626,9 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
children: <Widget>[
Container(
child: Text(
bookingTimeList.length > 0 ? '${Utils.timestampToString(context, bookingTimeList[bookingTimeIndex].unixTime)}'
: ((bookingTimeList.length == 0 && bookingDateTimeList.length == 0) ? ''
: bookingDateTimeList[bookingDateIndex].viewDate + ' ' + (bookingDateTimeList[bookingDateIndex].bookTimes.length > 0 ? bookingDateTimeList[bookingDateIndex].bookTimes[bookingTimeIndex].viewTime : '')),
bookingTimeList!.length > 0 ? '${Utils.timestampToString(context, bookingTimeList![bookingTimeIndex!].unixTime)}'
: ((bookingTimeList!.length == 0 && bookingDateTimeList!.length == 0) ? ''
: bookingDateTimeList![bookingDateIndex!].viewDate + ' ' + (bookingDateTimeList![bookingDateIndex!].bookTimes.length > 0 ? bookingDateTimeList![bookingDateIndex!].bookTimes[bookingTimeIndex!].viewTime : '')),
),
),
Container(
@@ -681,7 +680,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
children: <Widget>[
Container(
child: Text(
paymentPlatforms.length == 0 ? S.of(context).pay_on_deliery : PaymentPlatform.getPaymentPlatformName(context, paymentPlatforms[paymentPlatformIndex].code),
paymentPlatforms!.length == 0 ? S.of(context).pay_on_deliery : PaymentPlatform.getPaymentPlatformName(context, paymentPlatforms![paymentPlatformIndex!].code!),
),
),
Container(
@@ -712,7 +711,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
width: double.infinity,
padding: EdgeInsets.only(bottom: 10.0),
child: Text(
cartInfo.businessInfo.name,
'${cartInfo!.businessInfo?.name}',
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16.0,
@@ -731,9 +730,9 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
subtotal = 0.0;
for (var i = 0; i < cartInfo.productList.length; i++) {
subtotal += cartInfo.productList[i].totalPrice;
column.children.add(lineItem(cartInfo.productList[i]));
for (var i = 0; i < cartInfo!.productList!.length; i++) {
subtotal = subtotal! + cartInfo!.productList![i].totalPrice!;
column.children.add(lineItem(cartInfo!.productList![i]));
}
column.children.add(GestureDetector(
child: Container(
@@ -815,7 +814,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
width: 100.0,
alignment: Alignment.centerRight,
child: Text(
'${(subtotal - couponDiscountAmount).toStringAsFixed(2)}',
'${(subtotal! - couponDiscountAmount).toStringAsFixed(2)}',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
@@ -826,8 +825,8 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
));
if (cartInfo.extraFeeList.length > 0) {
for (var i = 0; i < cartInfo.extraFeeList.length; i++) {
if (cartInfo!.extraFeeList!.length > 0) {
for (var i = 0; i < cartInfo!.extraFeeList!.length; i++) {
column.children.add(Container(
padding: EdgeInsets.only(bottom: 16.0),
alignment: Alignment.centerRight,
@@ -838,7 +837,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Container(
alignment: Alignment.centerRight,
child: Text(
S.of(context).extra_fee_token(cartInfo.extraFeeList[i].name, cartInfo.extraFeeList[i].rate),
S.of(context).extra_fee_token(cartInfo!.extraFeeList![i].name, cartInfo!.extraFeeList![i].rate),
style: TextStyle(
color: Colors.grey,
),
@@ -848,7 +847,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
width: 100.0,
alignment: Alignment.centerRight,
child: Text(
'${cartInfo.extraFeeList[i].price.toStringAsFixed(2)}'
'${cartInfo!.extraFeeList![i].price.toStringAsFixed(2)}'
),
),
],
@@ -876,7 +875,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
width: 100.0,
alignment: Alignment.centerRight,
child: Text(
'${(cartInfo.totalPrice - couponDiscountAmount).toStringAsFixed(2)}',
'${(cartInfo!.totalPrice! - couponDiscountAmount).toStringAsFixed(2)}',
style: TextStyle(
fontSize: 19.0,
fontWeight: FontWeight.bold,
@@ -974,7 +973,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
children: <Widget>[
Container(
padding: EdgeInsets.all(5.0),
child: Util.showImage('${cartLineItem.product.imagePath}',
child: Util.showImage('${cartLineItem.product?.imagePath}',
width: 40.0,
height: 40.0,
fit: BoxFit.fill,
@@ -988,14 +987,14 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
children: <Widget>[
Container(
child: Text(
Utils.knownName(context, cartLineItem.name),
Utils.knownName(context, cartLineItem.name!),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Container(
child: Text(
cartLineItem.description,
'${cartLineItem.description}',
style: TextStyle(
fontSize: 12.0,
color: Colors.black38,
@@ -1011,14 +1010,14 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
alignment: Alignment.centerRight,
margin: EdgeInsets.only(right: 10.0),
child: Text(
'x${cartLineItem.quantity.round()}',
'x${cartLineItem.quantity!.round()}',
),
),
Container(
width: 60.0,
alignment: Alignment.centerRight,
child: Text(
'${cartLineItem.totalPrice.toStringAsFixed(2)}',
'${cartLineItem.totalPrice!.toStringAsFixed(2)}',
),
),
],
@@ -1050,7 +1049,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
if (cartInfo != null) {
Utils.showLoadingDialog(context);
}
CartInfo ci = Utils.getCartInfoByBusinessId(store.state.cartInfos, widget.businessId);
CartInfo? ci = Utils.getCartInfoByBusinessId(store.state.cartInfos, widget.businessId);
HttpUtil.httpPost('v1/orders/check', (response) {
if (cartInfo != null) {
Navigator.of(context).pop();
@@ -1074,7 +1073,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
shippingRates = (response.data['shipping_rates'] as List).map((e) => ShippingRate.fromJson(e)).toList();
selectedShippingRate = (response.data['selected_shipping_rate'] as String).length > 0 ? ShippingRate.fromJson(json.decode(response.data['selected_shipping_rate'])) : null;
int i = 0;
if (cartInfo.businessInfo.deliveryStoreDelivery) {
if (cartInfo!.businessInfo!.deliveryStoreDelivery) {
shippingMethodLabels.add(S.of(context).delivery);
shippingMethodIcons.add(Icons.directions_car);
if (deliveryMethod == 'store-delivery') {
@@ -1082,7 +1081,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
}
i++;
}
if (cartInfo.businessInfo.deliveryCanadaPost) {
if (cartInfo!.businessInfo!.deliveryCanadaPost) {
shippingMethodLabels.add(S.of(context).canada_post);
shippingMethodIcons.add(Icons.local_shipping);
if (deliveryMethod == 'canada-post') {
@@ -1090,7 +1089,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
}
i++;
}
if (cartInfo.businessInfo.deliveryPickup) {
if (cartInfo!.businessInfo!.deliveryPickup) {
shippingMethodLabels.add(S.of(context).pickup);
shippingMethodIcons.add(Icons.store);
if (deliveryMethod == 'pickup') {
@@ -1103,8 +1102,8 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
},
businessId: widget.businessId,
body: {
'product_list': ci.productList.toString(),
'extra_data': ci.extraData,
'product_list': ci?.productList.toString(),
'extra_data': ci?.extraData,
'business_id': widget.businessId,
'pay_method': getPaymentMethod(),
'delivery': deliveryMethod,
@@ -1128,8 +1127,8 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
int getPaymentMethod() {
int method = 0;
if (paymentPlatforms.length > 0 && paymentPlatformIndex < paymentPlatforms.length) {
PaymentPlatform paymentPlatform = paymentPlatforms[paymentPlatformIndex];
if (paymentPlatforms!.length > 0 && paymentPlatformIndex! < paymentPlatforms!.length) {
PaymentPlatform paymentPlatform = paymentPlatforms![paymentPlatformIndex!];
if (paymentPlatform.method == Constants.PAYMENT_METHOD_PAY_ON_DELIVERY) {
return 1;
}
@@ -1138,10 +1137,10 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
}
void afterBuild(Duration time) {
if(errorMessages.length > 0) {
if(errorMessages != null && errorMessages!.length > 0) {
print('error: ${errorMessages.toString()}');
// _scaffoldKey.currentState.showSnackBar(errorSnackBar(errorMessages));
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(errorMessages));
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(errorMessages!));
}
}
@@ -1176,7 +1175,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Widget getBookingTimeWidget() {
Widget widget;
if (bookingTimeList.length > 0) {
if (bookingTimeList!.length > 0) {
widget = Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
@@ -1208,9 +1207,9 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
Expanded(
child: ListView.builder(
itemCount: bookingTimeList.length,
itemCount: bookingTimeList!.length,
itemBuilder: (BuildContext context, int position) {
BookingTime bookingTime = bookingTimeList[position];
BookingTime bookingTime = bookingTimeList![position];
return GestureDetector(
child: Container(
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 10.0, top: 10.0),
@@ -1241,7 +1240,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
)
],
);
} else if (bookingDateTimeList.length > 0) {
} else if (bookingDateTimeList!.length > 0) {
widget = Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
@@ -1281,9 +1280,9 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
color: new Color(0xFFF5F5F5),
child: SizedBox.expand(
child: ListView.builder(
itemCount: bookingDateTimeList.length,
itemCount: bookingDateTimeList!.length,
itemBuilder: (BuildContext context, int position) {
BookingDateTime bookingDateTime = bookingDateTimeList[position];
BookingDateTime bookingDateTime = bookingDateTimeList![position];
return GestureDetector(
child: Container(
color: bookingDateIndex == position ? Colors.white : Colors.transparent,
@@ -1310,9 +1309,9 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Expanded(
child: SizedBox.expand(
child: ListView.builder(
itemCount: bookingDateTimeList[bookingDateIndex].bookTimes.length,
itemCount: bookingDateTimeList![bookingDateIndex!].bookTimes.length,
itemBuilder: (BuildContext context, int position) {
BookingDateTime bookingDateTime = bookingDateTimeList[bookingDateIndex];
BookingDateTime bookingDateTime = bookingDateTimeList![bookingDateIndex!];
return GestureDetector(
child: Container(
padding: EdgeInsets.only(left: 12.0, right: 12.0, top: 12.0, bottom: 12.0),
@@ -1425,7 +1424,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
],
);
if (paymentPlatforms.length == 0) {
if (paymentPlatforms!.length == 0) {
widget.children.add(Center(
child: Container(
padding: EdgeInsets.all(16.0),
@@ -1438,20 +1437,20 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
widget.children.add(
Expanded(
child:ListView.builder(
itemCount: paymentPlatforms.length,
itemCount: paymentPlatforms!.length,
itemBuilder: (BuildContext context, int position) {
PaymentPlatform paymentPlatform = paymentPlatforms[position];
PaymentPlatform paymentPlatform = paymentPlatforms![position];
if (paymentPlatform.code == Constants.PAYMENT_METHOD_CODE_SQUARE &&
(paymentPlatform.squareAppId == null || paymentPlatform.squareAppId.isEmpty) &&
(paymentPlatform.squareAccessToken == null || paymentPlatform.squareAccessToken.isEmpty) &&
(paymentPlatform.squareLocationId == null || paymentPlatform.squareLocationId.isEmpty)
(paymentPlatform.squareAppId == null || paymentPlatform.squareAppId!.isEmpty) &&
(paymentPlatform.squareAccessToken == null || paymentPlatform.squareAccessToken!.isEmpty) &&
(paymentPlatform.squareLocationId == null || paymentPlatform.squareLocationId!.isEmpty)
) {
return SizedBox.shrink();
}
if (paymentPlatform.code == Constants.PAYMENT_METHOD_CODE_CHASE &&
(paymentPlatform.xLogin == null || paymentPlatform.xLogin.isEmpty) &&
(paymentPlatform.transactionKey == null || paymentPlatform.transactionKey.isEmpty) &&
(paymentPlatform.responseKey == null || paymentPlatform.responseKey.isEmpty)
(paymentPlatform.xLogin == null || paymentPlatform.xLogin!.isEmpty) &&
(paymentPlatform.transactionKey == null || paymentPlatform.transactionKey!.isEmpty) &&
(paymentPlatform.responseKey == null || paymentPlatform.responseKey!.isEmpty)
) {
return SizedBox.shrink();
}
@@ -1494,7 +1493,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
child: Util.showImage(paymentPlatform.icon,
child: Util.showImage(paymentPlatform.icon ?? '',
errorWidget: (context, url, error) => Icon(Icons.broken_image, size: 50.0, color: Colors.transparent,),
fit: BoxFit.cover,
width: 50.0,
@@ -1504,7 +1503,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
Container(
margin: EdgeInsets.only(left: 10.0),
child: Text(
PaymentPlatform.getPaymentPlatformName(context, paymentPlatform.code),
PaymentPlatform.getPaymentPlatformName(context, paymentPlatform.code ?? ''),
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
@@ -1541,7 +1540,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
String getSelectedCouponName() {
if (selectedCoupon == null) {
if (coupons.length > 0) {
if (coupons!.length > 0) {
return S
.of(context)
.please_select;
@@ -1553,10 +1552,10 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
} else if (selectedCoupon == 0) {
return S.of(context).dont_use;
} else {
for (var i = 0; i < coupons.length; i++) {
if (selectedCoupon == coupons[i].id) {
if (coupons[i].isPercentage) {
return S.of(context).percentage_discount_token2(couponDiscountAmount.toStringAsFixed(2), coupons[i].valueAmount);
for (var i = 0; i < coupons!.length; i++) {
if (selectedCoupon == coupons![i].id) {
if (coupons![i].isPercentage) {
return S.of(context).percentage_discount_token2(couponDiscountAmount.toStringAsFixed(2), coupons![i].valueAmount);
} else {
return S.of(context).discount_amount_token(couponDiscountAmount.toStringAsFixed(2));
}
@@ -1632,7 +1631,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
labelText: S.of(context).enter_coupon_code,
),
validator: (String value) {
validator: (String? value) {
return null;
},
),
@@ -1663,7 +1662,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
);
if (paymentPlatforms.length == 0) {
if (paymentPlatforms!.length == 0) {
widget.children.add(Center(
child: Container(
padding: EdgeInsets.all(16.0),
@@ -1675,13 +1674,13 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
} else {
widget.children.add(Expanded(
child: ListView.builder(
itemCount: coupons.length + 1,
itemCount: coupons!.length + 1,
itemBuilder: (BuildContext context, int position) {
if (position == 0) {
return GestureDetector(
child: Container(
decoration: selectedCoupon == 0 ? BoxDecoration(
color: subtotal > cartInfo.businessInfo.minPrice ? Colors
color: subtotal! > cartInfo!.businessInfo!.minPrice ? Colors
.transparent : Colors.black38,
border: Border(
top: BorderSide(
@@ -1702,7 +1701,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
),
) : BoxDecoration(
color: subtotal > cartInfo.businessInfo.minPrice ? Colors
color: subtotal! > cartInfo!.businessInfo!.minPrice ? Colors
.transparent : Colors.black38,
),
child: Row(
@@ -1739,11 +1738,11 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
},
);
} else {
Coupon coupon = coupons[position - 1];
Coupon coupon = coupons![position - 1];
return GestureDetector(
child: Container(
decoration: selectedCoupon == coupon.id ? BoxDecoration(
color: subtotal > cartInfo.businessInfo.minPrice ? Colors
color: subtotal! > cartInfo!.businessInfo!.minPrice ? Colors
.transparent : Colors.black38,
border: Border(
top: BorderSide(
@@ -1764,7 +1763,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
),
) : BoxDecoration(
color: subtotal > coupon.minAmount ? Colors
color: subtotal! > coupon.minAmount ? Colors
.transparent : Colors.black26,
),
child: Row(
@@ -1885,12 +1884,12 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
),
onTap: () {
if (subtotal > coupon.minAmount &&
if (subtotal! > coupon.minAmount &&
mounted) {
setState(() {
selectedCoupon = coupon.id;
if (coupon.isPercentage) {
couponDiscountAmount = subtotal * coupon.valueAmount / 100.0;
couponDiscountAmount = subtotal! * coupon.valueAmount / 100.0;
} else {
couponDiscountAmount = coupon.valueAmount;
}
@@ -1917,7 +1916,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
crossAxisAlignment: CrossAxisAlignment.start,
children: [],
);
if (cartInfo.businessInfo.quickInputs.length > 0) {
if (cartInfo!.businessInfo!.quickInputs.length > 0) {
Wrap w = Wrap(
children: [],
);
@@ -1931,8 +1930,8 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
),
),
));
for (int i = 0; i < cartInfo.businessInfo.quickInputs.length; i++) {
String qi = cartInfo.businessInfo.quickInputs[i].value;
for (int i = 0; i < cartInfo!.businessInfo!.quickInputs.length; i++) {
String qi = cartInfo!.businessInfo!.quickInputs[i].value;
w.children.add(TextButton(
child: Text(
qi,
@@ -2183,7 +2182,7 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
confirmOrder() {
if (!canSubmit) {
// _scaffoldKey.currentState.showSnackBar(errorSnackBar(errorMessages));
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(errorMessages));
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(errorMessages!));
} else {
Utils.showSubmitDialog(context);
HttpUtil.httpPost('v1/orders', (response) {
@@ -2191,19 +2190,19 @@ class MobileCheckoutState extends State<MobileCheckout> with SingleTickerProvide
store.dispatch(UpdateCartInfo(Utils.removeCartInfoFromCartInfoList(store.state.cartInfos, cartInfo)));
eventBus.fire(OnCartInfoUpdated());
Order order = Order.fromJson(response.data);
PaymentPlatform paymentPlatform = paymentPlatforms[paymentPlatformIndex];
PaymentPlatform paymentPlatform = paymentPlatforms![paymentPlatformIndex!];
Routes.router.navigateTo(context, '/paynow/${order.id}', replace: true);
},
businessId: widget.businessId,
body: {
'cart_id': cartInfo.id,
'cart_id': cartInfo?.id,
'remark': orderRemark,
'booked_at': bookingTimeList.length > 0
? bookingTimeList[bookingTimeIndex].unixTime
'booked_at': bookingTimeList!.length > 0
? bookingTimeList![bookingTimeIndex!].unixTime
: (
(bookingTimeList.length == 0 && bookingDateTimeList.length == 0) ?
(bookingTimeList!.length == 0 && bookingDateTimeList!.length == 0) ?
0 :
bookingDateTimeList[bookingDateIndex].bookTimes[bookingTimeIndex]
bookingDateTimeList![bookingDateIndex!].bookTimes[bookingTimeIndex!]
.unixTime
),
'delivery': deliveryMethod,