init method

void init({
  1. String? clientId,
  2. String? clientSecret,
  3. Duration? connectTimeout,
  4. Duration? receiveTimeout,
  5. bool? showVerificationDialog,
  6. AuthyoDesignStyle? designStyle,
  7. AuthyoTheme? theme,
  8. AuthyoSocialLoginHandler? onSocialLogin,
  9. bool prefetchConfig = true,
  10. String? baseUrl,
})

Initializes the plugin with your clientId and clientSecret.

You can optionally set connectTimeout, receiveTimeout, and whether to use the built-in verification dialog with showVerificationDialog.

The dialog's look is resolved in this order — later wins:

  1. built-in defaults (Flat, Authyo blue)
  2. the design style + customization configured on your Authyo dashboard (fetched in the background and cached on device)
  3. designStyle / theme passed here

onSocialLogin lets you run social sign-in with your own native SDKs instead of the system browser; see AuthyoSocialLoginHandler.

baseUrl points the SDK at another Authyo server (staging / local), e.g. http://10.0.2.2:5000 from the Android emulator. Defaults to https://app.authyo.io.

Call this method before making any sendOtp or verifyOtp requests.

Implementation

void init({
  String? clientId,
  String? clientSecret,
  Duration? connectTimeout,
  Duration? receiveTimeout,
  bool? showVerificationDialog,
  AuthyoDesignStyle? designStyle,
  AuthyoTheme? theme,
  AuthyoSocialLoginHandler? onSocialLogin,
  bool prefetchConfig = true,
  String? baseUrl,
}) {
  if (clientId == null || clientSecret == null) {
    throw AuthyoInitializationError('''
Oops! Looks like you forgot to pass clientId or clientSecret to AuthyoService.init().
These are required to authenticate with Authyo.

🔐 Grab your credentials here:
https://app.authyo.io/account/welcome?ref=HARSCE2BE4&utm_source=partner&utm_medium=referral&utm_campaign=partner-program
''');
  }

  final api = _ApiService(
    clientId: clientId,
    clientSecret: clientSecret,
    connectTimeout: connectTimeout ?? const Duration(seconds: 30),
    receiveTimeout: receiveTimeout ?? const Duration(seconds: 30),
    baseUrl: baseUrl,
  );
  _apiService = api;
  _configService = _ConfigService(api, clientId: clientId);
  _socialService = _SocialLoginService(api);

  _showDefaultDialog = showVerificationDialog ?? true;
  _localStyle = designStyle;
  _localTheme = theme;
  _socialHandler = onSocialLogin;

  if (prefetchConfig) {
    // Warm the cache so the first dialog already has the dashboard look.
    unawaited(loadConfig().catchError((_) => AuthyoWidgetConfig.empty));
  }
}