|
|
|
@ -12,12 +12,14 @@ import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
|
|
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
|
|
|
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
|
|
|
|
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/features/authentication/authentication_view_model.dart';
|
|
|
|
import 'package:hmg_patient_app_new/features/offers_and_discounts/offers_and_discounts_view_model.dart';
|
|
|
|
import 'package:hmg_patient_app_new/features/offers_and_discounts/offers_and_discounts_view_model.dart';
|
|
|
|
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
|
|
|
|
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/offers_and_discount_payment_page.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/offers_and_discount_payment_page.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/offers_and_discounts_detailed_page.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/offers_and_discounts_detailed_page.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/offers_and_discounts_history_page.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/offers_and_discounts_history_page.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/widgets/offers_and_discount_type_selection_widget.dart';
|
|
|
|
import 'package:hmg_patient_app_new/presentation/offers_and_discounts/widgets/offers_and_discount_type_selection_widget.dart';
|
|
|
|
|
|
|
|
import 'package:hmg_patient_app_new/services/dialog_service.dart';
|
|
|
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
|
|
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
|
|
|
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart';
|
|
|
|
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart';
|
|
|
|
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
|
|
|
|
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
|
|
|
|
@ -41,11 +43,13 @@ class _OffersAndDiscountsPageState extends State<OffersAndDiscountsPage> {
|
|
|
|
late OffersAndDiscountsViewModel offersAndDiscountsViewModel;
|
|
|
|
late OffersAndDiscountsViewModel offersAndDiscountsViewModel;
|
|
|
|
late AppState appState;
|
|
|
|
late AppState appState;
|
|
|
|
final TextEditingController _searchController = TextEditingController();
|
|
|
|
final TextEditingController _searchController = TextEditingController();
|
|
|
|
|
|
|
|
FocusNode textFocusNode = FocusNode();
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
appState = getIt.get<AppState>();
|
|
|
|
appState = getIt.get<AppState>();
|
|
|
|
|
|
|
|
|
|
|
|
scheduleMicrotask(() async {
|
|
|
|
scheduleMicrotask(() async {
|
|
|
|
offersAndDiscountsViewModel = Provider.of<OffersAndDiscountsViewModel>(context, listen: false);
|
|
|
|
offersAndDiscountsViewModel = Provider.of<OffersAndDiscountsViewModel>(context, listen: false);
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,7 +67,7 @@ class _OffersAndDiscountsPageState extends State<OffersAndDiscountsPage> {
|
|
|
|
onError: (error) {
|
|
|
|
onError: (error) {
|
|
|
|
// Hide loader on error
|
|
|
|
// Hide loader on error
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
print("POMS Authentication failed: $error");
|
|
|
|
print("POMS POMS Authentication failed: $error");
|
|
|
|
// Authentication failed, but user can still browse offers
|
|
|
|
// Authentication failed, but user can still browse offers
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
@ -166,9 +170,18 @@ class _OffersAndDiscountsPageState extends State<OffersAndDiscountsPage> {
|
|
|
|
return CollapsingListView(
|
|
|
|
return CollapsingListView(
|
|
|
|
title: LocaleKeys.offerAndPackages.tr(context: context),
|
|
|
|
title: LocaleKeys.offerAndPackages.tr(context: context),
|
|
|
|
history: () {
|
|
|
|
history: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
if (!appState.isAuthenticated) {
|
|
|
|
CustomPageRoute(page: OffersAndDiscountsHistoryPage()),
|
|
|
|
getIt<DialogService>().showErrorBottomSheet(
|
|
|
|
);
|
|
|
|
message: LocaleKeys.loginToUseService.tr(),
|
|
|
|
|
|
|
|
onOkPressed: () {
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
|
|
|
getIt<AuthenticationViewModel>().onLoginPressed();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Navigator.of(context).push(
|
|
|
|
|
|
|
|
CustomPageRoute(page: OffersAndDiscountsHistoryPage()),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Consumer<OffersAndDiscountsViewModel>(builder: (context, offersAndDiscountVM, child) {
|
|
|
|
child: Consumer<OffersAndDiscountsViewModel>(builder: (context, offersAndDiscountVM, child) {
|
|
|
|
@ -180,18 +193,29 @@ class _OffersAndDiscountsPageState extends State<OffersAndDiscountsPage> {
|
|
|
|
TextInputWidget(
|
|
|
|
TextInputWidget(
|
|
|
|
labelText: LocaleKeys.search.tr(context: context),
|
|
|
|
labelText: LocaleKeys.search.tr(context: context),
|
|
|
|
hintText: LocaleKeys.typeAnyOffer.tr(),
|
|
|
|
hintText: LocaleKeys.typeAnyOffer.tr(),
|
|
|
|
hintColor: AppColors.textColor,
|
|
|
|
|
|
|
|
controller: _searchController,
|
|
|
|
controller: _searchController,
|
|
|
|
onChange: (value) {
|
|
|
|
leadingIcon: AppAssets.search_icon,
|
|
|
|
offersAndDiscountVM.setSearchQuery(value!);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isEnable: true,
|
|
|
|
isEnable: true,
|
|
|
|
prefix: null,
|
|
|
|
prefix: null,
|
|
|
|
|
|
|
|
isAllowLeadingIcon: true,
|
|
|
|
autoFocus: false,
|
|
|
|
autoFocus: false,
|
|
|
|
isBorderAllowed: false,
|
|
|
|
isBorderAllowed: false,
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
isAllowLeadingIcon: true,
|
|
|
|
focusNode: textFocusNode,
|
|
|
|
selectionType: SelectionTypeEnum.search,
|
|
|
|
suffix: _searchController.text.isNotEmpty
|
|
|
|
|
|
|
|
? GestureDetector(
|
|
|
|
|
|
|
|
onTap: () {
|
|
|
|
|
|
|
|
_searchController.clear();
|
|
|
|
|
|
|
|
// bookAppointmentsViewModel.filterClinics("");
|
|
|
|
|
|
|
|
offersAndDiscountVM.setSearchQuery("");
|
|
|
|
|
|
|
|
textFocusNode.unfocus();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
child: Utils.buildSvgWithAssets(icon: AppAssets.close_bottom_sheet_icon, width: 20.h, height: 20.h, fit: BoxFit.scaleDown),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
: null,
|
|
|
|
|
|
|
|
onChange: (value) {
|
|
|
|
|
|
|
|
offersAndDiscountVM.setSearchQuery(value!);
|
|
|
|
|
|
|
|
},
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: ResponsiveExtension(10).h,
|
|
|
|
vertical: ResponsiveExtension(10).h,
|
|
|
|
horizontal: ResponsiveExtension(15).h,
|
|
|
|
horizontal: ResponsiveExtension(15).h,
|
|
|
|
@ -342,49 +366,58 @@ class _OffersAndDiscountsPageState extends State<OffersAndDiscountsPage> {
|
|
|
|
icon: AppAssets.shoppingCart,
|
|
|
|
icon: AppAssets.shoppingCart,
|
|
|
|
iconColor: AppColors.whiteColor,
|
|
|
|
iconColor: AppColors.whiteColor,
|
|
|
|
onPressed: () async {
|
|
|
|
onPressed: () async {
|
|
|
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.pleaseWait.tr(context: context));
|
|
|
|
if (!appState.isAuthenticated) {
|
|
|
|
|
|
|
|
getIt<DialogService>().showErrorBottomSheet(
|
|
|
|
|
|
|
|
message: LocaleKeys.loginToUseService.tr(),
|
|
|
|
|
|
|
|
onOkPressed: () {
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
|
|
|
getIt<AuthenticationViewModel>().onLoginPressed();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.pleaseWait.tr(context: context));
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure patient is authenticated (will re-authenticate if needed)
|
|
|
|
// Ensure patient is authenticated (will re-authenticate if needed)
|
|
|
|
final isAuthenticated = await offersAndDiscountVM.ensureAuthenticated(
|
|
|
|
final isAuthenticated = await offersAndDiscountVM.ensureAuthenticated(
|
|
|
|
onSuccess: () {
|
|
|
|
onSuccess: () {
|
|
|
|
// Authentication successful, continue
|
|
|
|
// Authentication successful, continue
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onError: (error) {
|
|
|
|
onError: (error) {
|
|
|
|
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
|
|
|
|
// Show error to user
|
|
|
|
|
|
|
|
showCommonBottomSheetWithoutHeight(
|
|
|
|
|
|
|
|
context,
|
|
|
|
|
|
|
|
child: Utils.getErrorWidget(loadingText: LocaleKeys.paymentFailedPleaseTryAgain.tr(context: context)),
|
|
|
|
|
|
|
|
callBackFunc: () {},
|
|
|
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
|
|
|
isCloseButtonVisible: true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isAuthenticated) {
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
// Show error to user
|
|
|
|
return;
|
|
|
|
showCommonBottomSheetWithoutHeight(
|
|
|
|
}
|
|
|
|
context,
|
|
|
|
|
|
|
|
child: Utils.getErrorWidget(loadingText: LocaleKeys.paymentFailedPleaseTryAgain.tr(context: context)),
|
|
|
|
|
|
|
|
callBackFunc: () {},
|
|
|
|
|
|
|
|
isFullScreen: false,
|
|
|
|
|
|
|
|
isCloseButtonVisible: true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isAuthenticated) {
|
|
|
|
// Fetch offer details
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
await offersAndDiscountVM.getOfferDetails(
|
|
|
|
return;
|
|
|
|
offersAndDiscountVM.filteredOffers[index].id!,
|
|
|
|
|
|
|
|
onSuccess: (response) {
|
|
|
|
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
|
|
|
|
if (offersAndDiscountVM.offerDetails != null) {
|
|
|
|
|
|
|
|
offersAndDiscountVM.setSelectedOffer(offersAndDiscountVM.offerDetails!);
|
|
|
|
|
|
|
|
Navigator.of(context).push(
|
|
|
|
|
|
|
|
CustomPageRoute(
|
|
|
|
|
|
|
|
page: OffersAndDiscountPaymentPage(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onError: (error) {
|
|
|
|
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch offer details
|
|
|
|
|
|
|
|
await offersAndDiscountVM.getOfferDetails(
|
|
|
|
|
|
|
|
offersAndDiscountVM.filteredOffers[index].id!,
|
|
|
|
|
|
|
|
onSuccess: (response) {
|
|
|
|
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
|
|
|
|
if (offersAndDiscountVM.offerDetails != null) {
|
|
|
|
|
|
|
|
offersAndDiscountVM.setSelectedOffer(offersAndDiscountVM.offerDetails!);
|
|
|
|
|
|
|
|
Navigator.of(context).push(
|
|
|
|
|
|
|
|
CustomPageRoute(
|
|
|
|
|
|
|
|
page: OffersAndDiscountPaymentPage(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onError: (error) {
|
|
|
|
|
|
|
|
LoaderBottomSheet.hideLoader();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
backgroundColor: AppColors.primaryRedColor,
|
|
|
|
backgroundColor: AppColors.primaryRedColor,
|
|
|
|
borderColor: AppColors.primaryRedColor,
|
|
|
|
borderColor: AppColors.primaryRedColor,
|
|
|
|
|