getUserEmail method

Future<String?> getUserEmail()

Get user email.

Attention! User need to be logged in with accepted FacebookPermission.email permission.

If not logged in, decline FacebookPermission.email permission or error during request occurred, than returns null.

Implementation

Future<String?> getUserEmail() async {
  final token = await accessToken;
  if (!_isLoggedIn(token)) {
    if (debug) _log('Not logged in. Email is null');
    return null;
  }

  if (!token!.permissions.contains(FacebookPermission.email.name)) {
    if (debug) _log('User did not accept `email` permission. Email is null');
    return null;
  }

  try {
    final email = await _channel.invokeMethod<String>(_methodGetUserEmail);

    if (debug) _log('User email: $email');
    return email;
  } on PlatformException catch (e) {
    if (debug) _log('Get user email error: $e');
  }
  return null;
}