Flutter¶
For Flutter, the widget embeds the EU CAPTCHA in a WebView in the app and supplies an interface in Dart.
Requirements¶
The following requirements must be met:
| Requirement | Value |
|---|---|
| Flutter | From version 3.0 |
| Dart SDK | From version 3.0 |
| Operating system | Android from API level 19, iOS from version 13 |
| Credentials | Public sitekey from the Details view |
Enter the dependencies¶
Add these entries to the pubspec.yaml file:
Copy the lib/eucaptcha.dart file and the assets/ directory into your project, and enter the files:
Set up the platforms¶
For Android, add this entry to the android/app/src/main/AndroidManifest.xml file:
For iOS, no more settings are necessary.
Embed the widget¶
import 'eucaptcha.dart';
EuCaptcha(
sitekey: 'EUCAPTCHA_SITE_KEY',
theme: 'auto', // 'light', 'dark', or 'auto'
lang: 'en', // BCP 47 language code
onComplete: (response) {
// response is the token — submit to your server as "eu-captcha-response"
},
onExpire: (_) { /* CAPTCHA expired */ },
onError: (_) { /* error occurred */ },
)
The theme value controls the appearance with light, dark, and auto. The lang value takes a language code as specified in BCP 47.
Reset the widget¶
Use a GlobalKey<EuCaptchaState> to call reset():
final _captchaKey = GlobalKey<EuCaptchaState>();
EuCaptcha(key: _captchaKey, sitekey: '...', onComplete: ...)
// later:
_captchaKey.currentState?.reset();
Verify the token¶
After the onComplete call, send the token to your server. The server verifies the token:
POST https://api.eu-captcha.eu/v1/verify
Content-Type: application/json
{
"sitekey": "EUCAPTCHA_SITE_KEY",
"secret": "EUCAPTCHA_SECRET_KEY",
"client_ip": "<client IP>",
"client_token": "<token from widget>",
"client_user_agent": "<user-agent>"
}
The response is { "success": true, "train": false }.