showCaptcha method

Future<String?> showCaptcha({
  1. required BuildContext context,
  2. CaptchaType mode = CaptchaType.dialog,
  3. required dynamic onError(
    1. String error
    ),
  4. required dynamic onSuccess(
    1. String token
    ),
})

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,
  CaptchaType mode = CaptchaType.dialog,
  required Function(String error) onError,
  required Function(String token) onSuccess,
}) async {
  String? token;

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

  if (token != null) {
    onSuccess(token);
  } else {
    onError(onErrorMessage);
  }

  return token;
}