discardSession method

void discardSession({
  1. bool force = false,
})

Clears the current session.

If the session has successful payment legs, a warning is logged. Callers should confirm with the user before discarding a session that has completed payments (the ReconciliationScreen handles this via a confirmation dialog).

Implementation

void discardSession({bool force = false}) {
  if (_currentSession != null &&
      _currentSession!.hasSuccessfulPayments &&
      !force) {
    _logger?.error(
      this,
      'discardSession: blocked — session has '
      '${_currentSession!.successfulLegCount} successful leg(s) '
      'and force=false',
    );
    throw StateError(
      'Cannot discard session with '
      '${_currentSession!.successfulLegCount} successful payment leg(s). '
      'Use force: true to discard anyway.',
    );
  }

  if (_currentSession != null) {
    _logger?.info(
      this,
      'discardSession: clearing — '
      'splitId=${_currentSession!.splitId}, '
      'hadLegs=${_currentSession!.paymentLegs.length}, '
      'force=$force',
    );
  }

  _currentSession = null;
}