diff --git a/lib/config/config.dart b/lib/config/config.dart index c0565ad8..4b591cd8 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -360,6 +360,7 @@ const GET_E_REFERRALS = "Services/Patients.svc/REST/GetEReferrals"; // pharmacy const PHARMACY_VERIFY_CUSTOMER = "epharmacy/api/VerifyCustomer"; +const PHARMACY_GET_COUNTRY = "epharmacy/api/countries"; const PHARMACY_CREATE_CUSTOMER = "epharmacy/api/CreateCustomer"; const GET_PHARMACY_BANNER = "epharmacy/api/promotionbanners"; const GET_PHARMACY_TOP_MANUFACTURER = "epharmacy/api/topmanufacturer"; @@ -368,6 +369,9 @@ const GET_PHARMACY_PRODUCTs_BY_IDS = "epharmacy/api/productsbyids/"; const GET_CUSTOMERS_ADDRESSES = "epharmacy/api/Customers/"; const GET_ORDER = "orders?"; const GET_ORDER_DETAILS = "epharmacy/api/orders/"; +const ADD_CUSTOMER_ADDRESS = "epharmacy/api/addcustomeraddress"; +const EDIT_CUSTOMER_ADDRESS = "epharmacy/api/editcustomeraddress"; +const DELETE_CUSTOMER_ADDRESS = "epharmacy/api/deletecustomeraddress"; const GET_ADDRESS = "Customers/"; const GET_Cancel_ORDER = "cancelorder/"; const GET_SHOPPING_CART = "epharmacy/api/shopping_cart_items/"; diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 7c124afc..c7ac7f74 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -674,9 +674,16 @@ const Map localizedValues = { "shippedMethod": {"en": "SHIP BY:", "ar": " الشحن بواسطة:"}, "orderDetail": {"en": "Order Detail", "ar": " تفاصيل الطلب"}, "orderSummary": {"en": "Order Summary", "ar": " تفاصيل المنتج"}, - "subtotal": {"en": "Subtotal", "ar": " المجموع"}, + "subtotal": {"en": "Subtotal", "ar": " المجموع الفرعي"}, "shipping": {"en": "Shipping", "ar": " الشحن"}, + "shipBy": {"en": "SHIP BY:", "ar": "الشحن عن طريق:"}, + "lakumPoints": {"en": "Lakum Points", "ar": "نقاط لكم"}, + "use": {"en": "USE", "ar": "استخدم"}, + "proceedPay": {"en": "PROCEED TO PAY", "ar": "المتابعة للدفع"}, "vat": {"en": "VAT (15%)", "ar": "(15%) القيمة المضافة"}, + "inclusiveVat": {"en": "(inclusive VAT)", "ar": "(شامل الضريبة)"}, + "items": {"en": "item(s)", "ar": "عنصر"}, + "checkOut": {"en": "CHECK OUT", "ar": "الدفع"}, "sar": {"en": "SAR", "ar": " ر.س "}, "payOnline": {"en": "PAY ONLINE", "ar": "اتمام عملية الدفع "}, "cancelOrder": {"en": "CANCEL ORDER", "ar": "الغاء الطلب "}, @@ -1203,4 +1210,9 @@ const Map localizedValues = { }, + "pharmacyServiceTermsCondition": { + "en": "I agree with the terms of service and I adhere to them unconditionally", + "ar": " أوافق على شروط الخدمة وألتزم بها دون قيد أو شرط" + }, + }; diff --git a/lib/config/shared_pref_kay.dart b/lib/config/shared_pref_kay.dart index 9e57990c..6a65ac26 100644 --- a/lib/config/shared_pref_kay.dart +++ b/lib/config/shared_pref_kay.dart @@ -21,3 +21,4 @@ const THEME_VALUE = 'is_vibration'; const MAIN_USER = 'main-user'; const PHARMACY_LAST_VISITED_PRODUCTS = 'last-visited'; const PHARMACY_CUSTOMER_ID = 'costumer-id'; +const PHARMACY_SELECTED_ADDRESS = 'selected-address'; diff --git a/lib/core/model/pharmacies/Country.dart b/lib/core/model/pharmacies/Country.dart new file mode 100644 index 00000000..77f519d3 --- /dev/null +++ b/lib/core/model/pharmacies/Country.dart @@ -0,0 +1,32 @@ +class CountryData { + int id; + String name; + String namen; + String twoLetterIsoCode; + String threeLetterIsoCode; + + CountryData( + {this.id, + this.name, + this.namen, + this.twoLetterIsoCode, + this.threeLetterIsoCode}); + + CountryData.fromJson(Map json) { + id = json['id']; + name = json['name']; + namen = json['namen']; + twoLetterIsoCode = json['two_letter_iso_code']; + threeLetterIsoCode = json['three_letter_iso_code']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['name'] = this.name; + data['namen'] = this.namen; + data['two_letter_iso_code'] = this.twoLetterIsoCode; + data['three_letter_iso_code'] = this.threeLetterIsoCode; + return data; + } +} diff --git a/lib/core/model/pharmacies/LakumInquiryInformationObjVersion.dart b/lib/core/model/pharmacies/LakumInquiryInformationObjVersion.dart index 809277e1..c609fa0b 100644 --- a/lib/core/model/pharmacies/LakumInquiryInformationObjVersion.dart +++ b/lib/core/model/pharmacies/LakumInquiryInformationObjVersion.dart @@ -27,9 +27,9 @@ class LakumInquiryInformationObjVersion { int transferPoints; List transferPointsAmountPerYear; List transferPointsDetails; - int waitingPoints; - int loyalityAmount; - int loyalityPoints; + dynamic waitingPoints; + dynamic loyalityAmount; + dynamic loyalityPoints; int purchaseRate; LakumInquiryInformationObjVersion( diff --git a/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart b/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart index a2e3b924..485c92fb 100644 --- a/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart @@ -1,24 +1,117 @@ - +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Country.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/pharmacyAddress_service.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyAddressesModel.dart'; +import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; +import 'package:google_maps_place_picker/google_maps_place_picker.dart'; import '../../../locator.dart'; import '../base_view_model.dart'; class PharmacyAddressesViewModel extends BaseViewModel { - PharmacyAddressService _pharmacyAddressService = locator(); - List get address => _pharmacyAddressService.address; + PharmacyAddressService _pharmacyAddressService = + locator(); + + List get addresses => _pharmacyAddressService.addresses; + + int get selectedAddressIndex => _pharmacyAddressService.selectedAddressIndex; + CountryData get country => _pharmacyAddressService.country; + + setSelectedAddressIndex(int index) { + _pharmacyAddressService.selectedAddressIndex = index; + } - Future getAddress(address) async { + Future getAddressesList() async { setState(ViewState.Busy); - await _pharmacyAddressService.getAddress(address); + await _pharmacyAddressService.getAddresses(); if (_pharmacyAddressService.hasError) { error = _pharmacyAddressService.error; setState(ViewState.Error); } else { - print(address.length); + setState(ViewState.Idle); } } -} \ No newline at end of file +/* Future getCountries(String countryName) async { + setState(ViewState.Busy); + await _pharmacyAddressService.getCountries(countryName); + if (_pharmacyAddressService.hasError) { + error = _pharmacyAddressService.error; + // setState(ViewState.Error); + } else { + // setState(ViewState.Idle); + } + }*/ + + Future addEditAddress(PickResult value, Addresses editedAddress) async { + setState(ViewState.Busy); + + Addresses sendingAddress; + + if (editedAddress == null) { + sendingAddress = Addresses(); + sendingAddress.id = "0"; + sendingAddress.firstName = user.firstName; + sendingAddress.lastName = user.lastName; + sendingAddress.email = user.emailAddress; + sendingAddress.company = null; + } else { + sendingAddress = editedAddress; + } + value.addressComponents.forEach((element) { + if (element.types.contains("country")) { + sendingAddress.country = element.longName; + } + if (element.types.contains("administrative_area_level_1")) { + sendingAddress.city = element.longName; + } + if (element.types.contains("postal_code")) { + sendingAddress.zipPostalCode = element.longName; + } + if (element.types.contains("administrative_area_level_2")) { + sendingAddress.province = element.longName; + } + }); + sendingAddress.latLong = value.geometry.location.toString(); + + await _pharmacyAddressService.getCountries(sendingAddress.country); + sendingAddress.countryId = country.id; + sendingAddress.stateProvinceId = null; + sendingAddress.address1 = value.formattedAddress; + sendingAddress.address2 = ""; + sendingAddress.phoneNumber = user.mobileNumber; + sendingAddress.faxNumber = user.faxNumber; + sendingAddress.customerAttributes = ""; + sendingAddress.createdOnUtc = DateTime.now().toString(); + + if (editedAddress == null) { + await _pharmacyAddressService.addCustomerAddress(sendingAddress); + } else { + await _pharmacyAddressService.editCustomerAddress(sendingAddress); + } + + if (_pharmacyAddressService.hasError) { + error = _pharmacyAddressService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } + } + + Future deleteAddresses(Addresses sendingAddress) async { + setState(ViewState.Busy); + await _pharmacyAddressService.deleteCustomerAddress(sendingAddress); + if (_pharmacyAddressService.hasError) { + error = _pharmacyAddressService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } + } + + Future saveSelectedAddressLocally(Addresses selectedAddress) async { + await sharedPref.setObject(PHARMACY_SELECTED_ADDRESS, selectedAddress); + } +} diff --git a/lib/pages/pharmacies/screens/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-order-page.dart index d8a274d7..c5576900 100644 --- a/lib/pages/pharmacies/screens/cart-order-page.dart +++ b/lib/pages/pharmacies/screens/cart-order-page.dart @@ -1,6 +1,7 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; 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'; @@ -95,13 +96,13 @@ class CartOrderPage extends StatelessWidget { MainAxisAlignment.spaceBetween, children: [ Texts( - "Subtotal", + TranslationBase.of(context).subtotal, fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, ), Texts( - "SAR ${(cart.subtotal).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(cart.subtotal).toStringAsFixed(2)}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, @@ -120,13 +121,13 @@ class CartOrderPage extends StatelessWidget { MainAxisAlignment.spaceBetween, children: [ Texts( - "VAT (15%)", + "${TranslationBase.of(context).vat}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, ), Texts( - "SAR ${(cart.subtotalVatAmount).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(cart.subtotalVatAmount).toStringAsFixed(2)}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, @@ -151,7 +152,7 @@ class CartOrderPage extends StatelessWidget { fontWeight: FontWeight.bold, ), Texts( - "SAR ${(cart.subtotal).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(cart.subtotal).toStringAsFixed(2)}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.bold, @@ -181,7 +182,9 @@ class CartOrderPage extends StatelessWidget { : Container(), bottomSheet: Container( height: !(model.cartResponse.shoppingCarts == null || - model.cartResponse.shoppingCarts.length == 0) ? height * 0.15 : 0, + model.cartResponse.shoppingCarts.length == 0) + ? height * 0.15 + : 0, color: Colors.white, child: OrderBottomWidget(model.addresses, height), ), @@ -206,6 +209,8 @@ class _OrderBottomWidgetState extends State { @override Widget build(BuildContext context) { + ProjectViewModel projectProvider = Provider.of(context); + return Container( margin: EdgeInsets.symmetric(horizontal: 10, vertical: 0), child: Consumer( @@ -238,7 +243,9 @@ class _OrderBottomWidgetState extends State { width: 25.0, height: widget.height * 0.070, decoration: new BoxDecoration( - color: !isAgree ? Color(0xffeeeeee) : Colors.green, + color: !isAgree + ? Color(0xffeeeeee) + : Colors.green, shape: BoxShape.circle, ), child: !isAgree @@ -258,7 +265,8 @@ class _OrderBottomWidgetState extends State { padding: EdgeInsets.symmetric(horizontal: 4), margin: const EdgeInsets.symmetric(vertical: 4), child: Texts( - "I agree with the terms of service and I adhere to them unconditionally", + TranslationBase.of(context) + .pharmacyServiceTermsCondition, fontSize: 13, color: Colors.grey.shade800, fontWeight: FontWeight.normal, @@ -267,10 +275,8 @@ class _OrderBottomWidgetState extends State { ), InkWell( onTap: () => { - Navigator.push( - context, - FadePage( - page: PharmacyTermsConditions())) + Navigator.push(context, + FadePage(page: PharmacyTermsConditions())) }, child: Container( child: Icon( @@ -290,39 +296,43 @@ class _OrderBottomWidgetState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - margin: EdgeInsets.symmetric( - horizontal: 0, vertical: 4), - child: Row( - children: [ - Texts( - "SAR ${(cart.subtotal).toStringAsFixed(2)}", - fontSize: 14, - fontWeight: FontWeight.bold, - ), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 4), - child: Texts( - "(inclusive VAT)", - fontSize: 8, - color: Colors.grey, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + margin: EdgeInsets.symmetric( + horizontal: 0, vertical: 0), + child: Row( + children: [ + Texts( + "${TranslationBase.of(context).sar} ${(cart.subtotal).toStringAsFixed(2)}", + fontSize: + projectProvider.isArabic ? 12 : 14, fontWeight: FontWeight.bold, ), - ), - ], + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 4), + child: Texts( + "${TranslationBase.of(context).inclusiveVat}", + fontSize: 8, + color: Colors.grey, + fontWeight: FontWeight.bold, + ), + ), + ], + ), ), - ), - Texts( - "${cart.quantityCount} item(s)", - fontSize: 10, - color: Colors.grey, - fontWeight: FontWeight.bold, - ), - ], + Texts( + "${cart.quantityCount} ${TranslationBase.of(context).items}", + fontSize: 10, + color: Colors.grey, + fontWeight: FontWeight.bold, + ), + ], + ), ), RaisedButton( onPressed: isAgree @@ -335,7 +345,7 @@ class _OrderBottomWidgetState extends State { } : null, child: new Text( - "CHECK OUT", + "${TranslationBase.of(context).checkOut}", style: new TextStyle( color: isAgree ? Colors.white @@ -345,19 +355,9 @@ class _OrderBottomWidgetState extends State { color: Color(0xff005aff), disabledColor: Color(0xff005aff), ), - /* SecondaryButton( - label: "CHECK OUT", - color: Colors.blueAccent, - textColor: Colors.white, - onTap: (() { - Navigator.push( - context, FadePage(page: OrderPreviewPage(widget.addresses))); - }), - disabled: isAgree ? false : true, - )*/ ], ), - ) + ), ], ) : Container(), diff --git a/lib/pages/pharmacies/screens/cart-order-preview.dart b/lib/pages/pharmacies/screens/cart-order-preview.dart index aed2dbc5..f052c54e 100644 --- a/lib/pages/pharmacies/screens/cart-order-preview.dart +++ b/lib/pages/pharmacies/screens/cart-order-preview.dart @@ -2,11 +2,13 @@ import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/payment-checkout-data.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/address-select-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/payment-method-select-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/pharmacy_module_page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductOrderPreviewItem.dart'; +import 'package:diplomaticquarterapp/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; @@ -22,7 +24,8 @@ class OrderPreviewPage extends StatelessWidget { @override Widget build(BuildContext context) { - PreferredSizeWidget appBarWidget = AppBarWidget("Check out", null, true); + PreferredSizeWidget appBarWidget = + AppBarWidget("${TranslationBase.of(context).checkOut}", null, true); final mediaQuery = MediaQuery.of(context); final height = mediaQuery.size.height - appBarWidget.preferredSize.height - @@ -33,7 +36,7 @@ class OrderPreviewPage extends StatelessWidget { builder: (_, model, wi) => ChangeNotifierProvider.value( value: model.paymentCheckoutData, child: AppScaffold( - title: "Check out", + title: "${TranslationBase.of(context).checkOut}", isShowAppBar: true, isShowDecPage: false, appBarWidget: appBarWidget, @@ -114,13 +117,13 @@ class OrderPreviewPage extends StatelessWidget { MainAxisAlignment.spaceBetween, children: [ Texts( - "Subtotal", + "${TranslationBase.of(context).subtotal}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, ), Texts( - "SAR ${(model.cartResponse.subtotal).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, @@ -139,13 +142,13 @@ class OrderPreviewPage extends StatelessWidget { MainAxisAlignment.spaceBetween, children: [ Texts( - "Shipping", + "${TranslationBase.of(context).shipping}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, ), Texts( - "SAR ${(model.totalAdditionalShippingCharge).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(model.totalAdditionalShippingCharge).toStringAsFixed(2)}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, @@ -164,13 +167,13 @@ class OrderPreviewPage extends StatelessWidget { MainAxisAlignment.spaceBetween, children: [ Texts( - "VAT (15%)", + "${TranslationBase.of(context).vat}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, ), Texts( - "SAR ${(model.cartResponse.subtotalVatAmount).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotalVatAmount).toStringAsFixed(2)}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.w500, @@ -195,7 +198,7 @@ class OrderPreviewPage extends StatelessWidget { fontWeight: FontWeight.bold, ), Texts( - "SAR ${(model.cartResponse.subtotal).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", fontSize: 14, color: Colors.black, fontWeight: FontWeight.bold, @@ -215,7 +218,9 @@ class OrderPreviewPage extends StatelessWidget { ), ), bottomSheet: Container( - height: model.cartResponse.shoppingCarts != null ? height * 0.10 : 0, + height: model.cartResponse.shoppingCarts != null + ? height * 0.10 + : 0, color: Colors.white, child: PaymentBottomWidget(model), ), @@ -238,12 +243,14 @@ class _SelectAddressWidgetState extends State { Addresses address; _navigateToAddressPage() { - Navigator.push( - context, FadePage(page: AddressSelectPageTest(widget.addresses))) + Navigator.push(context, FadePage(page: PharmacyAddressesPage())) .then((result) { - address = result; - widget.model.paymentCheckoutData.address = address; - widget.model.getInformationsByAddress(); + if (result != null) { + address = result; + widget.model.paymentCheckoutData.address = address; + widget.model.getInformationsByAddress(); + } + /* setState(() { if (result != null) { address = result; @@ -396,7 +403,7 @@ class _SelectAddressWidgetState extends State { padding: EdgeInsets.symmetric( vertical: 0, horizontal: 6), child: Texts( - "SHIP BY:", + "${TranslationBase.of(context).shipBy}", fontSize: 12, fontWeight: FontWeight.bold, color: Colors.black, @@ -562,6 +569,8 @@ class _LakumWidgetState extends State { @override Widget build(BuildContext context) { + ProjectViewModel projectProvider = Provider.of(context); + return Container( color: Colors.white, padding: EdgeInsets.symmetric(vertical: 12, horizontal: 12), @@ -579,7 +588,7 @@ class _LakumWidgetState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Texts( - "Lakum Points", + "${TranslationBase.of(context).lakumPoints}", fontSize: 12, fontWeight: FontWeight.bold, ), @@ -599,23 +608,29 @@ class _LakumWidgetState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ Texts( - "Riyal", + "${TranslationBase.of(context).riyal}", fontSize: 12, fontWeight: FontWeight.bold, ), Container( - margin: EdgeInsets.only(left: 4), + margin: projectProvider.isArabic + ? EdgeInsets.only(right: 4) + : EdgeInsets.only(left: 4), width: 60, - height: 40, + height: 50, child: TextField( decoration: InputDecoration( border: OutlineInputBorder( borderSide: BorderSide(color: Colors.black, width: 0.2), gapPadding: 0, - borderRadius: BorderRadius.only( - topLeft: Radius.circular(8), - bottomLeft: Radius.circular(8)), + borderRadius: projectProvider.isArabic + ? BorderRadius.only( + topRight: Radius.circular(8), + bottomRight: Radius.circular(8)) + : BorderRadius.only( + topLeft: Radius.circular(8), + bottomLeft: Radius.circular(8)), ), disabledBorder: OutlineInputBorder( borderSide: @@ -670,21 +685,25 @@ class _LakumWidgetState extends State { ), ), Container( - height: 40, + height: 50, padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12), decoration: new BoxDecoration( color: Color(0xff3666E0), shape: BoxShape.rectangle, - borderRadius: BorderRadius.only( - topRight: Radius.circular(6), - bottomRight: Radius.circular(6)), + borderRadius: projectProvider.isArabic + ? BorderRadius.only( + topLeft: Radius.circular(6), + bottomLeft: Radius.circular(6)) + : BorderRadius.only( + topRight: Radius.circular(6), + bottomRight: Radius.circular(6)), border: Border.fromBorderSide(BorderSide( color: Color(0xff3666E0), width: 0.8, )), ), child: Texts( - "USE", + "${TranslationBase.of(context).use}", fontSize: 12, color: Colors.white, fontWeight: FontWeight.bold, @@ -727,7 +746,7 @@ class PaymentBottomWidget extends StatelessWidget { child: Row( children: [ Texts( - "SAR ${(model.cartResponse.subtotal).toStringAsFixed(2)}", + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xff929295), @@ -736,7 +755,7 @@ class PaymentBottomWidget extends StatelessWidget { padding: const EdgeInsets.symmetric(horizontal: 4), child: Texts( - "(inclusive VAT)", + "${TranslationBase.of(context).inclusiveVat}", fontSize: 8, color: Color(0xff929295), fontWeight: FontWeight.w600, @@ -746,7 +765,7 @@ class PaymentBottomWidget extends StatelessWidget { ), ), Texts( - "${model.cartResponse.quantityCount} item(s)", + "${model.cartResponse.quantityCount} ${TranslationBase.of(context).items}", fontSize: 10, color: Colors.grey, fontWeight: FontWeight.bold, @@ -785,7 +804,7 @@ class PaymentBottomWidget extends StatelessWidget { child: Padding( padding: const EdgeInsets.symmetric(vertical: 16), child: new Text( - "PROCEED TO PAY", + "${TranslationBase.of(context).proceedPay}", style: new TextStyle( color: (paymentData.address != null && paymentData.paymentOption != null) diff --git a/lib/pages/pharmacies/screens/pharmacy_module_page.dart b/lib/pages/pharmacies/screens/pharmacy_module_page.dart index 8a16ca25..a1b67f2a 100644 --- a/lib/pages/pharmacies/screens/pharmacy_module_page.dart +++ b/lib/pages/pharmacies/screens/pharmacy_module_page.dart @@ -8,6 +8,7 @@ import 'package:diplomaticquarterapp/pages/pharmacies/screens/lakum-main-page.da import 'package:diplomaticquarterapp/pages/pharmacies/widgets/BannerPager.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductTileItem.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/widgets/manufacturerItem.dart'; +import 'package:diplomaticquarterapp/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; @@ -192,7 +193,9 @@ class GridViewButtons extends StatelessWidget { opacity: 0, hasColorFilter: false, child: GridViewCard(TranslationBase.of(context).myPrescriptions, - 'assets/images/pharmacy_module/prescription_icon.png', () {}), + 'assets/images/pharmacy_module/prescription_icon.png', () { + Navigator.push(context, FadePage(page: PharmacyAddressesPage())); + }), ), DashboardItem( imageName: 'pharmacy_module/bg_4.png', diff --git a/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart b/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart index 30fd4cd6..7e8763e1 100644 --- a/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart +++ b/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart @@ -1,127 +1,82 @@ -import 'package:diplomaticquarterapp/widgets/avatar/large_avatar.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart'; +import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/pickupLocation/PickupLocationFromMap.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_html/style.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; -import 'package:google_maps_flutter/google_maps_flutter.dart'; +import 'package:geolocator/geolocator.dart'; +import 'package:google_maps_place_picker/google_maps_place_picker.dart'; class AddAddressPage extends StatefulWidget { + final Addresses editedAddress; + final Function(PickResult) onPick; + + AddAddressPage(this.editedAddress, this.onPick); + @override - _AddAddressState createState() => _AddAddressState(); + _AddAddressPageState createState() => _AddAddressPageState(); } -class _AddAddressState extends State { +class _AddAddressPageState extends State { + double _latitude; + double _longitude; - void onMapCreated(controller){ - setState(() { - mapController= controller; - }); - } - void _getAddressFromLatLng() {} - _onMapTypeButtonPressed(){} - _onAddMarkerButtonPressed(){} - - LatLng _initialPosition; - GoogleMapController mapController; @override void initState() { - // TODO: implement initState - _initialPosition = LatLng(24.662617030, 46.7334844); super.initState(); + if (widget.editedAddress != null && + widget.editedAddress.latLong != null && + widget.editedAddress.latLong != "") { + List latLng = widget.editedAddress.latLong.split(","); + _latitude = double.parse(latLng[0]); + _longitude = double.parse(latLng[1]); + } else { + _getCurrentLocation(); + } } - void _onMapCreated(GoogleMapController controller) { - mapController = controller; + _getCurrentLocation() async { + await Geolocator.getLastKnownPosition().then((value) { + _latitude = value.latitude; + _longitude = value.longitude; + }).catchError((e) { + _longitude = 0; + _latitude = 0; + }); } - @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - centerTitle: true, - title: Text(TranslationBase.of(context).addNewAddress, style: TextStyle(color:Colors.white)), - backgroundColor: Colors.green, - ), - body: Stack( - children: [ - GoogleMap( - zoomControlsEnabled: true, - myLocationButtonEnabled: true, - myLocationEnabled: true, - onMapCreated: _onMapCreated, - onCameraMove: (object) { -// widget.currentLat = object.target.latitude; -// widget.currentLong = object.target.longitude; - }, - onCameraIdle: _getAddressFromLatLng, - padding: EdgeInsets.only(bottom: 90.0), - initialCameraPosition: CameraPosition( - target: _initialPosition, - zoom: 13.0, - ), - ), -// Align( -// alignment: Alignment.topRight, -// child: Column( -// children: [ -// button(_onMapTypeButtonPressed,Icons.map), -// SizedBox( -// height:16.0, -// ), -// button(_onAddMarkerButtonPressed, Icons.add_location) -// ], -// ), -// ), - ] - ), - bottomSheet: InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return AddAddressPage(); - }), - ); - }, - child: Container( - height: 50.0, - color: Colors.green, - child: Container( - decoration: BoxDecoration( - border: Border.all( - color: Colors.green, - style: BorderStyle.solid, - width: 1.0 - ), - color: Colors.green, - borderRadius: BorderRadius.circular(10.0) - ), - child: Center( - child: Text(TranslationBase.of(context).confirmLocation, - style: TextStyle( - color: Colors.white, - fontSize: 15.0, - fontWeight: FontWeight.bold, - ), - ), - ), + PreferredSizeWidget appBarWidget = AppBarWidget( + "${TranslationBase.of(context).changeAddress}", null, true); + final mediaQuery = MediaQuery.of(context); + final height = mediaQuery.size.height - + appBarWidget.preferredSize.height - + mediaQuery.padding.top; + + return BaseView( + builder: (_, model, wi) => AppScaffold( + appBarTitle: TranslationBase.of(context).changeAddress, + isShowAppBar: true, + isPharmacy: true, + backgroundColor: Colors.white, + appBarWidget: appBarWidget, + body: Container( + height: height * 1, + child: PickupLocationFromMap( + latitude: _latitude, + longitude: _longitude, + isWithAppBar: false, + buttonColor: Color(0xFF5AB145), + buttonLabel: TranslationBase.of(context).save, + onPick: (value) { + widget.onPick(value); + }, ), ), ), - ); + ); } - - -// Widget button(Function function, IconData icon){ -// return FloatingActionButton( -// onPressed: function, -// materialTapTargetSize: MaterialTapTargetSize.padded, -// backgroundColor: Colors.red, -// child: Icon( -// icon, -// size: 18.0, -// ),); -// } - } - diff --git a/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart b/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart index 07862645..e3651e21 100644 --- a/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart +++ b/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart @@ -1,378 +1,320 @@ - +import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/pages/pharmacy/pharmacyAddresses/AddAddress.dart'; -import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; -import 'package:diplomaticquarterapp/config/config.dart'; -import 'package:diplomaticquarterapp/services/pharmacy_services/pharmacyAddress_service.dart'; -import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyAddressesModel.dart'; -import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart'; -class PharmacyAddressesPage extends StatefulWidget{ + +class PharmacyAddressesPage extends StatefulWidget { @override _PharmacyAddressesState createState() => _PharmacyAddressesState(); - } - -class _PharmacyAddressesState extends State{ - String address=""; - int selectedRadio; - bool _value = false; +} - AppSharedPreferences sharedPref = AppSharedPreferences(); - @override - void initState(){ -// WidgetsBinding.instance.addPostFrameCallback((_) => getAllAddress()); +class _PharmacyAddressesState extends State { - super.initState(); - selectedRadio=0; - } - setSelectedRadio(int val){ - setState(() { - selectedRadio = val; - }); + void navigateToAddressPage( + BuildContext ctx, PharmacyAddressesViewModel model, Addresses address) { + Navigator.push( + ctx, + FadePage( + page: AddAddressPage(address, (pickResult) { + model.addEditAddress(pickResult, address); + }))); } - Widget build (BuildContext context){ + Widget build(BuildContext context) { + PreferredSizeWidget appBarWidget = AppBarWidget( + "${TranslationBase.of(context).changeAddress}", null, true); + final mediaQuery = MediaQuery.of(context); + final height = mediaQuery.size.height - + appBarWidget.preferredSize.height - + mediaQuery.padding.top; + return BaseView( - onModelReady: (model) => model.getAddress(address), - builder: (_,model, wi )=> AppScaffold( - appBarTitle:TranslationBase.of(context).changeAddress, - baseViewModel: model, + onModelReady: (model) => model.getAddressesList(), + builder: (_, model, wi) => AppScaffold( + appBarTitle: TranslationBase.of(context).changeAddress, isShowAppBar: true, - isPharmacy:true , + isPharmacy: true, + baseViewModel: model, + backgroundColor: Colors.white, + appBarWidget: appBarWidget, body: Container( - child:SingleChildScrollView( + height: height * 0.90, + child: SingleChildScrollView( child: Column( - children:[ - ListView.builder( - scrollDirection: Axis.vertical, - shrinkWrap: true, - physics: ScrollPhysics(), - itemCount: model.address.length, - itemBuilder: (context, index){ - return Container( - child: Padding( - padding:EdgeInsets.only(top:10.0, left:5.0, right:5.0, bottom:5.0,), - child: Column( - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - InkWell( - onTap: () { - setState(() { - _value = !_value; - }); - }, - child: Container( - margin: EdgeInsets.only(right: 20), - - child: Padding( - padding: const EdgeInsets.all(5.0), - child: _value - ? Container( - child: SvgPicture.asset( - 'assets/images/pharmacy/check_icon.svg', - height: 25, - width: 25,), - ) - : Container( - child: SvgPicture.asset( - 'assets/images/pharmacy/check_icon.svg', - height: 23, - width: 23, - color: Colors.transparent, - ), - decoration: BoxDecoration( - border: Border.all( - color: Colors.grey, - style: BorderStyle.solid, - width: 1.0 - ), - color: Colors.transparent, - borderRadius: BorderRadius.circular(50.0) - ), - ), - ), - ), - ), - ], - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('name', -// model.address[0].customers[0].addresses[0].firstName, - style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, - ), - ), - SizedBox( - height: 5,), - Expanded( - child: Text(model.address[0].customers[0].addresses[0].address1+ ''+ - model.address[0].customers[0].addresses[0].address2+ '' + - model.address[0].customers[0].addresses[0].zipPostalCode, - style: TextStyle(fontSize: 15.0, color: Colors.grey, - ), - ), - ), - SizedBox( - height: 5,), - Row( - children: [ - Container( - margin: EdgeInsets.only(bottom: 8), - child: SvgPicture.asset( - 'assets/images/pharmacy/mobile_number_icon.svg', - height: 13,), - ), - Container( - margin: EdgeInsets.only(left: 10, bottom: 8), - child: Text('588888778', - style: TextStyle(fontSize: 15.0, - ), - ), - ), - ], - ), - SizedBox( - height: 15,), - Row( - children: [ - Column( - children: [ - InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return AddAddressPage(); - }), - ); - }, - child: Row( - children: [ - Container( - margin: EdgeInsets.only(right:10, bottom: 15), - child: SvgPicture.asset( - 'assets/images/pharmacy/edit_icon.svg', - height: 15,), - ), - Container( - margin: EdgeInsets.only(right:5, bottom: 15), - padding: EdgeInsets.only(right: 10.0), - child: Text(TranslationBase.of(context).edit, - style: TextStyle(fontSize: 15.0, - color: Colors.blue, - ), - ), - decoration: BoxDecoration( - border: Border( - right: BorderSide( - color: Colors.grey, - width: 1.0, - ), - ), - ), - ), - ], - ), - ), - ], - ), - Column( - children: [ - InkWell( - onTap: () { -// confirmDelete(snapshot.data[index]["id"]); - confirmDelete("address"); - }, - child: Row( - children: [ - Container( - margin: EdgeInsets.only(left: 15, right: 10, bottom: 15), - child: SvgPicture.asset( - 'assets/images/pharmacy/delete_red_icon.svg', - height: 15,), - ), - Container( - margin: EdgeInsets.only(bottom: 15), - child: Text(TranslationBase.of(context).delete, - style: TextStyle(fontSize: 15.0, - color: Colors.redAccent, - ), - ), - ), - ], - ), - ), - ], - ) - ], - ), - ], - ), - SizedBox( - height: 10, - ), - ], - ), - Divider( - color: Colors.grey[350], - height: 20, - thickness: 6, - indent: 0, - endIndent: 0, - ), - ], - ), - ), - ); - } - ), - SizedBox( - height: 10, - ), - InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return AddAddressPage(); + children: [ + ...List.generate( + model.addresses != null ? model.addresses.length : 0, + (index) => AddressItemWidget( + model, + model.addresses[index], + () { + setState(() { + model.setSelectedAddressIndex(index); + }); + }, + model.selectedAddressIndex == index, + (address) { + navigateToAddressPage(context, model, address); }), - ); - }, - child: Container( - margin: EdgeInsets.only(bottom: 100.0), - height: 50.0, - color: Colors.transparent, - child: Container( - decoration: BoxDecoration( - border: Border.all( - color: Colors.green, - style: BorderStyle.solid, - width: 1.0 - ), - color: Colors.transparent, - borderRadius: BorderRadius.circular(5.0) - ), - child: Center( - child: Text( - TranslationBase.of(context).addAddress, - style: TextStyle( - color: Colors.green, - fontWeight: FontWeight.bold, - ), - ), - ), - ), + ), + Container( + color: Colors.white, + margin: EdgeInsets.all(8), + child: BorderedButton( + TranslationBase.of(context).addAddress, + hasBorder: true, + borderColor: Color(0xFF0fca6d), + textColor: Color(0xFF0fca6d), + fontWeight: FontWeight.bold, + backgroundColor: Colors.white, + fontSize: 14, + vPadding: 12, + hasShadow: true, + handler: () { + navigateToAddressPage(context, model, null); + }, ), ), ], ), ), ), - bottomSheet: InkWell( - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return AddAddressPage(); - }), - ); - }, - child: Container( - height: 50.0, - color: Colors.green, - child: Container( - decoration: BoxDecoration( - border: Border.all( - color: Colors.green, - style: BorderStyle.solid, - width: 1.0 - ), - color: Colors.green, - borderRadius: BorderRadius.circular(5.0) + bottomSheet: Container( + height: height * 0.10, + color: Colors.white, + child: Column( + children: [ + Divider( + color: Colors.grey.shade300, + height: 1, + thickness: 1, + indent: 0, + endIndent: 0, ), - child: Center( - child: Text(TranslationBase.of(context).confirmAddress, - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - ), + Container( + padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8), + child: BorderedButton( + TranslationBase.of(context).confirmAddress, + hasBorder: true, + borderColor: Color(0xFF5AB145), + textColor: Colors.white, + fontWeight: FontWeight.bold, + backgroundColor: Color(0xFF5AB145), + fontSize: 14, + vPadding: 12, + handler: () { + model.saveSelectedAddressLocally( + model.addresses[model.selectedAddressIndex]); + Navigator.pop(context, + model.addresses[model.selectedAddressIndex]); + }, ), ), - ), + ], ), ), ), ); } - confirmDelete(address){ - showDialog( - context: context, - builder: (BuildContext context)=> AlertDialog( - title: Text(TranslationBase.of(context).confirmDeleteMsg, - style: TextStyle( - fontWeight: FontWeight.bold, - ),), - content: Text("address"), - actions:[ - FlatButton( - child: Text(TranslationBase.of(context).cancel, - style: TextStyle( - color: Colors.red, - fontWeight: FontWeight.bold, - fontSize: 16, - ),), - onPressed: (){ - Navigator.pop(context); - }, - ), - FlatButton( - child: Text(TranslationBase.of(context).confirmDelete, - style: TextStyle( - color: Colors.grey, - fontWeight: FontWeight.bold, - fontSize: 16, - ),), - onPressed: (){ -// http.delete("https://uat.hmgwebservices.com/epharmacy/api/Customers/272843?fields=addresses/$id"); - Navigator.push(context, - MaterialPageRoute(builder: (context)=> PharmacyAddressesPage() )); - }, - ), - ], - ) - ); - } } -getAllAddress() { +class AddressItemWidget extends StatelessWidget { + final PharmacyAddressesViewModel model; + final Addresses address; + final Function selectAddress; + final bool isSelected; + final Function(Addresses) onTabEditAddress; -} - - - - getConfirmAddress(){ - - } - getEditAddress(){ - - } - getDeleteAddress(){ + AddressItemWidget(this.model, this.address, this.selectAddress, + this.isSelected, this.onTabEditAddress); + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: Padding( + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 0), + child: Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + InkWell( + onTap: selectAddress, + child: Container( + margin: EdgeInsets.only(left: 16, right: 16), + child: Padding( + padding: const EdgeInsets.all(5.0), + child: Container( + decoration: new BoxDecoration( + color: !isSelected ? Colors.white : Colors.green, + shape: BoxShape.circle, + border: Border.all( + color: Colors.grey, + style: BorderStyle.solid, + width: 1.0), + ), + child: Padding( + padding: const EdgeInsets.all(0.0), + child: Icon( + Icons.check, + color: isSelected + ? Colors.white + : Colors.transparent, + size: 25, + ), + ), + ), + ), + ), + ), + ], + ), + Expanded( + child: Container( + child: Container( + margin: + EdgeInsets.symmetric(vertical: 12, horizontal: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.symmetric(vertical: 0), + child: Texts( + "${address.firstName} ${address.lastName}", + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 4), + child: Texts( + "${address.address1} ${address.address2} ${address.address2},, ${address.city}, ${address.country} ${address.zipPostalCode}", + fontSize: 12, + fontWeight: FontWeight.normal, + color: Colors.grey.shade500, + ), + ), + 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.grey, + ), + ], + ), + SizedBox( + height: 10, + ), + Container( + height: 25, + child: Row( + children: [ + BorderedButton( + TranslationBase.of(context).edit, + backgroundColor: Colors.transparent, + hasBorder: true, + borderColor: Colors.transparent, + textColor: Color(0x990000FF), + handler: () { + onTabEditAddress(address); + }, + icon: Icon( + Icons.edit, + size: 15, + color: Color(0x990000FF), + ), + ), + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 8), + child: SizedBox( + child: Container( + width: 1, + color: Colors.grey.shade400, + ), + ), + ), + BorderedButton( + TranslationBase.of(context).delete, + backgroundColor: Colors.transparent, + hasBorder: true, + borderColor: Colors.transparent, + textColor: Color(0x99FF0000), + handler: () { + ConfirmDialog dialog = new ConfirmDialog( + context: context, + title: "Are you sure want to delete", + confirmMessage: + "${address.address1} ${address.address2}", + okText: + TranslationBase.of(context).delete, + cancelText: TranslationBase.of(context) + .cancel_nocaps, + okFunction: () => { + model + .deleteAddresses(address) + .then((_) { + ConfirmDialog.closeAlertDialog( + context); + AppToast.showErrorToast( + message: + "Address has been deleted"); + }) + }, + cancelFunction: () => {}); + dialog.showAlertDialog(context); + }, + icon: Icon( + Icons.delete, + size: 15, + color: Color(0x99FF0000), + ), + ), + ], + ), + ), + ], + ), + ), + ), + ), + ], + ), + Divider( + color: Colors.grey.shade200, + height: 10, + thickness: 10, + indent: 0, + endIndent: 0, + ), + ], + ), + ), + ); + } } - - - - - diff --git a/lib/services/pharmacy_services/pharmacyAddress_service.dart b/lib/services/pharmacy_services/pharmacyAddress_service.dart index 3ff2a2d3..1bb6571c 100644 --- a/lib/services/pharmacy_services/pharmacyAddress_service.dart +++ b/lib/services/pharmacy_services/pharmacyAddress_service.dart @@ -1,38 +1,102 @@ import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Country.dart'; import 'package:diplomaticquarterapp/core/service/base_service.dart'; -import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; -import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; -import 'package:flutter/material.dart'; -import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyAddressesModel.dart'; +class PharmacyAddressService extends BaseService { + List addresses = List(); + CountryData country; + int selectedAddressIndex = 0; -class PharmacyAddressService extends BaseService{ + Future getAddresses() async { + var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); + Map queryParams = {'fields': 'addresses'}; + hasError = false; + Addresses selectedAddress; + try { + await baseAppClient.get("$GET_CUSTOMERS_ADDRESSES$customerId", + onSuccess: (dynamic response, int statusCode) async { + addresses.clear(); + var savedAddress = + await sharedPref.getObject(PHARMACY_SELECTED_ADDRESS); + if (savedAddress != null) { + selectedAddress = Addresses.fromJson(savedAddress); + } + int index = 0; + response['customers'][0]['addresses'].forEach((item) { + Addresses address = Addresses.fromJson(item); + if (selectedAddress != null && selectedAddress.id == item["id"]) { + selectedAddressIndex = index; + } + addresses.add(address); + index++; + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, queryParams: queryParams); + } catch (error) { + throw error; + } + } + + Future getCountries(String countryName) async { + hasError = false; + try { + await baseAppClient.get("$PHARMACY_GET_COUNTRY", + onSuccess: (dynamic response, int statusCode) { + // countries.clear(); + response['countries'].forEach((item) { + if (CountryData.fromJson(item).name == countryName || + CountryData.fromJson(item).namen == countryName) { + country = CountryData.fromJson(item); + } + // countries.add(CountryData.fromJson(item)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }); + } catch (error) { + throw error; + } + } - AppSharedPreferences sharedPref = AppSharedPreferences(); - AppGlobal appGlobal = new AppGlobal(); - AuthenticatedUser authUser = new AuthenticatedUser(); - AuthProvider authProvider = new AuthProvider(); + Future addCustomerAddress(Addresses address) async { + makeCustomerAddress(address, ADD_CUSTOMER_ADDRESS); + } - List get address => address; - List _addressList = List(); - List get reviewList => _addressList; - String url =""; + Future editCustomerAddress(Addresses address) async { + makeCustomerAddress(address, EDIT_CUSTOMER_ADDRESS); + } - Future getAddress(address) async { - print("step 1"); + Future deleteCustomerAddress(Addresses address) async { + makeCustomerAddress(address, DELETE_CUSTOMER_ADDRESS); + } + + Future makeCustomerAddress(Addresses address, String url) async { + var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; - url =GET_ADDRESS+"272843?fields=addresses"; - print(url); - await baseAppClient.getPharmacy(url, - onSuccess: (dynamic response, int statusCode) { - _addressList.clear(); - response['customers'].forEach((item) { - _addressList.add(PharmacyAddressesModel.fromJson(item)); - }); - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - }); - }} \ No newline at end of file + super.error = ""; + + Map customerObject = Map(); + customerObject["addresses"] = [address]; + customerObject["id"] = customerId; + customerObject["email"] = address.email; + customerObject["role_ids"] = [3]; + Map body = Map(); + body["customer"] = customerObject; + + await baseAppClient.post("$url", onSuccess: (response, statusCode) async { + addresses.clear(); + response['customers'][0]['addresses'].forEach((item) { + addresses.add(Addresses.fromJson(item)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: body); + } +} diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index ae0a3d88..232bd99a 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -735,7 +735,14 @@ class TranslationBase { String get orderDetail => localizedValues['orderDetail'][locale.languageCode]; String get subtotal => localizedValues['subtotal'][locale.languageCode]; String get shipping => localizedValues['shipping'][locale.languageCode]; + String get shipBy => localizedValues['shipBy'][locale.languageCode]; + String get lakumPoints => localizedValues['lakumPoints'][locale.languageCode]; + String get use => localizedValues['use'][locale.languageCode]; + String get proceedPay => localizedValues['proceedPay'][locale.languageCode]; String get vat => localizedValues['vat'][locale.languageCode]; + String get inclusiveVat => localizedValues['inclusiveVat'][locale.languageCode]; + String get items => localizedValues['items'][locale.languageCode]; + String get checkOut => localizedValues['checkOut'][locale.languageCode]; String get total => localizedValues['total'][locale.languageCode]; String get sar => localizedValues['sar'][locale.languageCode]; String get payOnline => localizedValues['payOnline'][locale.languageCode]; @@ -1036,6 +1043,7 @@ class TranslationBase { localizedValues['termOfService'][locale.languageCode]; String get shoppingCart => localizedValues['shoppingCart'][locale.languageCode]; + String get pharmacyServiceTermsCondition => localizedValues['pharmacyServiceTermsCondition'][locale.languageCode]; String get referralStatus => localizedValues['referralStatus'][locale.languageCode]; diff --git a/lib/widgets/buttons/borderedButton.dart b/lib/widgets/buttons/borderedButton.dart index e297a10e..b0bbdaf0 100644 --- a/lib/widgets/buttons/borderedButton.dart +++ b/lib/widgets/buttons/borderedButton.dart @@ -18,6 +18,7 @@ class BorderedButton extends StatelessWidget { final double fontSize; final Widget icon; final FontWeight fontWeight; + final bool hasShadow; BorderedButton( this.text, { @@ -36,6 +37,7 @@ class BorderedButton extends StatelessWidget { this.fontSize = 0, this.icon, this.fontWeight, + this.hasShadow = false, }); @override @@ -46,14 +48,21 @@ class BorderedButton extends StatelessWidget { }, child: Container( decoration: BoxDecoration( - shape: BoxShape.rectangle, - color: backgroundColor ?? Colors.white, - borderRadius: BorderRadius.circular(radius), - border: Border.fromBorderSide(BorderSide( - color: hasBorder ? borderColor : Colors.white, - width: 0.8, - )), - ), + shape: BoxShape.rectangle, + color: backgroundColor ?? Colors.white, + borderRadius: BorderRadius.circular(radius), + border: Border.fromBorderSide(BorderSide( + color: hasBorder ? borderColor : Colors.white, + width: 0.8, + )), + boxShadow: [ + BoxShadow( + color: !hasShadow ? Colors.transparent : Colors.grey.withOpacity(0.5), + // spreadRadius: 5, + blurRadius: 15.0, + offset: Offset(0.0, 0.75) // changes position of shadow + ), + ]), child: Container( child: Row( mainAxisAlignment: MainAxisAlignment.center, @@ -69,8 +78,11 @@ class BorderedButton extends StatelessWidget { text, textAlign: TextAlign.center, style: TextStyle( - fontSize: fontSize == 0 ? SizeConfig.textMultiplier * 1.6 : fontSize, - fontWeight: fontWeight != null ? fontWeight : FontWeight.normal, + fontSize: fontSize == 0 + ? SizeConfig.textMultiplier * 1.6 + : fontSize, + fontWeight: + fontWeight != null ? fontWeight : FontWeight.normal, color: textColor ?? Color(0xffc4aa54)), ), ), diff --git a/lib/widgets/dialogs/confirm_dialog.dart b/lib/widgets/dialogs/confirm_dialog.dart index 8f1192a5..02b208ad 100644 --- a/lib/widgets/dialogs/confirm_dialog.dart +++ b/lib/widgets/dialogs/confirm_dialog.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; class ConfirmDialog { final BuildContext context; + final title; final confirmMessage; final okText; final cancelText; @@ -14,6 +15,7 @@ class ConfirmDialog { ConfirmDialog( {@required this.context, + this.title, @required this.confirmMessage, @required this.okText, @required this.cancelText, @@ -31,7 +33,7 @@ class ConfirmDialog { // set up the AlertDialog AlertDialog alert = AlertDialog( - title: Text(TranslationBase.of(context).confirm), + title: title != null ? Text(title) : Text(TranslationBase.of(context).confirm), content: Text(this.confirmMessage), actions: [ cancelButton, diff --git a/lib/widgets/pickupLocation/PickupLocationFromMap.dart b/lib/widgets/pickupLocation/PickupLocationFromMap.dart index d8c93441..563de5d7 100644 --- a/lib/widgets/pickupLocation/PickupLocationFromMap.dart +++ b/lib/widgets/pickupLocation/PickupLocationFromMap.dart @@ -1,6 +1,7 @@ import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; import 'package:diplomaticquarterapp/widgets/others/close_back.dart'; import 'package:flutter/cupertino.dart'; @@ -13,24 +14,36 @@ class PickupLocationFromMap extends StatelessWidget { final Function(PickResult) onPick; final double latitude; final double longitude; + final bool isWithAppBar; + final String buttonLabel; + final Color buttonColor; - const PickupLocationFromMap({Key key, this.onPick, this.latitude, this.longitude}) + const PickupLocationFromMap( + {Key key, + this.onPick, + this.latitude, + this.longitude, + this.isWithAppBar = true, + this.buttonLabel, + this.buttonColor}) : super(key: key); @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); return Scaffold( - appBar: AppBar( - elevation: 0, - textTheme: TextTheme( - headline6: - TextStyle(color: Colors.white, fontWeight: FontWeight.bold), - ), - title: Text('Location'), - leading: CloseBack(), - centerTitle: true, - ), + appBar: isWithAppBar + ? AppBar( + elevation: 0, + textTheme: TextTheme( + headline6: + TextStyle(color: Colors.white, fontWeight: FontWeight.bold), + ), + title: Text('Location'), + leading: CloseBack(), + centerTitle: true, + ) + : null, body: PlacePicker( apiKey: GOOGLE_API_KEY, enableMyLocationButton: true, @@ -57,17 +70,30 @@ class PickupLocationFromMap extends StatelessWidget { child: state == SearchingState.Searching ? Center(child: CircularProgressIndicator()) : Container( - margin: EdgeInsets.all(12), - child: SecondaryButton( - color: Colors.grey[800], + margin: EdgeInsets.all(12), + child: BorderedButton( + buttonLabel != null ? buttonLabel : TranslationBase.of(context).next, textColor: Colors.white, - onTap: () { + fontWeight: FontWeight.bold, + backgroundColor: buttonColor != null ? buttonColor : Colors.grey[800], + fontSize: 14, + vPadding: 12, + radius: 10, + handler: () { onPick(selectedPlace); Navigator.of(context).pop(); }, - label: TranslationBase.of(context).next, ), - ), + /* SecondaryButton( + color: Colors.grey[800], + textColor: Colors.white, + onTap: () { + onPick(selectedPlace); + Navigator.of(context).pop(); + }, + label: TranslationBase.of(context).next, + ),*/ + ), ); }, initialPosition: LatLng(latitude, longitude),