captcha_plugin_flutter 0.0.9 copy "captcha_plugin_flutter: ^0.0.9" to clipboard
captcha_plugin_flutter: ^0.0.9 copied to clipboard

PlatformAndroidiOS
outdated

A new Flutter project for captcha.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:captcha_plugin_flutter/captcha_plugin_flutter.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final CaptchaPluginFlutter captchaPlugin = new CaptchaPluginFlutter();

  var eventChannel = const EventChannel("yd_captcha_flutter_event_channel");

  @override
  void initState() {
    super.initState();

    eventChannel.receiveBroadcastStream().listen(_onEvent);
  }

  void _onEvent(Object response) {
    if (response is Map) {
      var validate = response["validate"] as String;
      if (validate != null) {
        print(validate.isNotEmpty ? "验证成功" : "验证失败");
      } else {
        if (response.containsKey("code")) {
          var code = response["code"];
          var msg = response["msg"];
          print(code);
          print(msg);
        } else {
          var closed = response["closed"];
          print("验证码弹窗关闭" + closed.toString());
        }
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: new Column(
          children: [
            TextButton(
                onPressed: () => {
                      captchaPlugin.init({
                        "captcha_id": "易盾业务id",
                        "is_debug": true
                      })
                    },
                child: Text("初始化")),
            TextButton(
                onPressed: () => {captchaPlugin.showCaptcha()},
                child: Text("显示验证码")),
          ],
        )),
      ),
    );
  }
}
7
likes
105
pub points
81%
popularity

Publisher

unverified uploader

A new Flutter project for captcha.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on captcha_plugin_flutter