startVerification method

Future<void> startVerification(
  1. String phoneNumber
)

Implementation

Future<void> startVerification(String phoneNumber) async {
  if (isBusy) return;

  phone = phoneNumber;
  lastError = null;
  code = null;
  requestId = null;
  _waitingStartedAt = null;
  _setState(CallVerificationState.sending);

  try {
    final normalized = toSmsRuPhone(phoneNumber);
    if (!isValidPhone(normalized)) {
      throw SmsRuValidationException(message: 'Некорректный номер телефона');
    }

    final CallSendResponse response;
    if (_sendDelegate != null) {
      response = await _sendDelegate(normalized);
    } else {
      response = await _client!.sendCall(phone: normalized);
    }

    requestId = response.requestId;
    code = response.code;
    _waitingStartedAt = DateTime.now();

    if (kDebugMode) {
      debugPrint(
        '[SMS.RU] Call verification code: $code (requestId: $requestId)',
      );
    }

    _setState(CallVerificationState.waitingForCall);
  } on SmsRuException catch (e) {
    _fail(e);
  } catch (e) {
    _fail(e);
  }
}