showHistoryReceipt method

Future<void> showHistoryReceipt({
  1. required BuildContext context,
  2. required TransactionDetailsSettings settings,
})

Shows the history receipt dialog for previous transactions.

Displays a modal dialog for viewing historical transaction details. Includes context validation, delayed execution for state stability, and proper back button handling.

Parameters:

  • context: The build context for showing the dialog
  • settings: Configuration for the transaction details display

Example:

await ReceiptHandler.instance.showHistoryReceipt(
  context: context,
  settings: TransactionDetailsSettings(
    transactionId: 'TXN789',
    onClose: () =&gt; Navigator.pop(context),
  ),
);

Implementation

Future<void> showHistoryReceipt({
  required BuildContext context,
  required TransactionDetailsSettings settings,
}) async {
  Logar.debug('showHistoryReceipt starting', tag: 'RECEIPT_HANDLER');
  try {
    Logar.debug('Pushing dialog route', tag: 'RECEIPT_HANDLER');

    // Ensure we're using the root navigator and the context is still valid
    if (!context.mounted) {
      Logar.warning('Context is no longer mounted', tag: 'RECEIPT_HANDLER');
      return;
    }

    // Use a delayed future to ensure the dialog shows after any pending state changes
    await Future.delayed(const Duration(milliseconds: 100));

    if (!context.mounted) {
      Logar.warning(
        'Context is no longer mounted after delay',
        tag: 'RECEIPT_HANDLER',
      );
      return;
    }

    await Navigator.of(context, rootNavigator: true).push(
      DialogRoute(
        context: context,
        barrierDismissible: false,
        builder: (_) {
          Logar.debug(
            'Building TransactionStatusDialog',
            tag: 'RECEIPT_HANDLER',
          );
          return PopScope(
            canPop: false, // Prevent back button from dismissing
            child: Localizations(
              delegates:
                  AppLocalizationsSetup.localizationsDelegates.toList(),
              locale: settings.locale,
              child: TransactionStatusDialog(
                settings: settings.copyWith(
                  onClose: () {
                    Logar.debug('Dialog closed', tag: 'RECEIPT_HANDLER');
                    if (settings.onClose != null) {
                      Logar.debug(
                        'Calling custom onClose callback',
                        tag: 'RECEIPT_HANDLER',
                      );
                      settings.onClose!();
                    } else {
                      AmwalSdkNavigator.amwalNavigatorObserver.navigator!
                          .pop();

                      Logar.debug(
                        'No custom onClose callback provided',
                        tag: 'RECEIPT_HANDLER',
                      );
                    }
                  },
                ),
              ),
            ),
          );
        },
      ),
    );
    Logar.debug('Dialog route pushed successfully', tag: 'RECEIPT_HANDLER');
  } catch (e, stackTrace) {
    Logar.error(
      'showHistoryReceipt error',
      tag: 'RECEIPT_HANDLER',
      error: e,
      stackTrace: stackTrace,
    );
  }
}