setBackgrounded method

void setBackgrounded(
  1. bool backgrounded
)

Suspends automatic LNbits balance polling while the app is backgrounded. Existing balances remain available. NWC notifications, transaction monitoring, payments and explicit refreshBalance calls are unaffected.

Implementation

void setBackgrounded(bool backgrounded) {
  if (_isDisposed || _backgrounded == backgrounded) return;
  _backgrounded = backgrounded;
  for (final wallet in _wallets) {
    if (wallet.type != WalletType.LNBITS) continue;
    if (backgrounded) {
      unawaited(_balanceSubscriptions.remove(wallet.id)?.cancel());
    } else if (_walletBalanceStreams.containsKey(wallet.id)) {
      _initBalanceStream(wallet.id);
    }
  }
}