From 5cb5ef6396c300d521f912710ad81125305ff108 Mon Sep 17 00:00:00 2001 From: peima Date: Fri, 31 Jul 2026 15:05:08 +0800 Subject: [PATCH] phase3: checkout files clean (nullable fields, ternary/concat/condition fixes). 142->131 --- lib/widgets/desktop/desktop_checkout.dart | 24 ++++++------- .../general/attribute/radio_options.dart | 2 +- lib/widgets/mobile/mobile_checkout.dart | 34 +++++++++---------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/widgets/desktop/desktop_checkout.dart b/lib/widgets/desktop/desktop_checkout.dart index 4dfdb4e..6a40f98 100644 --- a/lib/widgets/desktop/desktop_checkout.dart +++ b/lib/widgets/desktop/desktop_checkout.dart @@ -292,7 +292,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi 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 : 0); print('aaa: $deliveryTimeInSeconds'); DateTime now = DateTime.now(); var formatter = DateFormat('H:mm'); @@ -494,7 +494,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi children: [ 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 ), @@ -505,7 +505,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi 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, @@ -654,7 +654,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi 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 : '')), + : bookingDateTimeList[bookingDateIndex].viewDate! + ' ' + (bookingDateTimeList[bookingDateIndex].bookTimes!.length > 0 ? bookingDateTimeList[bookingDateIndex].bookTimes![bookingTimeIndex].viewTime! : '')), ), ), Container( @@ -1075,7 +1075,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi 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(); @@ -1706,7 +1706,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi 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( @@ -1727,7 +1727,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi ), ), ) : BoxDecoration( - color: subtotal > cartInfo!.businessInfo!.minPrice ? Colors + color: subtotal > cartInfo!.businessInfo!.minPrice! ? Colors .transparent : Colors.black38, ), child: Row( @@ -1768,7 +1768,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi 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( @@ -1789,7 +1789,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi ), ), ) : BoxDecoration( - color: subtotal > coupon.minAmount ? Colors + color: subtotal > coupon.minAmount! ? Colors .transparent : Colors.black26, ), child: Row( @@ -1799,7 +1799,7 @@ class DesktopCheckoutState extends State with SingleTickerProvi Container( padding: EdgeInsets.only( left: 16.0, top: 16.0, right: 16.0, bottom: 16.0), - child: coupon.isPercentage ? + child: coupon.isPercentage == true ? Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, @@ -1910,12 +1910,12 @@ class DesktopCheckoutState extends State with SingleTickerProvi ), ), onTap: () { - if (subtotal > coupon.minAmount && + if (subtotal > coupon.minAmount! && mounted) { setState(() { selectedCoupon = coupon.id; if (coupon.isPercentage == true) { - couponDiscountAmount = subtotal * coupon.valueAmount / 100.0; + couponDiscountAmount = subtotal * coupon.valueAmount! / 100.0; } else { couponDiscountAmount = coupon.valueAmount!; } diff --git a/lib/widgets/general/attribute/radio_options.dart b/lib/widgets/general/attribute/radio_options.dart index 5d1e289..926d14e 100644 --- a/lib/widgets/general/attribute/radio_options.dart +++ b/lib/widgets/general/attribute/radio_options.dart @@ -47,7 +47,7 @@ class RadioOptionsState extends OptionsBaseState { overflow: TextOverflow.ellipsis, ), new Text( - product.productAttributes![this.index].required ? S.of(context).radio_option_is_required : S.of(context).radio_option_is_optional, + product.productAttributes![this.index].required == true ? S.of(context).radio_option_is_required : S.of(context).radio_option_is_optional, style: new TextStyle( fontSize: 10.0, color: new Color(0xFF999999) diff --git a/lib/widgets/mobile/mobile_checkout.dart b/lib/widgets/mobile/mobile_checkout.dart index fa495c6..1df72e6 100644 --- a/lib/widgets/mobile/mobile_checkout.dart +++ b/lib/widgets/mobile/mobile_checkout.dart @@ -46,13 +46,13 @@ class MobileCheckout extends StatefulWidget { class MobileCheckoutState extends State with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { late CartInfo cartInfo; - late Address shipAddress; + Address? shipAddress; late bool canSubmit; late List errorMessages; late List bookingTimeList; late List bookingDateTimeList; late List paymentPlatforms; - late TextValue durationInTraffic; + TextValue? durationInTraffic; late int selectedCoupon; double couponDiscountAmount = 0; late List coupons; @@ -65,7 +65,7 @@ class MobileCheckoutState extends State with SingleTickerProvide int deliveryMethodIndex = 0; late String deliveryMethod; List shippingRates = []; - late ShippingRate selectedShippingRate; + ShippingRate? selectedShippingRate; List shippingMethodLabels = []; List shippingMethodIcons = []; @@ -203,7 +203,7 @@ class MobileCheckoutState extends State with SingleTickerProvide color: Colors.white, ), ), - cartInfo.businessInfo!.isPublic ? SizedBox.shrink() : Container( + cartInfo.businessInfo!.isPublic == true ? 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 +267,7 @@ class MobileCheckoutState extends State 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 : 0); print('aaa: $deliveryTimeInSeconds'); DateTime now = DateTime.now(); var formatter = DateFormat('H:mm'); @@ -469,7 +469,7 @@ class MobileCheckoutState extends State with SingleTickerProvide children: [ 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 +480,7 @@ class MobileCheckoutState extends State 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, @@ -553,7 +553,7 @@ class MobileCheckoutState extends State 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, @@ -629,7 +629,7 @@ class MobileCheckoutState extends State with SingleTickerProvide 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 : '')), + : bookingDateTimeList[bookingDateIndex].viewDate! + ' ' + (bookingDateTimeList[bookingDateIndex].bookTimes!.length > 0 ? bookingDateTimeList[bookingDateIndex].bookTimes![bookingTimeIndex].viewTime! : '')), ), ), Container( @@ -1050,7 +1050,7 @@ class MobileCheckoutState extends State 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(); @@ -1681,7 +1681,7 @@ class MobileCheckoutState extends State with SingleTickerProvide 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 +1702,7 @@ class MobileCheckoutState extends State with SingleTickerProvide ), ), ) : BoxDecoration( - color: subtotal > cartInfo.businessInfo!.minPrice ? Colors + color: subtotal > cartInfo.businessInfo!.minPrice! ? Colors .transparent : Colors.black38, ), child: Row( @@ -1743,7 +1743,7 @@ class MobileCheckoutState extends State with SingleTickerProvide 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 +1764,7 @@ class MobileCheckoutState extends State with SingleTickerProvide ), ), ) : BoxDecoration( - color: subtotal > coupon.minAmount ? Colors + color: subtotal > coupon.minAmount! ? Colors .transparent : Colors.black26, ), child: Row( @@ -1774,7 +1774,7 @@ class MobileCheckoutState extends State with SingleTickerProvide Container( padding: EdgeInsets.only( left: 16.0, top: 16.0, right: 16.0, bottom: 16.0), - child: coupon.isPercentage ? + child: coupon.isPercentage == true ? Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, @@ -1885,12 +1885,12 @@ class MobileCheckoutState extends State with SingleTickerProvide ), ), onTap: () { - if (subtotal > coupon.minAmount && + if (subtotal > coupon.minAmount! && mounted) { setState(() { selectedCoupon = coupon.id!; if (coupon.isPercentage == true) { - couponDiscountAmount = subtotal * coupon.valueAmount / 100.0; + couponDiscountAmount = subtotal * coupon.valueAmount! / 100.0; } else { couponDiscountAmount = coupon.valueAmount!; }