captcha_plugin_flutter 1.0.1
captcha_plugin_flutter: ^1.0.1 copied to clipboard
captcha plugin.
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,
"is_no_sense_mode": false,
"dimAmount": 0.8,
"is_touch_outside_disappear": true,
"timeout": 8000,
"is_hide_close_button": false,
"use_default_fallback": true,
"failed_max_retry_count": 4,
"language_type": "ja"
})
},
child: Text("初始化")),
TextButton(
onPressed: () => {captchaPlugin.showCaptcha()},
child: Text("显示验证码")),
],
)),
),
);
}
}