diff --git a/lib/api/offers_and_discounts_api_client.dart b/lib/api/offers_and_discounts_api_client.dart index 76bd1e9..5744ac6 100644 --- a/lib/api/offers_and_discounts_api_client.dart +++ b/lib/api/offers_and_discounts_api_client.dart @@ -278,6 +278,15 @@ class OffersAndDiscountsApiClient { if (geoLocation != null && geoLocation.isNotEmpty) { postParams["WP_Geo_Location"] = geoLocation; + } else if (context != null) { + try { + Position? position = await _getCurrentPositionSilently(context); + if (position != null) { + postParams["WP_Geo_Location"] = "${position.latitude},${position.longitude}"; + } + } catch (e) { + debugPrint("getWalaPlusRetailers: unable to get current location: $e"); + } } _cleanWalaPlusParams(postParams); diff --git a/lib/ui/landing/dashboard_screen_for_dependet.dart b/lib/ui/landing/dashboard_screen_for_dependet.dart index f6ad458..a80a894 100644 --- a/lib/ui/landing/dashboard_screen_for_dependet.dart +++ b/lib/ui/landing/dashboard_screen_for_dependet.dart @@ -246,9 +246,8 @@ class _DashboardScreenForDependetState extends State categoryId: catParam, page: 1, perPage: pageSize, - geoLocation: isNearestOffers ? "24.9485,46.977" : null, offerType: offerTypeParam, - context: context, + context: isNearestOffers ? context : null, ); retailersList = response?.retailers ?? []; @@ -289,9 +288,8 @@ class _DashboardScreenForDependetState extends State categoryId: catParam, page: nextPage, perPage: pageSize, - geoLocation: isNearestOffers ? "24.9485,46.977" : null, offerType: offerTypeParam, - context: context, + context: isNearestOffers ? context : null, ); List newRetailers = response?.retailers ?? []; diff --git a/lib/widgets/bottom_sheets/confirm_bottom_sheet.dart b/lib/widgets/bottom_sheets/confirm_bottom_sheet.dart new file mode 100644 index 0000000..cd09ecb --- /dev/null +++ b/lib/widgets/bottom_sheets/confirm_bottom_sheet.dart @@ -0,0 +1,171 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:mohem_flutter_app/classes/colors.dart'; +import 'package:mohem_flutter_app/extensions/int_extensions.dart'; +import 'package:mohem_flutter_app/extensions/string_extensions.dart'; +import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; +import 'package:mohem_flutter_app/widgets/button/default_button.dart'; + +/// Generic, fully customizable confirmation bottom sheet matching the app's visual theme +/// (same handle bar / rounded-top-sheet / gradient button look used across other sheets). +/// Everything is driven by the caller - title/message/button text/colors/icon/callbacks - +/// with sensible defaults so a minimal call still looks consistent with the rest of the app. +class ConfirmBottomSheet extends StatelessWidget { + final String? title; + final String message; + final String? confirmText; + final String? cancelText; + final VoidCallback onConfirm; + final VoidCallback? onCancel; + final bool isDestructive; + final bool showCancelButton; + final IconData? icon; + final Color? iconColor; + final Color? iconBackgroundColor; + final List? confirmButtonColors; + final Color? confirmButtonTextColor; + final Color? cancelButtonColor; + final Color? cancelButtonTextColor; + + const ConfirmBottomSheet({ + Key? key, + this.title, + required this.message, + this.confirmText, + this.cancelText, + required this.onConfirm, + this.onCancel, + this.isDestructive = false, + this.showCancelButton = true, + this.icon, + this.iconColor, + this.iconBackgroundColor, + this.confirmButtonColors, + this.confirmButtonTextColor, + this.cancelButtonColor, + this.cancelButtonTextColor, + }) : super(key: key); + + /// Convenience launcher - mirrors Utils.confirmDialog's call shape but as a bottom sheet. + static Future show( + BuildContext context, { + String? title, + required String message, + String? confirmText, + String? cancelText, + required VoidCallback onConfirm, + VoidCallback? onCancel, + bool isDestructive = false, + bool showCancelButton = true, + IconData? icon, + Color? iconColor, + Color? iconBackgroundColor, + List? confirmButtonColors, + Color? confirmButtonTextColor, + Color? cancelButtonColor, + Color? cancelButtonTextColor, + }) { + return showModalBottomSheet( + context: context, + isScrollControlled: true, + backgroundColor: Colors.transparent, + builder: (BuildContext sheetContext) { + return ConfirmBottomSheet( + title: title, + message: message, + confirmText: confirmText, + cancelText: cancelText, + onConfirm: onConfirm, + onCancel: onCancel, + isDestructive: isDestructive, + showCancelButton: showCancelButton, + icon: icon, + iconColor: iconColor, + iconBackgroundColor: iconBackgroundColor, + confirmButtonColors: confirmButtonColors, + confirmButtonTextColor: confirmButtonTextColor, + cancelButtonColor: cancelButtonColor, + cancelButtonTextColor: cancelButtonTextColor, + ); + }, + ); + } + + @override + Widget build(BuildContext context) { + Color effectiveIconColor = iconColor ?? (isDestructive ? MyColors.redColor : MyColors.textMixColor); + Color effectiveIconBg = iconBackgroundColor ?? effectiveIconColor.withOpacity(0.1); + List effectiveConfirmColors = confirmButtonColors ?? (isDestructive ? const [MyColors.redA3Color, MyColors.redColor] : const [MyColors.gradiantEndColor, MyColors.gradiantStartColor]); + + return SafeArea( + top: false, + child: Container( + padding: const EdgeInsets.fromLTRB(20, 12, 20, 20), + decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.vertical(top: Radius.circular(24))), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + // Drag handle + Center( + child: Container( + width: 44, + height: 4.5, + margin: const EdgeInsets.only(bottom: 18), + decoration: BoxDecoration(color: const Color(0xFFCBD5E1), borderRadius: BorderRadius.circular(2.5)), + ), + ), + + if (icon != null) ...[ + Center( + child: Container( + width: 56, + height: 56, + alignment: Alignment.center, + decoration: BoxDecoration(color: effectiveIconBg, shape: BoxShape.circle), + child: Icon(icon, color: effectiveIconColor, size: 28), + ), + ), + 16.height, + ], + + (title ?? LocaleKeys.confirm.tr()).toText18(isBold: true, isCentered: true, color: MyColors.darkTextColor), + 8.height, + message.toText14(color: MyColors.grey70Color, textAlign: TextAlign.center), + 24.height, + + Row( + children: [ + if (showCancelButton) ...[ + Expanded( + child: DefaultButton( + cancelText ?? LocaleKeys.cancel.tr(), + () { + Navigator.pop(context); + onCancel?.call(); + }, + colors: [cancelButtonColor ?? MyColors.lightGreyEAColor, cancelButtonColor ?? MyColors.lightGreyEAColor], + textColor: cancelButtonTextColor ?? MyColors.darkTextColor, + ), + ), + 12.width, + ], + Expanded( + child: DefaultButton( + confirmText ?? LocaleKeys.ok.tr(), + () { + Navigator.pop(context); + onConfirm(); + }, + colors: effectiveConfirmColors, + textColor: confirmButtonTextColor ?? Colors.white, + ), + ), + ], + ), + ], + ), + ), + ); + } +}