Yandex SmartCaptcha for Flutter

Pub Version Pub Points Dart Package Docs License: MIT

This package makes it easy to integrate Yandex SmartCaptcha into Flutter mobile apps. To learn more about the Yandex SmartCaptcha service, visit its official page.

This package was inspired by flutter_yandex_smartcaptcha, but it offers several improvements, including bug fixes, slightly better performance, enhanced documentation, and a much cleaner API.

Motivation

One day at work, I urgently needed to integrate a Yandex CAPTCHA into a mobile app, and the flutter_yandex_smartcaptcha package came to the rescue. However, I discovered a serious bug and reported it to the author. When they didn’t respond, I decided to create a similar package myself and learn how to publish packages on pub.flutter-io.cn in the process. The end of the magnificent story.

Usage

Super simple! Here’s the most basic example:

YandexSmartCaptcha(
  config: CaptchaConfig(
    clientKey: 'your-client-key',
  ),
  onChallengeSolved: (token) {
    // Handle the solved captcha token
  },
)

In most cases, you’ll only need the YandexSmartCaptcha and CaptchaConfig classes. The CaptchaController is entirely optional – it's useful if you need to trigger a challenge popup programmatically, but that’s rare.

Configuration parameters

Parameter Required Default Description
clientKey The client-side key passed to Web SmartCaptcha.
language ru The language for the Web SmartCaptcha UI.
alwaysShowChallenge false If true, the user will always be presented with a challenge (useful for testing).
useInvisibleMode false If true, runs the CAPTCHA in invisible mode – without the "I’m not a robot" checkbox.
badgePosition bottomRight If useInvisibleMode is enabled, specifies the position of the badge linking to the Data Processing Notice (DPN).
hideBadge false If true and useInvisibleMode is enabled, hides the DPN badge.
initialScale 1.0 The initial scale factor for the Web SmartCaptcha content.
allowUserScaling false If true, the user can scale the Web SmartCaptcha content using gestures.
maximumScale 3.0 If allowUserScaling is enabled, specifies the maximum scale factor for the content.
backgroundColor null The background color of the YandexSmartCaptcha widget.
useWebViewMode true If true, runs the CAPTCHA in a mobile-optimized WebView mode to improve challenge accuracy.

✱ "Web SmartCaptcha" refers to the underlying HTML page hosted inside the WebView that executes Yandex SmartCaptcha's JavaScript code.

Screenshots

  1. SmartCaptcha in a simple test screen:
The initial state of the Yandex SmartCaptcha container with the 'I’m not a robot' checkbox. The initial state of the Yandex SmartCaptcha pop-up, featuring a challenge for the user to solve. The state of the Yandex SmartCaptcha container with the 'I’m not a robot' box checked, after the user successfully solved the challenge.

  1. SmartCaptcha in a real-world application:
The initial state of the Yandex SmartCaptcha container with the 'I’m not a robot' checkbox, as seen in a real-world application. The initial state of the Yandex SmartCaptcha pop-up, featuring a challenge for the user to solve in a real-world application.