diff --git a/lib/core/service/parmacyModule/order-preview-service.dart b/lib/core/service/parmacyModule/order-preview-service.dart index 0ada84e7..0364d64f 100644 --- a/lib/core/service/parmacyModule/order-preview-service.dart +++ b/lib/core/service/parmacyModule/order-preview-service.dart @@ -62,6 +62,8 @@ class OrderPreviewService extends BaseService { Future getShoppingCart() async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); + if (customerId == null) return null; + Map queryParams = {'shopping_cart_type': '1'}; dynamic localRes; hasError = false; @@ -94,8 +96,8 @@ class OrderPreviewService extends BaseService { Map body = Map(); body["shopping_cart_item"] = choppingCartObject; - await baseAppClient.pharmacyPost("$GET_SHOPPING_CART$productId", isExternal: false, - onSuccess: (response, statusCode) async { + await baseAppClient.pharmacyPost("$GET_SHOPPING_CART$productId", + isExternal: false, onSuccess: (response, statusCode) async { localRes = response; }, onFailure: (String error, int statusCode) { hasError = true; @@ -112,8 +114,8 @@ class OrderPreviewService extends BaseService { Map body = Map(); - await baseAppClient.pharmacyPost("$DELETE_SHOPPING_CART$productId", isExternal: false, - onSuccess: (response, statusCode) async { + await baseAppClient.pharmacyPost("$DELETE_SHOPPING_CART$productId", + isExternal: false, onSuccess: (response, statusCode) async { localRes = response; }, onFailure: (String error, int statusCode) { hasError = true; @@ -225,8 +227,9 @@ class OrderPreviewService extends BaseService { body['order'] = orderBody; try { - await baseAppClient.pharmacyPost(ORDER_SHOPPING_CART, isExternal: false, isAllowAny: true, - onSuccess: (response, statusCode) async { + await baseAppClient.pharmacyPost(ORDER_SHOPPING_CART, + isExternal: false, + isAllowAny: true, onSuccess: (response, statusCode) async { orderList.clear(); response['orders'].forEach((item) { orderList.add(OrderDetailModel.fromJson(item)); @@ -263,24 +266,22 @@ class OrderPreviewService extends BaseService { } } - Future getDriverLocation(dynamic driverId) async{ + Future getDriverLocation(dynamic driverId) async { Map jsonBody = Map(); jsonBody['DriverID'] = driverId; LatLng coordinates; await baseAppClient.post(DRIVER_LOCATION, onSuccess: (response, statusCode) async { - if(statusCode == 200){ - dynamic locationObject = response['PatientER_GetDriverLocationList'][0]; - double lat = locationObject['Latitude']; - double lon = locationObject['Longitude']; - if(lat != null && lon != null){ - coordinates = LatLng(lat,lon); - } - } - }, onFailure: (String error, int statusCode) { - - }, body: jsonBody); + if (statusCode == 200) { + dynamic locationObject = response['PatientER_GetDriverLocationList'][0]; + double lat = locationObject['Latitude']; + double lon = locationObject['Longitude']; + if (lat != null && lon != null) { + coordinates = LatLng(lat, lon); + } + } + }, onFailure: (String error, int statusCode) {}, body: jsonBody); return coordinates; } diff --git a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart index 9bcfd490..801f6fb7 100644 --- a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart @@ -9,6 +9,8 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/payment-checkout-data.dart'; import 'package:diplomaticquarterapp/core/service/parmacyModule/order-preview-service.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; +import 'package:diplomaticquarterapp/uitl/navigation_service.dart'; import '../../../locator.dart'; import '../base_view_model.dart'; @@ -17,12 +19,14 @@ class OrderPreviewViewModel extends BaseViewModel { OrderPreviewService _orderService = locator(); List get addresses => _orderService.addresses; + LacumAccountInformation get lacumInformation => _orderService.lacumInformation; + List get orderListModel => _orderService.orderList; PharmacyModuleViewModel pharmacyModuleViewModel = - locator(); + locator(); ShoppingCartResponse cartResponse = ShoppingCartResponse(); PaymentCheckoutData paymentCheckoutData = PaymentCheckoutData(); @@ -38,24 +42,31 @@ class OrderPreviewViewModel extends BaseViewModel { getShoppingCart(); } } - + void update(){ + notifyListeners(); + } Future getShoppingCart() async { - setState(ViewState.Busy); + // setState(ViewState.Busy); + // GifLoaderDialogUtils.showMyDialog( + // locator().navigatorKey.currentContext); await _orderService.getShoppingCart().then((res) { - _handleGetShoppingCartResponse(res); + if (res != null) _handleGetShoppingCartResponse(res); }); if (_orderService.hasError) { error = _orderService.error; - setState(ViewState.Error); + // setState(ViewState.Error); } else { if (paymentCheckoutData != null) { paymentCheckoutData.cartDataVisible = true; } - setState(ViewState.Idle); + // GifLoaderDialogUtils.hideDialog( + // locator().navigatorKey.currentContext); + setState(ViewState.Idle); } } - Future changeProductQuantity(ShoppingCart product) async { + Future changeProductQuantity( + ShoppingCart product) async { setState(ViewState.Busy); var resp = await _orderService.changeProductQuantity(product.id, product); var object = _handleGetShoppingCartResponse(resp); @@ -112,7 +123,8 @@ class OrderPreviewViewModel extends BaseViewModel { res["shopping_carts"].forEach((item) { ShoppingCart shoppingCart = ShoppingCart.fromJson(item); cartResponse.shoppingCarts.add(shoppingCart); - totalAdditionalShippingCharge += shoppingCart.product.additionalShippingCharge; + totalAdditionalShippingCharge += + shoppingCart.product.additionalShippingCharge; }); return cartResponse; } @@ -164,7 +176,8 @@ class OrderPreviewViewModel extends BaseViewModel { setState(ViewState.Busy); await _orderService.getLacumGroupInformation(); paymentCheckoutData.lacumInformation = _orderService.lacumGroupInformation; - paymentCheckoutData.usedLakumPoints = paymentCheckoutData.lacumInformation.lakumInquiryInformationObjVersion.pointsBalanceAmount; + paymentCheckoutData.usedLakumPoints = paymentCheckoutData + .lacumInformation.lakumInquiryInformationObjVersion.pointsBalanceAmount; if (_orderService.hasError) { error = _orderService.error; setState(ViewState.Error); @@ -175,8 +188,10 @@ class OrderPreviewViewModel extends BaseViewModel { getShippingOption() async { setState(ViewState.Busy); - await _orderService.getShippingOption(paymentCheckoutData.address).then((res) { - paymentCheckoutData.shippingOption = ShippingOption.fromJson(res); + await _orderService + .getShippingOption(paymentCheckoutData.address) + .then((res) { + paymentCheckoutData.shippingOption = ShippingOption.fromJson(res); paymentCheckoutData.updateData(); }); if (_orderService.hasError) { @@ -191,7 +206,8 @@ class OrderPreviewViewModel extends BaseViewModel { setState(ViewState.Busy); await pharmacyModuleViewModel.generatePharmacyToken(); - await _orderService.makeOrder(paymentCheckoutData, cartResponse.shoppingCarts); + await _orderService.makeOrder( + paymentCheckoutData, cartResponse.shoppingCarts); if (_orderService.hasError) { error = _orderService.error; setState(ViewState.ErrorLocal); diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 2fc2100c..a77aaa1c 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -68,11 +68,10 @@ class _Login extends State { if(BASE_URL.contains("uat.")){ nationalIDorFile.text = "2001273"; mobileNumberController.text = mobileNo = "0555416043"; - } else { - // TODO Mousa Sheeeloh + }/* else { nationalIDorFile.text = "3376044"; mobileNumberController.text = mobileNo = "0555416575"; - } + }*/ } getDeviceToken() async { diff --git a/lib/pages/pharmacies/screens/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-order-page.dart index e53175b8..6f63927d 100644 --- a/lib/pages/pharmacies/screens/cart-order-page.dart +++ b/lib/pages/pharmacies/screens/cart-order-page.dart @@ -7,6 +7,7 @@ import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-order-preview.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/pharmacy-terms-conditions-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductOrderItem.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/widgets/buttons/GestureIconButton.dart'; @@ -15,6 +16,7 @@ import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; +import 'package:http/http.dart'; import 'package:provider/provider.dart'; class CartOrderPage extends StatefulWidget { @@ -25,13 +27,14 @@ class CartOrderPage extends StatefulWidget { class _CartOrderPageState extends State { - + bool isLoading = true; @override void initState() { super.initState(); - Provider.of(context, listen: false).getShoppingCart(); + getData(); } + @override Widget build(BuildContext context) { final mediaQuery = MediaQuery.of(context); @@ -40,7 +43,9 @@ class _CartOrderPageState extends State { final height = mediaQuery.size.height - 60 - mediaQuery.padding.top; AppScaffold appScaffold; return NetworkBaseView( - baseViewModel: model, + // baseViewModel: model, + isLoading: isLoading, + isLocalLoader: true, child: AppScaffold( appBarTitle: TranslationBase.of(context).shoppingCart, isShowAppBar: true, @@ -245,6 +250,15 @@ class _CartOrderPageState extends State { ), ); } + + void getData()async { + + await Provider.of(context, listen: false).getShoppingCart(); + setState(() { + isLoading= false; + }); + + } } class OrderBottomWidget extends StatefulWidget { diff --git a/lib/pages/pharmacies/screens/cart-order-preview.dart b/lib/pages/pharmacies/screens/cart-order-preview.dart index 2c7e6f42..f6e1d392 100644 --- a/lib/pages/pharmacies/screens/cart-order-preview.dart +++ b/lib/pages/pharmacies/screens/cart-order-preview.dart @@ -31,236 +31,213 @@ class OrderPreviewPage extends StatefulWidget { class _OrderPreviewPageState extends State { MyInAppBrowser browser; + bool isLoading = true; @override void initState() { super.initState(); - Provider.of(context, listen: false).getShoppingCart(); + getData(); } + + void getData() async { + if (isLoading) + await Provider.of(context, listen: false) + .getShoppingCart(); + setState(() { + isLoading = false; + }); + } + @override Widget build(BuildContext context) { + final mediaQuery = MediaQuery.of(context); final height = mediaQuery.size.height - 60 - mediaQuery.padding.top; - OrderPreviewViewModel model = Provider.of(context); - return NetworkBaseView( - child: AppScaffold( - appBarTitle: "${TranslationBase.of(context).checkOut}", - isShowAppBar: true, - isPharmacy: true, - isShowDecPage: false, - backgroundColor: Colors.white, - baseViewModel: model, - body: Container( - height: height * 0.90, - child: SingleChildScrollView( - child: Container( - color: Color(0xFFF1F1F1), - child: Column( - children: [ - SelectAddressWidget(model,widget.addresses), - SizedBox( - height: 10, - ), - SelectPaymentOptionWidget(model), - SizedBox( - height: 10, - ), - Consumer( - builder: (ctx, paymentData, _) => - paymentData.lacumInformation != null - ? Container( - child: Column( - children: [ - LakumWidget(model), - SizedBox( - height: 10, - ), - ], - ), - ) - : Container()), - Container( - color: Colors.white, - width: double.infinity, - padding: EdgeInsets.all(8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Texts( - TranslationBase - .of(context) - .reviewOrder, - fontSize: 14, - fontWeight: FontWeight.bold, - color: Colors.black, - ), - ...List.generate( - model.cartResponse.shoppingCarts != null - ? model.cartResponse.shoppingCarts.length - : 0, - (index) => - ProductOrderPreviewItem( - model.cartResponse - .shoppingCarts[index]), - ), - ], - ), + OrderPreviewViewModel model = Provider.of(context); + return AppScaffold( + appBarTitle: "${TranslationBase.of(context).checkOut}", + isShowAppBar: true, + isPharmacy: true, + isShowDecPage: false, + isLoading: isLoading, + isLocalLoader: true, + backgroundColor: Colors.white, + // baseViewModel: model, + body: Container( + color: Color(0xFFF1F1F1), + height: height * 0.90, + child: SingleChildScrollView( + child: Container( + color: Color(0xFFF1F1F1), + child: Column( + children: [ + SelectAddressWidget(model, widget.addresses), + SizedBox( + height: 10, + ), + SelectPaymentOptionWidget(model), + SizedBox( + height: 10, + ), + Consumer( + builder: (ctx, paymentData, _) => + paymentData.lacumInformation != null + ? Container( + child: Column( + children: [ + LakumWidget(model), + SizedBox( + height: 10, + ), + ], + ), + ) + : Container()), + Container( + color: Colors.white, + width: double.infinity, + padding: EdgeInsets.all(8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Texts( + TranslationBase.of(context).reviewOrder, + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ...List.generate( + model.cartResponse.shoppingCarts != null + ? model.cartResponse.shoppingCarts.length + : 0, + (index) => ProductOrderPreviewItem( + model.cartResponse.shoppingCarts[index]), + ), + ], ), - Container( - width: double.infinity, - padding: EdgeInsets.all(8), - child: model.cartResponse.subtotal != null - ? Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Texts( - TranslationBase - .of(context) - .orderSummary, - fontSize: 14, - fontWeight: FontWeight.bold, - color: Colors.black, - ), - SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, + ), + Container( + width: double.infinity, + padding: EdgeInsets.all(8), + child: model.cartResponse.subtotal != null + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Texts( - "${TranslationBase - .of(context) - .subtotal}", + TranslationBase.of(context).orderSummary, fontSize: 14, + fontWeight: FontWeight.bold, color: Colors.black, - fontWeight: FontWeight.w500, ), - Texts( - "${TranslationBase - .of(context) - .sar} ${(model.cartResponse.subtotal) - .toStringAsFixed(2)}", - fontSize: 14, - color: Colors.black, - fontWeight: FontWeight.w500, + SizedBox( + height: 20, ), - ], - ), - const Divider( - color: Color(0xFFD6D6D6), - height: 20, - thickness: 1, - indent: 0, - endIndent: 0, - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Texts( - "${TranslationBase - .of(context) - .shipping}", - fontSize: 14, - color: Colors.black, - fontWeight: FontWeight.w500, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + "${TranslationBase.of(context).subtotal}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + Texts( + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ], ), - Texts( - "${TranslationBase - .of(context) - .sar} ${(model - .totalAdditionalShippingCharge) - .toStringAsFixed(2)}", - fontSize: 14, - color: Colors.black, - fontWeight: FontWeight.w500, + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 1, + indent: 0, + endIndent: 0, ), - ], - ), - const Divider( - color: Color(0xFFD6D6D6), - height: 20, - thickness: 1, - indent: 0, - endIndent: 0, - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Texts( - "${TranslationBase - .of(context) - .vat}", - fontSize: 14, - color: Colors.black, - fontWeight: FontWeight.w500, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + "${TranslationBase.of(context).shipping}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + Texts( + "${TranslationBase.of(context).sar} ${(model.totalAdditionalShippingCharge).toStringAsFixed(2)}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ], ), - Texts( - "${TranslationBase - .of(context) - .sar} ${(model.cartResponse - .subtotalVatAmount).toStringAsFixed( - 2)}", - fontSize: 14, - color: Colors.black, - fontWeight: FontWeight.w500, + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 1, + indent: 0, + endIndent: 0, ), - ], - ), - const Divider( - color: Color(0xFFD6D6D6), - height: 20, - thickness: 1, - indent: 0, - endIndent: 0, - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Texts( - TranslationBase - .of(context) - .total, - fontSize: 14, - color: Colors.black, - fontWeight: FontWeight.bold, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + "${TranslationBase.of(context).vat}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + Texts( + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotalVatAmount).toStringAsFixed(2)}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ], ), - Texts( - "${TranslationBase - .of(context) - .sar} ${(model.cartResponse.subtotal) - .toStringAsFixed(2)}", - fontSize: 14, - color: Colors.black, - fontWeight: FontWeight.bold, + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 1, + indent: 0, + endIndent: 0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + TranslationBase.of(context).total, + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.bold, + ), + Texts( + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.bold, + ), + ], + ), + SizedBox( + height: 10, ), ], - ), - SizedBox( - height: 10, - ), - ], - ) - : Container(), - ) - ], - ), + ) + : Container(), + ) + ], ), ), ), - bottomSheet: Container( - height: model.cartResponse.shoppingCarts != null - ? height * 0.10 - : 0, - color: Colors.white, - child: PaymentBottomWidget(model), - ), ), - baseViewModel: model, + bottomSheet: Container( + height: model.cartResponse.shoppingCarts != null ? height * 0.10 : 0, + color: Colors.white, + child: PaymentBottomWidget(model), + ), ); } } @@ -308,172 +285,161 @@ class _SelectAddressWidgetState extends State { @override Widget build(BuildContext context) { return Consumer( - builder: (ctx, paymentData, _) => - Container( - color: Colors.white, - child: address == null - ? InkWell( - onTap: () => {_navigateToAddressPage()}, - child: Container( - margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), - child: Row( - children: [ - Image.asset( - "assets/images/pharmacy_module/ic_shipping_address.png", - width: 30.0, - height: 30.0, - fit: BoxFit.scaleDown, - ), - Expanded( - child: Container( - padding: - EdgeInsets.symmetric(vertical: 0, horizontal: 6), - child: Texts( - TranslationBase - .of(context) - .selectAddress, - fontSize: 14, - fontWeight: FontWeight.bold, - color: Color(0xff0000ff), - ), + builder: (ctx, paymentData, _) => Container( + color: Colors.white, + child: address == null + ? InkWell( + onTap: () => {_navigateToAddressPage()}, + child: Container( + margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), + child: Row( + children: [ + Image.asset( + "assets/images/pharmacy_module/ic_shipping_address.png", + width: 30.0, + height: 30.0, + fit: BoxFit.scaleDown, ), - ), - Icon( - Icons.arrow_forward_ios, - size: 20, - color: Colors.grey.shade400, - ), - ], - ), - ), - ) - : Container( - child: Container( - margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Image.asset( - "assets/images/pharmacy_module/ic_shipping_mark.png", - width: 30.0, - height: 30.0, - fit: BoxFit.scaleDown, - ), - Expanded( - child: Container( - padding: EdgeInsets.symmetric( - vertical: 0, horizontal: 6), - child: Texts( - TranslationBase - .of(context) - .shippingAddress, - fontSize: 14, - fontWeight: FontWeight.bold, - color: Colors.black, - ), - ), - ), - InkWell( - onTap: () => {_navigateToAddressPage()}, + Expanded( + child: Container( + padding: + EdgeInsets.symmetric(vertical: 0, horizontal: 6), child: Texts( - TranslationBase - .of(context) - .changeAddress, - fontSize: 12, - fontWeight: FontWeight.normal, + TranslationBase.of(context).selectAddress, + fontSize: 14, + fontWeight: FontWeight.bold, color: Color(0xff0000ff), ), ), - ], - ), - Padding( - padding: const EdgeInsets.symmetric(vertical: 8), - child: Texts( - "${address.firstName} ${address.lastName}", - fontSize: 14, - fontWeight: FontWeight.bold, - color: Colors.black, ), - ), - Padding( - padding: const EdgeInsets.symmetric(vertical: 8), - child: Texts( - "${address.address1} ${address.address2} ${address - .address2},, ${address.city}, ${address - .country} ${address.zipPostalCode}", - fontSize: 12, - fontWeight: FontWeight.normal, - color: Colors.grey.shade500, + Icon( + Icons.arrow_forward_ios, + size: 20, + color: Colors.grey.shade400, ), - ), - Row( - children: [ - Container( - margin: const EdgeInsets.only(right: 8), - child: Icon( - Icons.phone, - size: 20, - color: Colors.black, + ], + ), + ), + ) + : Container( + child: Container( + margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Image.asset( + "assets/images/pharmacy_module/ic_shipping_mark.png", + width: 30.0, + height: 30.0, + fit: BoxFit.scaleDown, ), - ), - Texts( - "${address.phoneNumber}", + Expanded( + child: Container( + padding: EdgeInsets.symmetric( + vertical: 0, horizontal: 6), + child: Texts( + TranslationBase.of(context).shippingAddress, + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + ), + InkWell( + onTap: () => {_navigateToAddressPage()}, + child: Texts( + TranslationBase.of(context).changeAddress, + fontSize: 12, + fontWeight: FontWeight.normal, + color: Color(0xff0000ff), + ), + ), + ], + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: Texts( + "${address.firstName} ${address.lastName}", fontSize: 14, fontWeight: FontWeight.bold, - color: Colors.grey, - ), - ], - ), - Container( - margin: EdgeInsets.symmetric(vertical: 8), - child: SizedBox( - height: 2, - width: double.infinity, - child: Container( - color: Color(0xffefefef), + color: Colors.black, ), ), - ), - Row( - children: [ - Image.asset( - "assets/images/pharmacy_module/ic_shipping_truck.png", - width: 30.0, - height: 30.0, - fit: BoxFit.scaleDown, + Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: Texts( + "${address.address1} ${address.address2} ${address.address2},, ${address.city}, ${address.country} ${address.zipPostalCode}", + fontSize: 12, + fontWeight: FontWeight.normal, + color: Colors.grey.shade500, ), - Container( - padding: EdgeInsets.symmetric( - vertical: 0, horizontal: 6), - child: Texts( - "${TranslationBase - .of(context) - .shipBy}", - fontSize: 12, + ), + Row( + children: [ + Container( + margin: const EdgeInsets.only(right: 8), + child: Icon( + Icons.phone, + size: 20, + color: Colors.black, + ), + ), + Texts( + "${address.phoneNumber}", + fontSize: 14, fontWeight: FontWeight.bold, - color: Colors.black, + color: Colors.grey, ), - ), - Container( - child: Image.asset( - paymentData.shippingOption - .shippingRateComputationMethodSystemName == - "Shipping.FixedOrByWeight" - ? "assets/images/pharmacy_module/payment/hmg_shipping_logo.png" - : "assets/images/pharmacy_module/payment/aramex_shipping_logo.png", - fit: BoxFit.contain, + ], + ), + Container( + margin: EdgeInsets.symmetric(vertical: 8), + child: SizedBox( + height: 2, + width: double.infinity, + child: Container( + color: Color(0xffefefef), ), - margin: EdgeInsets.symmetric(horizontal: 8), ), - ], - ), - ], + ), + Row( + children: [ + Image.asset( + "assets/images/pharmacy_module/ic_shipping_truck.png", + width: 30.0, + height: 30.0, + fit: BoxFit.scaleDown, + ), + Container( + padding: EdgeInsets.symmetric( + vertical: 0, horizontal: 6), + child: Texts( + "${TranslationBase.of(context).shipBy}", + fontSize: 12, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + Container( + child: Image.asset( + paymentData.shippingOption + .shippingRateComputationMethodSystemName == + "Shipping.FixedOrByWeight" + ? "assets/images/pharmacy_module/payment/hmg_shipping_logo.png" + : "assets/images/pharmacy_module/payment/aramex_shipping_logo.png", + fit: BoxFit.contain, + ), + margin: EdgeInsets.symmetric(horizontal: 8), + ), + ], + ), + ], + ), ), - ), - ), // ic_shipping_mark.png - ), + ), // ic_shipping_mark.png + ), ); } } @@ -493,17 +459,16 @@ class _SelectPaymentOptionWidgetState extends State { _navigateToPaymentOption() { Navigator.push(context, FadePage(page: PaymentMethodSelectPage())) - .then((result) => - { - setState(() { - if (result != null) { - paymentOption = result; - widget.model.paymentCheckoutData.paymentOption = - paymentOption; - widget.model.paymentCheckoutData.updateData(); - } - }) - }); + .then((result) => { + setState(() { + if (result != null) { + paymentOption = result; + widget.model.paymentCheckoutData.paymentOption = + paymentOption; + widget.model.paymentCheckoutData.updateData(); + } + }) + }); } @override @@ -520,89 +485,85 @@ class _SelectPaymentOptionWidgetState extends State { color: Colors.white, child: paymentOption == null ? InkWell( - onTap: () => {_navigateToPaymentOption()}, - child: Container( - margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), - child: Row( - children: [ - Image.asset( - "assets/images/pharmacy_module/ic_payment_option.png", - width: 30.0, - height: 30.0, - fit: BoxFit.scaleDown, - ), - Expanded( - child: Container( - padding: - EdgeInsets.symmetric(vertical: 0, horizontal: 6), - child: Texts( - TranslationBase - .of(context) - .selectPaymentOption, - fontSize: 14, - fontWeight: FontWeight.bold, - color: Color(0xff0000ff), - ), - ), - ), - Icon( - Icons.arrow_forward_ios, - size: 20, - color: Colors.grey.shade400, - ), - ], - ), - ), - ) - : Container( - margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), - child: Row( - children: [ - Image.asset( - "assets/images/pharmacy_module/ic_payment_option.png", - width: 30.0, - height: 30.0, - fit: BoxFit.scaleDown, - ), - Container( - margin: EdgeInsets.symmetric(horizontal: 8), - padding: EdgeInsets.symmetric(horizontal: 4, vertical: 0), - decoration: new BoxDecoration( - color: Colors.grey.shade100, - shape: BoxShape.rectangle, - ), - child: Image.asset( - widget.model.getPaymentOptionImage(paymentOption), - width: 30.0, - height: 30.0, - fit: BoxFit.scaleDown, - ), - ), - Expanded( + onTap: () => {_navigateToPaymentOption()}, child: Container( - padding: EdgeInsets.symmetric(vertical: 0, horizontal: 6), - child: Texts( - widget.model.getPaymentOptionName(paymentOption), - fontSize: 14, - fontWeight: FontWeight.bold, - color: Colors.black, + margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), + child: Row( + children: [ + Image.asset( + "assets/images/pharmacy_module/ic_payment_option.png", + width: 30.0, + height: 30.0, + fit: BoxFit.scaleDown, + ), + Expanded( + child: Container( + padding: + EdgeInsets.symmetric(vertical: 0, horizontal: 6), + child: Texts( + TranslationBase.of(context).selectPaymentOption, + fontSize: 14, + fontWeight: FontWeight.bold, + color: Color(0xff0000ff), + ), + ), + ), + Icon( + Icons.arrow_forward_ios, + size: 20, + color: Colors.grey.shade400, + ), + ], ), ), - ), - InkWell( - onTap: () => {_navigateToPaymentOption()}, - child: Texts( - TranslationBase - .of(context) - .changeMethod, - fontSize: 12, - fontWeight: FontWeight.normal, - color: Color(0xff0000ff), + ) + : Container( + margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), + child: Row( + children: [ + Image.asset( + "assets/images/pharmacy_module/ic_payment_option.png", + width: 30.0, + height: 30.0, + fit: BoxFit.scaleDown, + ), + Container( + margin: EdgeInsets.symmetric(horizontal: 8), + padding: EdgeInsets.symmetric(horizontal: 4, vertical: 0), + decoration: new BoxDecoration( + color: Colors.grey.shade100, + shape: BoxShape.rectangle, + ), + child: Image.asset( + widget.model.getPaymentOptionImage(paymentOption), + width: 30.0, + height: 30.0, + fit: BoxFit.scaleDown, + ), + ), + Expanded( + child: Container( + padding: EdgeInsets.symmetric(vertical: 0, horizontal: 6), + child: Texts( + widget.model.getPaymentOptionName(paymentOption), + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + ), + InkWell( + onTap: () => {_navigateToPaymentOption()}, + child: Texts( + TranslationBase.of(context).changeMethod, + fontSize: 12, + fontWeight: FontWeight.normal, + color: Color(0xff0000ff), + ), + ), + ], ), ), - ], - ), - ), ); } } @@ -640,15 +601,12 @@ class _LakumWidgetState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Texts( - "${TranslationBase - .of(context) - .lakumPoints}", + "${TranslationBase.of(context).lakumPoints}", fontSize: 12, fontWeight: FontWeight.bold, ), Texts( - "${widget.model.paymentCheckoutData.lacumInformation - .lakumInquiryInformationObjVersion.pointsBalanceAmount}", + "${widget.model.paymentCheckoutData.lacumInformation.lakumInquiryInformationObjVersion.pointsBalanceAmount}", fontSize: 12, fontWeight: FontWeight.normal, ), @@ -663,9 +621,7 @@ class _LakumWidgetState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ Texts( - "${TranslationBase - .of(context) - .riyal}", + "${TranslationBase.of(context).riyal}", fontSize: 12, fontWeight: FontWeight.bold, ), @@ -679,19 +635,19 @@ class _LakumWidgetState extends State { decoration: InputDecoration( border: OutlineInputBorder( borderSide: - BorderSide(color: Colors.black, width: 0.2), + BorderSide(color: Colors.black, width: 0.2), gapPadding: 0, borderRadius: projectProvider.isArabic ? BorderRadius.only( - topRight: Radius.circular(8), - bottomRight: Radius.circular(8)) + topRight: Radius.circular(8), + bottomRight: Radius.circular(8)) : BorderRadius.only( - topLeft: Radius.circular(8), - bottomLeft: Radius.circular(8)), + topLeft: Radius.circular(8), + bottomLeft: Radius.circular(8)), ), disabledBorder: OutlineInputBorder( borderSide: - BorderSide(color: Colors.black, width: 0.4), + BorderSide(color: Colors.black, width: 0.4), gapPadding: 0, borderRadius: BorderRadius.only( topLeft: Radius.circular(8), @@ -703,22 +659,22 @@ class _LakumWidgetState extends State { style: TextStyle( fontSize: 14, color: widget - .model - .paymentCheckoutData - .lacumInformation - .lakumInquiryInformationObjVersion - .pointsBalanceAmount > - 0 + .model + .paymentCheckoutData + .lacumInformation + .lakumInquiryInformationObjVersion + .pointsBalanceAmount > + 0 ? Colors.black : Colors.grey, ), enabled: widget - .model - .paymentCheckoutData - .lacumInformation - .lakumInquiryInformationObjVersion - .pointsBalanceAmount == - 0 + .model + .paymentCheckoutData + .lacumInformation + .lakumInquiryInformationObjVersion + .pointsBalanceAmount == + 0 ? false : true, onChanged: (val) { @@ -737,7 +693,7 @@ class _LakumWidgetState extends State { widget.model.paymentCheckoutData.usedLakumPoints = 0; } _pointsController.text = - "${widget.model.paymentCheckoutData.usedLakumPoints}"; + "${widget.model.paymentCheckoutData.usedLakumPoints}"; }, ), ), @@ -749,20 +705,18 @@ class _LakumWidgetState extends State { shape: BoxShape.rectangle, borderRadius: projectProvider.isArabic ? BorderRadius.only( - topLeft: Radius.circular(6), - bottomLeft: Radius.circular(6)) + topLeft: Radius.circular(6), + bottomLeft: Radius.circular(6)) : BorderRadius.only( - topRight: Radius.circular(6), - bottomRight: Radius.circular(6)), + topRight: Radius.circular(6), + bottomRight: Radius.circular(6)), border: Border.fromBorderSide(BorderSide( color: Color(0xff3666E0), width: 0.8, )), ), child: Texts( - "${TranslationBase - .of(context) - .use}", + "${TranslationBase.of(context).use}", fontSize: 12, color: Colors.white, fontWeight: FontWeight.bold, @@ -794,114 +748,108 @@ class PaymentBottomWidget extends StatelessWidget { return Container( margin: EdgeInsets.symmetric(horizontal: 10, vertical: 0), child: Consumer( - builder: (ctx, paymentData, _) => - paymentData.cartDataVisible + builder: (ctx, paymentData, _) => paymentData.cartDataVisible ? Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Container( - margin: - EdgeInsets.symmetric(horizontal: 0, vertical: 4), - child: Row( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Container( + margin: + EdgeInsets.symmetric(horizontal: 0, vertical: 4), + child: Row( + children: [ + Texts( + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", + fontSize: 14, + fontWeight: FontWeight.bold, + color: Color(0xff929295), + ), + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 4), + child: Texts( + "${TranslationBase.of(context).inclusiveVat}", + fontSize: 8, + color: Color(0xff929295), + fontWeight: FontWeight.w600, + ), + ), + ], + ), + ), Texts( - "${TranslationBase - .of(context) - .sar} ${(model.cartResponse.subtotal) - .toStringAsFixed(2)}", - fontSize: 14, + "${model.cartResponse.quantityCount} ${TranslationBase.of(context).items}", + fontSize: 10, + color: Colors.grey, fontWeight: FontWeight.bold, - color: Color(0xff929295), ), - Padding( - padding: - const EdgeInsets.symmetric(horizontal: 4), - child: Texts( - "${TranslationBase - .of(context) - .inclusiveVat}", - fontSize: 8, + ], + ), + Container( + child: RaisedButton( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( color: Color(0xff929295), - fontWeight: FontWeight.w600, + width: 1, ), ), - ], - ), - ), - Texts( - "${model.cartResponse.quantityCount} ${TranslationBase - .of(context) - .items}", - fontSize: 10, - color: Colors.grey, - fontWeight: FontWeight.bold, - ), - ], - ), - Container( - child: RaisedButton( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - side: BorderSide( - color: Color(0xff929295), - width: 1, - ), - ), - onPressed: (paymentData.address != null && - paymentData.paymentOption != null) - ? () async { - await model.makeOrder(); - if (model.state == ViewState.Idle) { - AppToast.showSuccessToast( - message: "Order has been placed successfully!!"); - openPayment(model.orderListModel[0], model.user); - } else { - AppToast.showErrorToast(message: model.error); - } - Navigator.pop(context); - Navigator.pop(context); - } - : null, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 16), - child: new Text( - "${TranslationBase - .of(context) - .proceedPay}", - style: new TextStyle( - color: (paymentData.address != null && - paymentData.paymentOption != null) - ? Colors.white - : Colors.grey.shade400, - fontWeight: FontWeight.bold, - fontSize: 12), + onPressed: (paymentData.address != null && + paymentData.paymentOption != null) + ? () async { + await model.makeOrder(); + if (model.state == ViewState.Idle) { + AppToast.showSuccessToast( + message: + "Order has been placed successfully!!"); + openPayment( + model.orderListModel[0], model.user); + } else { + AppToast.showErrorToast(message: model.error); + } + Navigator.pop(context); + Navigator.pop(context); + } + : null, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 16), + child: new Text( + "${TranslationBase.of(context).proceedPay}", + style: new TextStyle( + color: (paymentData.address != null && + paymentData.paymentOption != null) + ? Colors.white + : Colors.grey.shade400, + fontWeight: FontWeight.bold, + fontSize: 12), + ), + ), + color: (paymentData.address != null && + paymentData.paymentOption != null) + ? Colors.green + : Color(0xff929295), + disabledColor: (paymentData.address != null && + paymentData.paymentOption != null) + ? Colors.green + : Color(0xff929295), + ), ), - ), - color: (paymentData.address != null && - paymentData.paymentOption != null) - ? Colors.green - : Color(0xff929295), - disabledColor: (paymentData.address != null && - paymentData.paymentOption != null) - ? Colors.green - : Color(0xff929295), + ], ), - ), - ], - ), - ) + ) : Container(), ), ); } - openPayment(OrderDetailModel order, - AuthenticatedUser authenticatedUser,) { + openPayment( + OrderDetailModel order, + AuthenticatedUser authenticatedUser, + ) { browser = new MyInAppBrowser( onExitCallback: onBrowserExit, onLoadStartCallback: onBrowserLoadStart); @@ -912,8 +860,7 @@ class PaymentBottomWidget extends StatelessWidget { order.id, order.billingAddress.email, order.customValuesXml, - "${authenticatedUser.firstName} ${authenticatedUser - .middleName} ${authenticatedUser.lastName}", + "${authenticatedUser.firstName} ${authenticatedUser.middleName} ${authenticatedUser.lastName}", authenticatedUser.patientID, authenticatedUser, browser); @@ -950,7 +897,7 @@ class PaymentBottomWidget extends StatelessWidget { } else { AppToast.showErrorToast( message: - "Transaction Failed!\Your transaction is field to some reason please try again or contact to the administration"); + "Transaction Failed!\Your transaction is field to some reason please try again or contact to the administration"); } } } diff --git a/lib/pages/pharmacies/screens/pharmacy_module_page.dart b/lib/pages/pharmacies/screens/pharmacy_module_page.dart index 02a1a89a..2e71a0c3 100644 --- a/lib/pages/pharmacies/screens/pharmacy_module_page.dart +++ b/lib/pages/pharmacies/screens/pharmacy_module_page.dart @@ -4,6 +4,7 @@ import 'package:diplomaticquarterapp/core/service/parmacyModule/order-preview-se import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/BestSellerViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/BrandViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/LastVisitedViewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/PrescriptionViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; @@ -47,7 +48,7 @@ class PharmacyPage extends StatefulWidget { class _PharmacyPageState extends State { @override Widget build(BuildContext context) { - + OrderPreviewViewModel orderPreviewViewModel = Provider.of(context); return WillPopScope( onWillPop: ()async{ return false; @@ -56,7 +57,8 @@ class _PharmacyPageState extends State { onModelReady: (model) async { await model.getSavedLanguage(); await model.getBannerList(); - await locator().getShoppingCart(); + if(model.isLogin) + await orderPreviewViewModel.getShoppingCart(); }, allowAny: true, builder: (_, model, wi) => AppScaffold( diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index 93bccbd2..b3cc63d7 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -58,6 +58,7 @@ class AppScaffold extends StatelessWidget { final List appBarIcons; final List imagesInfo; final bool isHelp; + final bool isLocalLoader; AuthenticatedUserObject authenticatedUserObject = locator(); @@ -89,7 +90,7 @@ class AppScaffold extends StatelessWidget { this.showHomeAppBarIcon = true, this.imagesInfo, appBar, - this.customAppBar}); + this.customAppBar, this.isLocalLoader= false}); AppScaffold setOnAppBarCartClick(VoidCallback onClick) { _onCartClick = onClick; @@ -146,7 +147,17 @@ class AppScaffold extends StatelessWidget { buildBodyWidget(context) { return Stack( - children: [body, isHelp == true ? RobotIcon() : Container()]); + children: [ + Center( + child:isLoading? CircularProgressIndicator( + backgroundColor: Colors.white, + valueColor: AlwaysStoppedAnimation( + Colors.grey[500], + ), + ):body), + + + isHelp == true ? RobotIcon() : Container()]); } } diff --git a/lib/widgets/others/network_base_view.dart b/lib/widgets/others/network_base_view.dart index 10b4da12..4ce75527 100644 --- a/lib/widgets/others/network_base_view.dart +++ b/lib/widgets/others/network_base_view.dart @@ -10,8 +10,9 @@ class NetworkBaseView extends StatefulWidget { final BaseViewModel baseViewModel; final Widget child; final bool isLocalLoader; + final bool isLoading; - NetworkBaseView({Key key, this.baseViewModel, this.child, this.isLocalLoader = false}); + NetworkBaseView({Key key, this.baseViewModel, this.child, this.isLocalLoader = false, this.isLoading}); @override _NetworkBaseViewState createState() => _NetworkBaseViewState(); @@ -31,7 +32,14 @@ class _NetworkBaseViewState extends State{ @override Widget build(BuildContext context) { return Container( - child: buildBaseViewWidget(), + child: (widget.baseViewModel!=null ) ?buildBaseViewWidget():Center( + child:widget.isLoading? CircularProgressIndicator( + backgroundColor: Colors.white, + valueColor: AlwaysStoppedAnimation( + Colors.grey[500], + ), + ):widget.child, + ) , ); }