logIn method

Future<Result<VKLoginResult>> logIn({
  1. List<VKScope> scope = const [],
  2. List<String>? customScope,
})

Start log in VK process.

scope Array of scope. If required scope is not in enum VKScope, than use customScope.

Value in not error result can't be null.

If user cancel log in process, than value result will be returned, but value property VKLoginResult.isCanceled will be true and VKLoginResult.accessToken will be null.

If error occurs during log in process, than error result will be returned.

Implementation

Future<Result<VKLoginResult>> logIn(
    {List<VKScope> scope = const [], List<String>? customScope}) async {
  assert(_initialized,
      'SDK is not initialized. You should call initSdk() first');
  if (!_initialized) throw Exception('SDK is not initialized.');

  final scopeArg = _getScope(scope: scope, customScope: customScope);

  if (debug) _log('Log In with scope $scopeArg');

  try {
    final res = await _channel.invokeMethod<Map<dynamic, dynamic>>(
        _methodLogIn, {_argLogInScope: scopeArg});

    if (res == null) {
      return Result.error('Invalid null result');
    } else {
      return Result.value(VKLoginResult.fromMap(res.cast<String, dynamic>()));
    }
  } on PlatformException catch (e) {
    if (debug) _log('Log In error: $e');
    return Result.error(e);
  }
}