From 137eca4c6964fd931a4a99317cc78c791c62f49c Mon Sep 17 00:00:00 2001 From: peima Date: Sat, 1 Aug 2026 01:16:25 +0800 Subject: [PATCH] phase3: nullable fields/methods, casts, ?.call, condition fixes across 11 files. 108->72 --- lib/widgets/desktop/desktop_coupons.dart | 12 +- lib/widgets/desktop/desktop_edit_address.dart | 10 +- lib/widgets/desktop/desktop_me.dart | 20 ++-- lib/widgets/desktop/desktop_my_support.dart | 14 +-- lib/widgets/desktop/desktop_order_detail.dart | 106 ++++++++--------- lib/widgets/desktop/shop_products.dart | 10 +- .../general/animation_point_manager.dart | 10 +- .../general/parabolic_animation_widget.dart | 10 +- lib/widgets/general/sliding_up_panel.dart | 10 +- .../mobile/mobile_attribute_selection.dart | 8 +- lib/widgets/mobile/mobile_edit_address.dart | 10 +- lib/widgets/mobile/mobile_order_detail.dart | 108 +++++++++--------- 12 files changed, 164 insertions(+), 164 deletions(-) diff --git a/lib/widgets/desktop/desktop_coupons.dart b/lib/widgets/desktop/desktop_coupons.dart index 1d2632e..1ed8659 100644 --- a/lib/widgets/desktop/desktop_coupons.dart +++ b/lib/widgets/desktop/desktop_coupons.dart @@ -27,7 +27,7 @@ class DesktopCoupons extends StatefulWidget { } class DesktopCouponsState extends State { - late List coupons; + List? coupons; double sideSpace = 0; double mainSpace = 1200; @@ -56,10 +56,10 @@ class DesktopCouponsState extends State { } Widget w = ListView.builder( - itemCount: coupons.length > 0 ? coupons.length : 1, + itemCount: coupons!.length > 0 ? coupons!.length : 1, itemBuilder: (BuildContext context, int position) { - if (coupons.length > 0) { - Coupon coupon = coupons[position]; + if (coupons!.length > 0) { + Coupon coupon = coupons![position]; return Container( color: Colors.black12, child: couponWidget(coupon), @@ -137,7 +137,7 @@ class DesktopCouponsState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - coupon.store != null ? coupon.store!.name : S.of(context).general_coupon, + coupon.store != null ? coupon.store!.name! : S.of(context).general_coupon, style: TextStyle( fontSize: 20.0, fontWeight: FontWeight.bold, @@ -169,7 +169,7 @@ class DesktopCouponsState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( - child: !coupon.isPercentage ? + child: coupon.isPercentage != true ? Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/widgets/desktop/desktop_edit_address.dart b/lib/widgets/desktop/desktop_edit_address.dart index 8c3f3d6..5db9aea 100644 --- a/lib/widgets/desktop/desktop_edit_address.dart +++ b/lib/widgets/desktop/desktop_edit_address.dart @@ -106,7 +106,7 @@ class DesktopEditAddressState extends State { .contact_name, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -161,7 +161,7 @@ class DesktopEditAddressState extends State { .mobile_phone_number, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -193,7 +193,7 @@ class DesktopEditAddressState extends State { .street_line_1, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -247,7 +247,7 @@ class DesktopEditAddressState extends State { .city, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -317,7 +317,7 @@ class DesktopEditAddressState extends State { .postal_code, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S diff --git a/lib/widgets/desktop/desktop_me.dart b/lib/widgets/desktop/desktop_me.dart index 46ad599..c94af66 100644 --- a/lib/widgets/desktop/desktop_me.dart +++ b/lib/widgets/desktop/desktop_me.dart @@ -36,7 +36,7 @@ class DesktopMeState extends State { late String accessToken; late bool isLoading; - late User _user; + User? _user; double sideSpace = 0; double mainSpace = 1200; @@ -81,9 +81,9 @@ class DesktopMeState extends State { children: [ Container( margin: EdgeInsets.only(right: 5.0), - child: _user != null && _user.avatarUrl!.isNotEmpty + child: _user != null && _user!.avatarUrl!.isNotEmpty ? Util.showImage( - 'https:${_user.avatarUrl}', + 'https:${_user!.avatarUrl}', width: 60, height: 60, fit: BoxFit.fill, @@ -101,7 +101,7 @@ class DesktopMeState extends State { ), Container( child: Text( - _user != null ? _user.nickname : S.of(context).please_login, + _user != null ? _user!.nickname! : S.of(context).please_login, style: TextStyle( color: Colors.black38, fontSize: 18.0, @@ -125,7 +125,7 @@ class DesktopMeState extends State { Container( child: Text( _user != null - ? Utils.safePhoneNumber(_user.mobile!) + ? Utils.safePhoneNumber(_user!.mobile!) : '', style: TextStyle( color: Colors.black38, @@ -182,7 +182,7 @@ class DesktopMeState extends State { Container( child: Text( _user != null - ? '${_user.wallet!.toStringAsFixed(2)}' + ? '${_user!.wallet!.toStringAsFixed(2)}' : '0.00', style: TextStyle( fontSize: 24.0, @@ -228,7 +228,7 @@ class DesktopMeState extends State { children: [ Container( child: Text( - _user != null ? '${_user.coupon}' : '0', + _user != null ? '${_user!.coupon}' : '0', style: TextStyle( fontSize: 24.0, color: Colors.orangeAccent, @@ -262,7 +262,7 @@ class DesktopMeState extends State { onTap: () { if (_user != null) { Routes.router.navigateTo( - context, '/coupons/${_user.id}'); + context, '/coupons/${_user!.id}'); } else { _pleaseLoginToast(); } @@ -281,7 +281,7 @@ class DesktopMeState extends State { children: [ Container( child: Text( - _user != null ? '${_user.points}' : '0', + _user != null ? '${_user!.points}' : '0', style: TextStyle( fontSize: 24.0, color: Colors.lightGreen, @@ -493,7 +493,7 @@ class DesktopMeState extends State { ), ), ), - onTap: tap!, + onTap: () => tap(), ), ); return widget; diff --git a/lib/widgets/desktop/desktop_my_support.dart b/lib/widgets/desktop/desktop_my_support.dart index b339680..75f462e 100644 --- a/lib/widgets/desktop/desktop_my_support.dart +++ b/lib/widgets/desktop/desktop_my_support.dart @@ -30,7 +30,7 @@ class DesktopMySupport extends StatefulWidget { } class DesktopMySupportState extends State { - late List tickets; + List? tickets; double division = 3; @@ -45,7 +45,7 @@ class DesktopMySupportState extends State { void _onRefresh() { _page = 1; if (tickets != null) { - tickets.clear(); + tickets!.clear(); } else { tickets = []; } @@ -106,7 +106,7 @@ class DesktopMySupportState extends State { enablePullUp: true, header: WaterDropHeader(), footer: CustomFooter( - builder: (BuildContext context, LoadStatus mode){ + builder: (BuildContext context, LoadStatus? mode){ Widget footer; if(mode == LoadStatus.idle) { footer = Text(S.of(context).pull_up_to_load_more); @@ -157,9 +157,9 @@ class DesktopMySupportState extends State { right: 8.0, ), child: tickets == null ? Text('') : - (tickets.length > 0 ? + (tickets!.length > 0 ? Wrap( - children: tickets.map((a) => _getTicket(a)).toList(), + children: tickets!.map((a) => _getTicket(a)).toList(), ) : Center( child: Text(S.of(context).no_ticket_yet), @@ -240,7 +240,7 @@ class DesktopMySupportState extends State { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - ticket.isClosed ? + ticket.isClosed == true ? Container( padding: EdgeInsets.only(right: 10.0), child: Icon(Icons.lock, color: Colors.green, size: 16.0,), @@ -321,7 +321,7 @@ class DesktopMySupportState extends State { if (tickets == null) { tickets = []; } - tickets.addAll((value['tickets'] as List).map((e) => Ticket.fromJson(e)).toList()); + tickets!.addAll((value['tickets'] as List).map((e) => Ticket.fromJson(e)).toList()); }); } }).catchError((error) { diff --git a/lib/widgets/desktop/desktop_order_detail.dart b/lib/widgets/desktop/desktop_order_detail.dart index 3ff6812..54cabd4 100644 --- a/lib/widgets/desktop/desktop_order_detail.dart +++ b/lib/widgets/desktop/desktop_order_detail.dart @@ -39,7 +39,7 @@ class DesktopOrderDetail extends StatefulWidget { } class DesktopOrderDetailState extends State { - late Order order; + Order? order; late LatLng _lastMapPosition; late LatLng customerLatLng; @@ -110,7 +110,7 @@ class DesktopOrderDetailState extends State { width: double.infinity, padding: EdgeInsets.only(top: 0.0, bottom: 16.0), child: Text( - order.cartInfo!.businessInfo!.name!, + order!.cartInfo!.businessInfo!.name!, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( @@ -129,7 +129,7 @@ class DesktopOrderDetailState extends State { ), ), onTap: () { - Routes.router.navigateTo(context, '/shop/${order.businessId}/na/na/na'); + Routes.router.navigateTo(context, '/shop/${order!.businessId}/na/na/na'); }, ), ), @@ -141,7 +141,7 @@ class DesktopOrderDetailState extends State { Icons.phone, ), onTap: () { - Utils.launchURL('tel:${order.businessInfo!.phone}'); + Utils.launchURL('tel:${order!.businessInfo!.phone}'); }, ), ), @@ -150,13 +150,13 @@ class DesktopOrderDetailState extends State { ); if (!kIsWeb) { - if (order.shippingMethod == 'store-delivery' && order.status != Constants.STATUS_COMPLETE && order.status != Constants.STATUS_CANCELLED) { + if (order!.shippingMethod == 'store-delivery' && order!.status != Constants.STATUS_COMPLETE && order!.status != Constants.STATUS_CANCELLED) { col.children.add(Container( height: 200.0, child: GoogleMap( onMapCreated: _onMapCreated, initialCameraPosition: CameraPosition( - target: new LatLng(double.parse(order.shippingAddress!.lat!), double.parse(order.shippingAddress!.lng!)!), + target: new LatLng(double.parse(order!.shippingAddress!.lat!), double.parse(order!.shippingAddress!.lng!)!), zoom: 11.0, ), onCameraMove: _onCameraMove, @@ -167,14 +167,14 @@ class DesktopOrderDetailState extends State { ].toSet(), ), )); - if (order.deliveryDistance != null && order.deliveryDistance!.distance != null) { + if (order!.deliveryDistance != null && order!.deliveryDistance!.distance != null) { col.children.add(Container( padding: EdgeInsets.only(top: 6.0, bottom: 6.0), margin: EdgeInsets.only(bottom: 6.0), child: Text( S.of(context).delivery_distance_token( - order.deliveryDistance!.distance!.text!, - order.deliveryDistance!.duration!.text! + order!.deliveryDistance!.distance!.text!, + order!.deliveryDistance!.duration!.text! ), ), decoration: BoxDecoration( @@ -190,7 +190,7 @@ class DesktopOrderDetailState extends State { } } - for (CartLineItem lineItem in order.cartInfo!.productList!) { + for (CartLineItem lineItem in order!.cartInfo!.productList!) { col.children.add(Container( padding: EdgeInsets.only(top: 16.0, bottom: 0.0), @@ -289,7 +289,7 @@ class DesktopOrderDetailState extends State { width: 100.0, alignment: Alignment.centerRight, child: Text( - '${order.getSubtotal().toStringAsFixed(2)}', + '${order!.getSubtotal().toStringAsFixed(2)}', style: TextStyle( fontSize: 15.0, ), @@ -298,8 +298,8 @@ class DesktopOrderDetailState extends State { ], ), ); - for (var i = 0; i < order.cartInfo!.extraFeeList!.length; i++) { - ExtraFee extraFee = order.cartInfo!.extraFeeList![i]; + for (var i = 0; i < order!.cartInfo!.extraFeeList!.length; i++) { + ExtraFee extraFee = order!.cartInfo!.extraFeeList![i]; col.children.add( Row( mainAxisAlignment: MainAxisAlignment.start, @@ -356,7 +356,7 @@ class DesktopOrderDetailState extends State { width: 100.0, alignment: Alignment.centerRight, child: Text( - '${order.totalPrice!.toStringAsFixed(2)}', + '${order!.totalPrice!.toStringAsFixed(2)}', style: TextStyle( fontSize: 18.0, fontWeight: FontWeight.bold, @@ -409,7 +409,7 @@ class DesktopOrderDetailState extends State { ), ), ); - if (order.shippingMethod != 'pickup') { + if (order!.shippingMethod != 'pickup') { col.children.add(Container( child: Row( mainAxisAlignment: MainAxisAlignment.start, @@ -428,7 +428,7 @@ class DesktopOrderDetailState extends State { child: Container( margin: EdgeInsets.only(top: 10.0, bottom: 10.0), child: Text( - '${order.address}, ${order.consignee}, ${order.phone}', + '${order!.address}, ${order!.consignee}, ${order!.phone}', style: TextStyle( color: Colors.black38, ), @@ -466,7 +466,7 @@ class DesktopOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - '${order.cartInfo!.businessInfo!.fullAddress}', + '${order!.cartInfo!.businessInfo!.fullAddress}', style: TextStyle( color: Colors.black38, ), @@ -505,7 +505,7 @@ class DesktopOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - '${Utils.timestampToString(context, order.bookedAt!, withTime: true)}', + '${Utils.timestampToString(context, order!.bookedAt!, withTime: true)}', style: TextStyle( color: Colors.black38, ), @@ -543,7 +543,7 @@ class DesktopOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - order.shippingMethod == 'pickup' ? S.of(context).pickup : S.of(context).store_delivery, + order!.shippingMethod == 'pickup' ? S.of(context).pickup : S.of(context).store_delivery, style: TextStyle( color: Colors.black38, ), @@ -633,7 +633,7 @@ class DesktopOrderDetailState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ Text( - '${order.orderNum}', + '${order!.orderNum}', style: TextStyle( color: Colors.black38, ), @@ -655,7 +655,7 @@ class DesktopOrderDetailState extends State { S.of(context).copy, ), onTap: () { - Clipboard.setData(ClipboardData(text: '${order.orderNum}')); + Clipboard.setData(ClipboardData(text: '${order!.orderNum}')); Fluttertoast.showToast( msg: S.of(context).order_number_copied_to_clipboard, toastLength: Toast.LENGTH_SHORT, @@ -700,7 +700,7 @@ class DesktopOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - order.payMethod == 0 ? S.of(context).online_payment : S.of(context).pay_on_deliery, + order!.payMethod == 0 ? S.of(context).online_payment : S.of(context).pay_on_deliery, style: TextStyle( color: Colors.black38, ), @@ -741,15 +741,15 @@ class DesktopOrderDetailState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ Text( - order.paymentStatus == Constants.PAYMENT_STATUS_PAID ? S.of(context).paid : S.of(context).unpaid, + order!.paymentStatus == Constants.PAYMENT_STATUS_PAID ? S.of(context).paid : S.of(context).unpaid, style: TextStyle( color: Colors.black38, ), ), Container( - margin: order.paymentStatus != Constants.PAYMENT_STATUS_PAID && order.status != Constants.STATUS_CANCELLED ? EdgeInsets.only(left: 10.0, right: 10.0) : EdgeInsets.only(left: 0.0, right: 0.0), - child: order.paymentStatus != Constants.PAYMENT_STATUS_PAID && order.status != Constants.STATUS_CANCELLED ? Text('') : SizedBox.shrink(), - decoration: order.paymentStatus != Constants.PAYMENT_STATUS_PAID && order.status != Constants.STATUS_CANCELLED ? BoxDecoration( + margin: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID && order!.status != Constants.STATUS_CANCELLED ? EdgeInsets.only(left: 10.0, right: 10.0) : EdgeInsets.only(left: 0.0, right: 0.0), + child: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID && order!.status != Constants.STATUS_CANCELLED ? Text('') : SizedBox.shrink(), + decoration: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID && order!.status != Constants.STATUS_CANCELLED ? BoxDecoration( border: Border( left: BorderSide( width: 0.5, @@ -759,16 +759,16 @@ class DesktopOrderDetailState extends State { ) : null, ), GestureDetector( - child: order.paymentStatus != Constants.PAYMENT_STATUS_PAID - && order.status != Constants.STATUS_CANCELLED - && order.status != Constants.STATUS_COMPLETE ? Text( + child: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID + && order!.status != Constants.STATUS_CANCELLED + && order!.status != Constants.STATUS_COMPLETE ? Text( S.of(context).pay_now, style: TextStyle( fontWeight: FontWeight.bold, ), ) : SizedBox.shrink(), onTap: () { - Routes.router.navigateTo(context, '/paynow/${order.id}'); + Routes.router.navigateTo(context, '/paynow/${order!.id}'); }, ), ], @@ -806,7 +806,7 @@ class DesktopOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - Utils.timestampToString(context, order.createdAt!, withTime: true), + Utils.timestampToString(context, order!.createdAt!, withTime: true), style: TextStyle( color: Colors.black38, ), @@ -862,7 +862,7 @@ class DesktopOrderDetailState extends State { ), ), Text( - Utils.getOrderStatus(context, order.status!), + Utils.getOrderStatus(context, order!.status!), maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( @@ -884,7 +884,7 @@ class DesktopOrderDetailState extends State { ), ),); - for (Fulfillment fulfillment in order.fulfillments!) { + for (Fulfillment fulfillment in order!.fulfillments!) { col.children.add(Container( padding: EdgeInsets.only(top: 10.0, bottom: 10.0), width: double.infinity, @@ -963,13 +963,13 @@ class DesktopOrderDetailState extends State { back: true, breadCrumbs: [ BreadCrumb(S.of(context).order_detail, null), - BreadCrumb('#${order.orderNum}', null) + BreadCrumb('#${order!.orderNum}', null) ], breadCrumbHeight: Constants.BREADCRUMB_HEIGHT, ), body: WillPopScope( onWillPop: () async { - if (widget.fromOrders != null && widget.fromOrders) { + if (widget.fromOrders == true) { return true; } else { Routes.router.navigateTo( @@ -1000,7 +1000,7 @@ class DesktopOrderDetailState extends State { children: [ Container( padding: EdgeInsets.only(right: 10.0), - child: order.status == Constants.STATUS_PENDING && order.paymentStatus == Constants.PAYMENT_STATUS_UNPAID ? + child: order!.status == Constants.STATUS_PENDING && order!.paymentStatus == Constants.PAYMENT_STATUS_UNPAID ? TextButton( child: Text( S.of(context).cancel_order, @@ -1015,7 +1015,7 @@ class DesktopOrderDetailState extends State { ) : SizedBox.shrink(), ), Container( - child: order.status == Constants.STATUS_COMPLETE && !order.hasComment ? ElevatedButton( + child: order!.status == Constants.STATUS_COMPLETE && order!.hasComment != true ? ElevatedButton( child: Text( S.of(context).comment, style: TextStyle( @@ -1023,16 +1023,16 @@ class DesktopOrderDetailState extends State { ), ), onPressed: () { - Routes.router.navigateTo(context, '/new-comment/${order.id}'); + Routes.router.navigateTo(context, '/new-comment/${order!.id}'); }, ) : SizedBox.shrink(), ), ], ), Container( - child: order.paymentStatus != Constants.PAYMENT_STATUS_PAID - && order.status != Constants.STATUS_CANCELLED - && order.status != Constants.STATUS_COMPLETE ? + child: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID + && order!.status != Constants.STATUS_CANCELLED + && order!.status != Constants.STATUS_COMPLETE ? TextButton( child: Text( S.of(context).pay_now, @@ -1042,7 +1042,7 @@ class DesktopOrderDetailState extends State { ), ), onPressed: () { - Routes.router.navigateTo(context, '/paynow/${order.id}'); + Routes.router.navigateTo(context, '/paynow/${order!.id}'); }, ) : TextButton( child: Text( @@ -1053,7 +1053,7 @@ class DesktopOrderDetailState extends State { ), ), onPressed: () { - Utils.orderAgain(context, order.cartInfo!); + Utils.orderAgain(context, order!.cartInfo!); }, ), ), @@ -1091,13 +1091,13 @@ class DesktopOrderDetailState extends State { order = Order.fromJson(data); if (!kIsWeb) { - if (order.shippingMethod == 'store-delivery' && order.status != Constants.STATUS_COMPLETE && order.status != Constants.STATUS_CANCELLED) { - storeLatLng = LatLng(double.parse(order.businessInfo!.address!.lat!), - double.parse(order.businessInfo!.address!.lng!)); - customerLatLng = LatLng(double.parse(order.shippingAddress!.lat!), - double.parse(order.shippingAddress!.lng!)); + if (order!.shippingMethod == 'store-delivery' && order!.status != Constants.STATUS_COMPLETE && order!.status != Constants.STATUS_CANCELLED) { + storeLatLng = LatLng(double.parse(order!.businessInfo!.address!.lat!), + double.parse(order!.businessInfo!.address!.lng!)); + customerLatLng = LatLng(double.parse(order!.shippingAddress!.lat!), + double.parse(order!.shippingAddress!.lng!)); deliveryLatLng = - LatLng(order.shipperPosition!.lat!, order.shipperPosition!.lng!); + LatLng(order!.shipperPosition!.lat!, order!.shipperPosition!.lng!); _polyLine.clear(); _polyLine.add( @@ -1110,7 +1110,7 @@ class DesktopOrderDetailState extends State { ], width: 3, points: [ - order.shipperPosition!.lat != 0.0 ? deliveryLatLng : storeLatLng, + order!.shipperPosition!.lat != 0.0 ? deliveryLatLng : storeLatLng, customerLatLng, ] ) @@ -1135,12 +1135,12 @@ class DesktopOrderDetailState extends State { title: S .of(context) .customer, - snippet: order.shippingAddress!.addressLine1, + snippet: order!.shippingAddress!.addressLine1, ), icon: homeIcon, )); - if (order.shipperPosition!.lat != 0.0 && - order.shipperPosition!.lng != 0.0) { + if (order!.shipperPosition!.lat != 0.0 && + order!.shipperPosition!.lng != 0.0) { _markers.add(Marker( markerId: MarkerId('shipper_position'), position: deliveryLatLng, diff --git a/lib/widgets/desktop/shop_products.dart b/lib/widgets/desktop/shop_products.dart index f9c71f8..1ce77d6 100644 --- a/lib/widgets/desktop/shop_products.dart +++ b/lib/widgets/desktop/shop_products.dart @@ -29,7 +29,7 @@ class ShopProductsState extends State { dynamic data; static const num _categoryHeight = 50.0; - static const num _categoryDescHeight = 50.0; + static const double _categoryDescHeight = 50.0; static const num _productHeight = 266.0; bool displayProductByCategoryClick = false; @@ -114,7 +114,7 @@ class ShopProductsState extends State { itemBuilder: (BuildContext context, int i) { CategoryProducts cp = _categoryProducts[i]; int qtyInCategory = 0; - CartInfo cartInfo = Utils.getCartInfoByBusiness(store.state.cartInfos, _business); + CartInfo cartInfo = Utils.getCartInfoByBusiness(store.state.cartInfos, _business)!; if (cartInfo != null && cartInfo.businessInfo!.id == _business.id && cartInfo.productList != null) { @@ -207,7 +207,7 @@ class ShopProductsState extends State { CategoryProducts cp = _categoryProducts[i]; if (cp.products!.length > 0) { col.children.add(new Container( - height: _categoryDescHeight!, + height: _categoryDescHeight, padding: new EdgeInsets.symmetric(horizontal: 10.0), color: new Color(0xFFF5F5F5), child: new Row( @@ -386,7 +386,7 @@ class ShopProductsState extends State { .pull_up_to_load_more; } CategoryProducts currentCp = - getCategoryProductByCategoryId(categoryId); + getCategoryProductByCategoryId(categoryId)!; if (currentCp != null) { currentCp.products!.addAll(moreCategoryProducts[0].products!); } else { @@ -410,7 +410,7 @@ class ShopProductsState extends State { return num; } - CategoryProducts getCategoryProductByCategoryId(int cid) { + CategoryProducts? getCategoryProductByCategoryId(int cid) { for (CategoryProducts cp in _categoryProducts) { if (cp.id == cid) { return cp; diff --git a/lib/widgets/general/animation_point_manager.dart b/lib/widgets/general/animation_point_manager.dart index 317b524..7d96c98 100644 --- a/lib/widgets/general/animation_point_manager.dart +++ b/lib/widgets/general/animation_point_manager.dart @@ -21,7 +21,7 @@ class AnimationPointManager { Offset endAdjustOffset = Offset.zero, }) async { controller1 = createController(vsync, duration); - Animation animation = createAnimation(controller1); + Animation animation = createAnimation(controller1); AnimatedWidget animatedWidget = ParabolicAnimationWidget( animation: animation!, @@ -34,7 +34,7 @@ class AnimationPointManager { endAdjustOffset: endAdjustOffset, ); list.add(animatedWidget); - statusListener(AnimationStatus.dismissed); + statusListener?.call(AnimationStatus.dismissed); try { await controller1.forward().orCancel; @@ -47,7 +47,7 @@ class AnimationPointManager { print('Error: $error'); } - statusListener(AnimationStatus.completed); + statusListener?.call(AnimationStatus.completed); } Future addPopupAniamtion({ @@ -69,7 +69,7 @@ class AnimationPointManager { popupOffset: popupOffset, ); list.add(animatedWidget); - statusListener(AnimationStatus.dismissed); + statusListener?.call(AnimationStatus.dismissed); try { await controller2.forward().orCancel; @@ -83,7 +83,7 @@ class AnimationPointManager { print('Error: $error'); } - statusListener(AnimationStatus.completed); + statusListener?.call(AnimationStatus.completed); } static AnimationController createController( diff --git a/lib/widgets/general/parabolic_animation_widget.dart b/lib/widgets/general/parabolic_animation_widget.dart index d47de01..c3dc0bc 100644 --- a/lib/widgets/general/parabolic_animation_widget.dart +++ b/lib/widgets/general/parabolic_animation_widget.dart @@ -29,7 +29,7 @@ class ParabolicAnimationWidget extends AnimatedWidget { Widget build(BuildContext context) { _calPoints(); - final Animation animation = listenable!; + final Animation animation = listenable! as Animation; final double time = animation.value; // 设time=1 已知两点坐标 和 初速度 可求出 加速度 a @@ -66,17 +66,17 @@ class ParabolicAnimationWidget extends AnimatedWidget { void _calPoints() { if (_startOffset == null) { - RenderBox stackBox = stackKey.currentContext!.findRenderObject()!; + RenderBox stackBox = stackKey.currentContext!.findRenderObject()! as RenderBox; Offset stackBoxOffset = stackBox.globalToLocal(Offset.zero); EdgeInsets startMargin = _margin(startKey); - RenderBox startBox = startKey.currentContext!.findRenderObject()!; + RenderBox startBox = startKey.currentContext!.findRenderObject()! as RenderBox; _startOffset = startBox.localToGlobal(Offset( startMargin.left + startAdjustOffset.dx, stackBoxOffset.dy + startMargin.top + startAdjustOffset.dy)); EdgeInsets endMargin = _margin(endKey); - RenderBox endBox = endKey.currentContext!.findRenderObject()!; + RenderBox endBox = endKey.currentContext!.findRenderObject()! as RenderBox; _endOffset = endBox.localToGlobal(Offset( endMargin.left + endAdjustOffset.dx, stackBoxOffset.dy + endMargin.top + endAdjustOffset.dy)); @@ -85,7 +85,7 @@ class ParabolicAnimationWidget extends AnimatedWidget { EdgeInsets _margin(GlobalKey key) { final Widget widget = key.currentContext!.widget; - EdgeInsets margin = (widget is Container) ? widget.margin : EdgeInsets.zero; + EdgeInsets margin = (widget is Container) ? (widget.margin ?? EdgeInsets.zero) : EdgeInsets.zero; return margin ?? EdgeInsets.zero; } } \ No newline at end of file diff --git a/lib/widgets/general/sliding_up_panel.dart b/lib/widgets/general/sliding_up_panel.dart index c54adbd..b549fbd 100644 --- a/lib/widgets/general/sliding_up_panel.dart +++ b/lib/widgets/general/sliding_up_panel.dart @@ -228,11 +228,11 @@ class _SlidingUpPanelState extends State with SingleTickerProvid duration: const Duration(milliseconds: 300), value: widget.defaultPanelState == PanelState.CLOSED ? 0.0 : 1.0 //set the default panel state (i.e. set initial value of _ac) )..addListener((){ - if(widget.onPanelSlide != null) widget.onPanelSlide(_ac.value); + if(widget.onPanelSlide != null) widget.onPanelSlide?.call(_ac.value); - if(widget.onPanelOpened != null && _ac.value == 1.0) widget.onPanelOpened(); + if(widget.onPanelOpened != null && _ac.value == 1.0) widget.onPanelOpened?.call(); - if(widget.onPanelClosed != null && _ac.value == 0.0) widget.onPanelClosed(); + if(widget.onPanelClosed != null && _ac.value == 0.0) widget.onPanelClosed?.call(); }); // prevent the panel content from being scrolled only if the widget is @@ -326,7 +326,7 @@ class _SlidingUpPanelState extends State with SingleTickerProvid height: widget.maxHeight, child: widget.panel != null ? widget.panel - : widget.panelBuilder(_sc), + : widget.panelBuilder!(_sc), ), ), @@ -391,7 +391,7 @@ class _SlidingUpPanelState extends State with SingleTickerProvid // this is because the listener is designed only for use with linking the scrolling of // panels and using it for panels that don't want to linked scrolling yields odd results Widget _gestureHandler({Widget? child}){ - if (!widget.isDraggable) return child; + if (!widget.isDraggable) return child!; if (widget.panel != null){ return GestureDetector( diff --git a/lib/widgets/mobile/mobile_attribute_selection.dart b/lib/widgets/mobile/mobile_attribute_selection.dart index 5ffed59..a615e37 100644 --- a/lib/widgets/mobile/mobile_attribute_selection.dart +++ b/lib/widgets/mobile/mobile_attribute_selection.dart @@ -119,13 +119,13 @@ class MobileAttributeSelectionState extends State { }); ProductAttribute pa = product.productAttributes![index]; - if (pa.required && Utils.selectionsNotEmptyAt(selections, pa.name!)) { + if (pa.required == true && Utils.selectionsNotEmptyAt(selections, pa.name!)) { setState(() { nextButtonEnable = true; productDesc = product.description! + ', ' + extendDescription.join('; '); productPrice = product.price! + extendPrice; }); - } else if (!pa.required){ + } else if (pa.required != true){ setState(() { nextButtonEnable = true; productDesc = product.description! + ', ' + extendDescription.join('; '); @@ -143,9 +143,9 @@ class MobileAttributeSelectionState extends State { bool _checkCanGoNext() { ProductAttribute pa = product.productAttributes![index]; - if (pa.required && Utils.selectionsNotEmptyAt(selections, pa.name!)) { + if (pa.required == true && Utils.selectionsNotEmptyAt(selections, pa.name!)) { return true; - } else if (!pa.required){ + } else if (pa.required != true){ return true; } return false; diff --git a/lib/widgets/mobile/mobile_edit_address.dart b/lib/widgets/mobile/mobile_edit_address.dart index d9e9160..83791d6 100644 --- a/lib/widgets/mobile/mobile_edit_address.dart +++ b/lib/widgets/mobile/mobile_edit_address.dart @@ -110,7 +110,7 @@ class MobileEditAddressState extends State { .contact_name, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -165,7 +165,7 @@ class MobileEditAddressState extends State { .mobile_phone_number, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -197,7 +197,7 @@ class MobileEditAddressState extends State { .street_line_1, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -251,7 +251,7 @@ class MobileEditAddressState extends State { .city, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S @@ -321,7 +321,7 @@ class MobileEditAddressState extends State { .postal_code, ), validator: (String? value) { - if (value + if (value! .trim() .isEmpty) { return S diff --git a/lib/widgets/mobile/mobile_order_detail.dart b/lib/widgets/mobile/mobile_order_detail.dart index 8ce349d..77a21e8 100644 --- a/lib/widgets/mobile/mobile_order_detail.dart +++ b/lib/widgets/mobile/mobile_order_detail.dart @@ -37,7 +37,7 @@ class MobileOrderDetail extends StatefulWidget { } class MobileOrderDetailState extends State { - late Order order; + Order? order; late LatLng _lastMapPosition; late LatLng customerLatLng; @@ -80,7 +80,7 @@ class MobileOrderDetailState extends State { leading: IconButton( icon: Icon(Icons.arrow_back_ios), onPressed: (){ - if (widget.fromOrders != null && widget.fromOrders) { + if (widget.fromOrders == true) { Navigator.of(context).pop(); } else { Routes.router.navigateTo( @@ -93,7 +93,7 @@ class MobileOrderDetailState extends State { ), body: WillPopScope( onWillPop: () async { - if (widget.fromOrders != null && widget.fromOrders) { + if (widget.fromOrders == true) { return true; } else { Routes.router.navigateTo( @@ -123,7 +123,7 @@ class MobileOrderDetailState extends State { width: double.infinity, padding: EdgeInsets.only(top: 0.0, bottom: 16.0), child: Text( - order.cartInfo!.businessInfo!.name!, + order!.cartInfo!.businessInfo!.name!, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( @@ -142,7 +142,7 @@ class MobileOrderDetailState extends State { ), ), onTap: () { - Routes.router.navigateTo(context, '/shop/${order.businessId}/na/na/na'); + Routes.router.navigateTo(context, '/shop/${order!.businessId}/na/na/na'); }, ), ), @@ -154,7 +154,7 @@ class MobileOrderDetailState extends State { Icons.phone, ), onTap: () { - Utils.launchURL('tel:${order.businessInfo!.phone}'); + Utils.launchURL('tel:${order!.businessInfo!.phone}'); }, ), ), @@ -163,15 +163,15 @@ class MobileOrderDetailState extends State { ); if (!kIsWeb) { - if (order.shippingMethod == 'store-delivery' && order.status != Constants.STATUS_COMPLETE && order.status != Constants.STATUS_CANCELLED) { + if (order!.shippingMethod == 'store-delivery' && order!.status != Constants.STATUS_COMPLETE && order!.status != Constants.STATUS_CANCELLED) { col.children.add(Container( height: 200.0, child: GoogleMap( onMapCreated: _onMapCreated, initialCameraPosition: CameraPosition( target: LatLng( - double.parse(order.shippingAddress!.lat!), - double.parse(order.shippingAddress!.lng!)), + double.parse(order!.shippingAddress!.lat!), + double.parse(order!.shippingAddress!.lng!)), zoom: 11.0, ), onCameraMove: _onCameraMove, @@ -182,14 +182,14 @@ class MobileOrderDetailState extends State { ].toSet(), ), )); - if (order.deliveryDistance != null && order.deliveryDistance!.distance != null) { + if (order!.deliveryDistance != null && order!.deliveryDistance!.distance != null) { col.children.add(Container( padding: EdgeInsets.only(top: 6.0, bottom: 6.0), margin: EdgeInsets.only(bottom: 6.0), child: Text( S.of(context).delivery_distance_token( - order.deliveryDistance!.distance!.text!, - order.deliveryDistance!.duration!.text! + order!.deliveryDistance!.distance!.text!, + order!.deliveryDistance!.duration!.text! ), ), decoration: BoxDecoration( @@ -205,7 +205,7 @@ class MobileOrderDetailState extends State { } } - for (CartLineItem lineItem in order.cartInfo!.productList!) { + for (CartLineItem lineItem in order!.cartInfo!.productList!) { col.children.add(Container( padding: EdgeInsets.only(top: 16.0, bottom: 0.0), @@ -304,7 +304,7 @@ class MobileOrderDetailState extends State { width: 100.0, alignment: Alignment.centerRight, child: Text( - '${order.getSubtotal().toStringAsFixed(2)}', + '${order!.getSubtotal().toStringAsFixed(2)}', style: TextStyle( fontSize: 15.0, ), @@ -313,8 +313,8 @@ class MobileOrderDetailState extends State { ], ), ); - for (var i = 0; i < order.cartInfo!.extraFeeList!.length; i++) { - ExtraFee extraFee = order.cartInfo!.extraFeeList![i]; + for (var i = 0; i < order!.cartInfo!.extraFeeList!.length; i++) { + ExtraFee extraFee = order!.cartInfo!.extraFeeList![i]; col.children.add( Row( mainAxisAlignment: MainAxisAlignment.start, @@ -371,7 +371,7 @@ class MobileOrderDetailState extends State { width: 100.0, alignment: Alignment.centerRight, child: Text( - '${order.totalPrice!.toStringAsFixed(2)}', + '${order!.totalPrice!.toStringAsFixed(2)}', style: TextStyle( fontSize: 18.0, fontWeight: FontWeight.bold, @@ -424,7 +424,7 @@ class MobileOrderDetailState extends State { ), ), ); - if (order.shippingMethod != 'pickup') { + if (order!.shippingMethod != 'pickup') { col.children.add(Container( child: Row( mainAxisAlignment: MainAxisAlignment.start, @@ -443,7 +443,7 @@ class MobileOrderDetailState extends State { child: Container( margin: EdgeInsets.only(top: 10.0, bottom: 10.0), child: Text( - '${order.address}, ${order.consignee}, ${order.phone}', + '${order!.address}, ${order!.consignee}, ${order!.phone}', style: TextStyle( color: Colors.black38, ), @@ -481,7 +481,7 @@ class MobileOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - '${order.cartInfo!.businessInfo!.fullAddress}', + '${order!.cartInfo!.businessInfo!.fullAddress}', style: TextStyle( color: Colors.black38, ), @@ -520,7 +520,7 @@ class MobileOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - '${Utils.timestampToString(context, order.bookedAt!, withTime: true)}', + '${Utils.timestampToString(context, order!.bookedAt!, withTime: true)}', style: TextStyle( color: Colors.black38, ), @@ -558,7 +558,7 @@ class MobileOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - order.shippingMethod == 'pickup' ? S.of(context).pickup : S.of(context).store_delivery, + order!.shippingMethod == 'pickup' ? S.of(context).pickup : S.of(context).store_delivery, style: TextStyle( color: Colors.black38, ), @@ -648,7 +648,7 @@ class MobileOrderDetailState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ Text( - '${order.orderNum}', + '${order!.orderNum}', style: TextStyle( color: Colors.black38, ), @@ -670,7 +670,7 @@ class MobileOrderDetailState extends State { S.of(context).copy, ), onTap: () { - Clipboard.setData(ClipboardData(text: '${order.orderNum}')); + Clipboard.setData(ClipboardData(text: '${order!.orderNum}')); Fluttertoast.showToast( msg: S.of(context).order_number_copied_to_clipboard, toastLength: Toast.LENGTH_SHORT, @@ -715,7 +715,7 @@ class MobileOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - order.payMethod == 0 ? S.of(context).online_payment : S.of(context).pay_on_deliery, + order!.payMethod == 0 ? S.of(context).online_payment : S.of(context).pay_on_deliery, style: TextStyle( color: Colors.black38, ), @@ -756,15 +756,15 @@ class MobileOrderDetailState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ Text( - order.paymentStatus == Constants.PAYMENT_STATUS_PAID ? S.of(context).paid : S.of(context).unpaid, + order!.paymentStatus == Constants.PAYMENT_STATUS_PAID ? S.of(context).paid : S.of(context).unpaid, style: TextStyle( color: Colors.black38, ), ), Container( - margin: order.paymentStatus != Constants.PAYMENT_STATUS_PAID && order.status != Constants.STATUS_CANCELLED ? EdgeInsets.only(left: 10.0, right: 10.0) : EdgeInsets.only(left: 0.0, right: 0.0), - child: order.paymentStatus != Constants.PAYMENT_STATUS_PAID && order.status != Constants.STATUS_CANCELLED ? Text('') : SizedBox.shrink(), - decoration: order.paymentStatus != Constants.PAYMENT_STATUS_PAID && order.status != Constants.STATUS_CANCELLED ? BoxDecoration( + margin: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID && order!.status != Constants.STATUS_CANCELLED ? EdgeInsets.only(left: 10.0, right: 10.0) : EdgeInsets.only(left: 0.0, right: 0.0), + child: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID && order!.status != Constants.STATUS_CANCELLED ? Text('') : SizedBox.shrink(), + decoration: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID && order!.status != Constants.STATUS_CANCELLED ? BoxDecoration( border: Border( left: BorderSide( width: 0.5, @@ -774,16 +774,16 @@ class MobileOrderDetailState extends State { ) : null, ), GestureDetector( - child: order.paymentStatus != Constants.PAYMENT_STATUS_PAID - && order.status != Constants.STATUS_CANCELLED - && order.status != Constants.STATUS_COMPLETE ? Text( + child: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID + && order!.status != Constants.STATUS_CANCELLED + && order!.status != Constants.STATUS_COMPLETE ? Text( S.of(context).pay_now, style: TextStyle( fontWeight: FontWeight.bold, ), ) : SizedBox.shrink(), onTap: () { - Routes.router.navigateTo(context, '/paynow/${order.id}'); + Routes.router.navigateTo(context, '/paynow/${order!.id}'); }, ), ], @@ -821,7 +821,7 @@ class MobileOrderDetailState extends State { margin: EdgeInsets.only(top: 10.0, bottom: 10.0), alignment: Alignment.centerRight, child: Text( - Utils.timestampToString(context, order.createdAt!, withTime: true), + Utils.timestampToString(context, order!.createdAt!, withTime: true), style: TextStyle( color: Colors.black38, ), @@ -877,7 +877,7 @@ class MobileOrderDetailState extends State { ), ), Text( - Utils.getOrderStatus(context, order.status!), + Utils.getOrderStatus(context, order!.status!), maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( @@ -899,7 +899,7 @@ class MobileOrderDetailState extends State { ), ),); - for (Fulfillment fulfillment in order.fulfillments!) { + for (Fulfillment fulfillment in order!.fulfillments!) { col.children.add(Container( padding: EdgeInsets.only(top: 10.0, bottom: 10.0), width: double.infinity, @@ -983,7 +983,7 @@ class MobileOrderDetailState extends State { children: [ Container( padding: EdgeInsets.only(right: 10.0), - child: order.status == Constants.STATUS_PENDING && order.paymentStatus == Constants.PAYMENT_STATUS_UNPAID ? + child: order!.status == Constants.STATUS_PENDING && order!.paymentStatus == Constants.PAYMENT_STATUS_UNPAID ? TextButton( child: Text( S.of(context).cancel_order, @@ -994,34 +994,34 @@ class MobileOrderDetailState extends State { ) : SizedBox.shrink(), ), Container( - child: order.status == Constants.STATUS_COMPLETE && !order.hasComment ? ElevatedButton( + child: order!.status == Constants.STATUS_COMPLETE && order!.hasComment != true ? ElevatedButton( child: Text( S.of(context).comment, ), onPressed: () { - Routes.router.navigateTo(context, '/new-comment/${order.id}'); + Routes.router.navigateTo(context, '/new-comment/${order!.id}'); }, ) : SizedBox.shrink(), ), ], ), Container( - child: order.paymentStatus != Constants.PAYMENT_STATUS_PAID - && order.status != Constants.STATUS_CANCELLED - && order.status != Constants.STATUS_COMPLETE ? + child: order!.paymentStatus != Constants.PAYMENT_STATUS_PAID + && order!.status != Constants.STATUS_CANCELLED + && order!.status != Constants.STATUS_COMPLETE ? TextButton( child: Text( S.of(context).pay_now, ), onPressed: () { - Routes.router.navigateTo(context, '/paynow/${order.id}'); + Routes.router.navigateTo(context, '/paynow/${order!.id}'); }, ) : TextButton( child: Text( S.of(context).order_again, ), onPressed: () { - Utils.orderAgain(context, order.cartInfo!); + Utils.orderAgain(context, order!.cartInfo!); }, ), ), @@ -1059,13 +1059,13 @@ class MobileOrderDetailState extends State { order = Order.fromJson(data); if (!kIsWeb) { - if (order.shippingMethod == 'store-delivery' && order.status != Constants.STATUS_COMPLETE && order.status != Constants.STATUS_CANCELLED) { - storeLatLng = LatLng(double.parse(order.businessInfo!.address!.lat!), - double.parse(order.businessInfo!.address!.lng!)); - customerLatLng = LatLng(double.parse(order.shippingAddress!.lat!), - double.parse(order.shippingAddress!.lng!)); + if (order!.shippingMethod == 'store-delivery' && order!.status != Constants.STATUS_COMPLETE && order!.status != Constants.STATUS_CANCELLED) { + storeLatLng = LatLng(double.parse(order!.businessInfo!.address!.lat!), + double.parse(order!.businessInfo!.address!.lng!)); + customerLatLng = LatLng(double.parse(order!.shippingAddress!.lat!), + double.parse(order!.shippingAddress!.lng!)); deliveryLatLng = - LatLng(order.shipperPosition!.lat!, order.shipperPosition!.lng!); + LatLng(order!.shipperPosition!.lat!, order!.shipperPosition!.lng!); _polyLine.clear(); _polyLine.add( @@ -1078,7 +1078,7 @@ class MobileOrderDetailState extends State { ], width: 3, points: [ - order.shipperPosition!.lat != 0.0 ? deliveryLatLng : storeLatLng, + order!.shipperPosition!.lat != 0.0 ? deliveryLatLng : storeLatLng, customerLatLng, ] ) @@ -1103,12 +1103,12 @@ class MobileOrderDetailState extends State { title: S .of(context) .customer, - snippet: order.shippingAddress!.addressLine1, + snippet: order!.shippingAddress!.addressLine1, ), icon: homeIcon, )); - if (order.shipperPosition!.lat != 0.0 && - order.shipperPosition!.lng != 0.0) { + if (order!.shipperPosition!.lat != 0.0 && + order!.shipperPosition!.lng != 0.0) { _markers.add(Marker( markerId: MarkerId('shipper_position'), position: deliveryLatLng,