showCaptcha method

Future<String?> showCaptcha({
  1. required BuildContext context,
  2. required CaptchaParams params,
})

Shows the captcha widget in the chosen mode.

onSuccess is called when the captcha is solved with a valid token. onError is called when captcha fails or closes without solving.

Implementation

Future<String?> showCaptcha({
  required BuildContext context,
  required CaptchaParams params,
}) async {
  String? token;

  _log(
    'showCaptcha requestedMode=${params.mode} mounted=${context.mounted}',
  );

  switch (params.mode) {
    case CaptchaType.screen:
      token = await _showAsScreen(context);
    case CaptchaType.dialog:
      token = await _showAsDialog(context);
    case CaptchaType.modalBottomSheet:
      token = await _showAsBottomSheet(context);
    case CaptchaType.responsiveDialog:
      token = await _showAsResponsiveDialog(context);
  }

  if (token != null) {
    _log('captcha completed tokenLength=${token.length}');
    params.onSuccess(token);
  } else {
    _log('captcha closed or failed without a token');
    params.onError(onErrorMessage);
  }

  return token;
}