didChangeAppLifecycleState method

  1. @override
void didChangeAppLifecycleState(
  1. AppLifecycleState state
)
override

Called when the system puts the app in the background or returns the app to the foreground.

An example of implementing this method is provided in the class-level documentation for the WidgetsBindingObserver class.

This method exposes notifications from SystemChannels.lifecycle.

See also:

Implementation

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
  super.didChangeAppLifecycleState(state);
  switch (state) {
    case AppLifecycleState.resumed:
      // Bug 3 fix: skip if payment already succeeded to prevent double navigation
      if (wasInBackground && !_paymentSucceeded) {
        final data = cachedDataOrNull;
        final tranIds = data?.data?.transInfo.tranNo;
        if (tranIds == null || tranIds.isEmpty || referrerId == null) {
          wasInBackground = false;
          return;
        }
        await _checkPaymentStatusAndNavigate(tranIds);
        if (!_isPolling && !_paymentSucceeded) {
          // For bank app flow, initSocketServer() is never called so
          // _transactionId is null. Seed it from cachedData so the
          // fallback polling actually fires (fixes bottom nav bar return).
          _transactionId ??= tranIds;
          _startPolling();
        }
      }
      break;
    case AppLifecycleState.detached:
    case AppLifecycleState.hidden:
    case AppLifecycleState.paused:
    case AppLifecycleState.inactive:
      wasInBackground = true;
      _stopPolling();
      break;
  }
}