Skip to content

arcaptcha/arcaptcha-flutter

Repository files navigation

ARCaptcha Flutter Plugin

This is ARCaptcha Flutter plugin which allows you to integrate the ARCaptcha widget into your Flutter app, which offers a secure and effective way of verifying users. With this plugin, you can display a CAPTCHA for verification, either in visible or invisible modes, and handle the successful verification or error states. This plugin provides flexibility to customize the appearance and behavior of the CAPTCHA widget directly from your Flutter app.

Getting Started

To use the arcaptcha plugin in your Flutter project, follow these steps:

  1. Add the Dependency

    Open the pubspec.yaml file in your Flutter project and add the following dependency:

    dependencies:
      arcaptcha:
         git:
             url: https://github.com/arcaptcha/arcaptcha-flutter.git
    
  2. Initialize ARCaptcha
    First, fetch the project dependencies by running:

    flutter pub get

    Before using the ARCaptcha widget, you need to import the package and initialize it with your Site Key. You can also customize settings such as theme, size, color, language, error display and domain.
    Import the package:

    import 'package:arcaptcha/arcaptcha.dart';

    Then initialize ARCaptcha:

    Arcaptcha.init(
        siteKey: "<your site key>", // Required. Your public API site key.
        domain: "yourdomain.com"    // Optional. Set the domain. Defaults to localhost
        theme: "light",             // Optional. Set the theme of widget. Defualts to light
        color: "blue",              // Optional. Set color of every colored element in widget.
        errorPrint: "1",            // Optional. Enable error messages at the bottom of the checkbox.
        lang: "en",                 // Optional. Set language of widget . Defaults to fa
        size: "normal",             // Optional. Set size of the widget. Options: 'normal' | 'invisible'. Default is 'normal'.
    );
  3. Display ARCaptcha
    To display the captcha, use the Arcaptcha.show() method. This will open the captcha in a WebView.

    final result = await Arcaptcha.show(context);
  4. Handling the Result

    1. Successful Captcha:
      If the user successfully solves the captcha, the result will be a unique token that can be used for verification.
      Example:

      flutter: CAPTCHA result: 910036544655114230735492473541
      
    2. Captcha Error:
      If there is any error while solving the captcha (e.g., incorrect answer, invalid site key, etc.), an error message will be returned. The error contains a code and a message indicating what went wrong.
      Example:

      flutter: Arcaptcha error: {code: 203, message: answer-wrong-error}
      
    3. User Cancels or Skips the Captcha:
      f the user decides not to solve the captcha and exits the widget without completing it, the result will be null, indicating that the captcha was not solved.
      Example:

      flutter: CAPTCHA result: null
      

      The token is returned and printed (you can use this token for verification).

Configuration

The only way to configure ARCaptcha is to set custom attributes on the ARCaptcha container 'div'. You're already required to do this with data-site-key, but there are a handful of other optional attributes that enable more customization.

Attribute Render option Value Description
data-site-key site_key your site key Required. Your public API site key.
data-size size normal or inivisible Optional. Set the size of the widget. Defaults to normal.
data-theme theme light or dark Optional. Set the theme of widget. Defualts to light
data-color color color name or hex code Optional. Set color of every colored element in widget.
data-error-print error_print 0 or 1 Optional. Disable or enable error messages at the bottom of checkbox. Defaults to 0(enabled)
data-lang lang en or fa Optional. Set language of widget . Defaults to fa
domain domain yourdomain.com Optional. Set your website domain. Defaults to localhost

About

ARCaptcha Flutter plugin!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •