Flutter 如何使用localhost作为recaptcha的域

Flutter 如何使用localhost作为recaptcha的域,flutter,recaptcha,flutter-web,Flutter,Recaptcha,Flutter Web,我在FlatterWeb上挖我的手,我想为我的基本形式集成recaptcha。我已经在google控制台上配置了recaptcha。然而,出于开发目的,当我在本地主机域中使用它时,我总是会遇到这个错误 导入“包装:颤振/材料.省道”; 将“dart:ui”导入为ui; 将“dart:html”导入为html; 类platformViewRegistry{ 静态registerViewFactory(字符串视图ID,动态cb){ //忽略:未定义的\u前缀\u名称 ui.platformView

我在FlatterWeb上挖我的手,我想为我的基本形式集成recaptcha。我已经在google控制台上配置了recaptcha。然而,出于开发目的,当我在本地主机域中使用它时,我总是会遇到这个错误

导入“包装:颤振/材料.省道”;
将“dart:ui”导入为ui;
将“dart:html”导入为html;
类platformViewRegistry{
静态registerViewFactory(字符串视图ID,动态cb){
//忽略:未定义的\u前缀\u名称
ui.platformViewRegistry.registerViewFactory(viewId,cb);
}
}
类TestPlugin扩展StatefulWidget{
TestPlugin();
_TestPluginState createState();
}
类_TestPluginState扩展状态{
字符串createdVidWid='map_element';
final _formKey=GlobalKey();
@凌驾
void initState(){
//忽略:未定义的\u前缀\u名称
ui.platformViewRegistry.registerViewFactory(
createdViewId,
(int viewId)=>html.iframelement()
..width=MediaQuery.of(context).size.width.toString()
…height=MediaQuery.of(context).size.height.toString()
…srcdoc=“”
雷帕查
函数captchaCallback(响应){
//log('响应为:'+响应);
警报(响应);
如果(验证码类型!=“未定义”){
验证码后信息(响应);
}
}
"""
..style.border='none');
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回填充(
填充:常数边集全部(20.0),
孩子:表格(
键:_formKey,
子项:列(子项:[
TextFormField(),
尺寸箱(高度:10),
容器(
身高:140,
宽度:double.infinity,
孩子:HtmlElementView(
视图类型:CreatedViewWid,
),
),
ElevatedButton(按下时:(){},子项:Text('Submit'))
]),
),
);
}
}
我已经输入了正确的数据站点密钥,这在上面的代码中没有提到。我还禁用了在控制台上验证reCaptcha解决方案的来源。我还将localhost添加到我的域列表中。任何帮助都将不胜感激


编辑:这可能与站点和密钥没有任何问题,因为我能够使用具有相同密钥集的NodeJS实现这一点。我想这与flatter和v2-reCaptcha有关。

谷歌曾使用过测试localhost的键,但现在看起来您只需要将localhost添加为一个域

参见谷歌文档:

我刚刚编辑了我的问题。我已经将localhost添加到我的域列表中了,仍然没有运气!只是想知道控制台日志中是否有错误?这个问题很可能不是google recapcha的问题。我的浏览器控制台和vscode调试控制台都没有错误。我想知道Flitter是否导致了一个问题,迫使它使用v2而不是v3。尝试位于此处的v2测试密钥:尝试了所有方法,但没有任何效果不知道为什么。。尝试使用测试键,尝试使用127.0.0.1而不是localhost,实际上我想使用reCAPTCHA复选框,即v2。尚未找到任何支持web平台的插件。
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
import 'dart:html' as html;


class platformViewRegistry {
static registerViewFactory(String viewId, dynamic cb) {
// ignore:undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(viewId, cb);
}
}

class TestPlugin extends StatefulWidget {
TestPlugin();

_TestPluginState createState() => _TestPluginState();
}

class _TestPluginState extends State<TestPlugin> {
String createdViewId = 'map_element';
final _formKey = GlobalKey<FormState>();
@override
void initState() {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
    createdViewId,
    (int viewId) => html.IFrameElement()
      ..width = MediaQuery.of(context).size.width.toString()
      ..height = MediaQuery.of(context).size.height.toString()
      ..srcdoc = """<!DOCTYPE html><html>
<head>
<title>reCAPTCHA</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<div style='height: 50px;width: 100px;'></div>
<form action="?" method="POST">
  <div class="g-recaptcha" 
    data-sitekey="my_key"
    data-callback="captchaCallback"></div>

</form>
<script>
  function captchaCallback(response){
    //console.log('the response is: '+response);
    alert(response);
    if(typeof Captcha!=="undefined"){
      Captcha.postMessage(response);
    }
  }
</script>
</body>
</html>"""
      ..style.border = 'none');

super.initState();
}

@override
Widget build(BuildContext context) {
return Padding(
  padding: const EdgeInsets.all(20.0),
  child: Form(
    key: _formKey,
    child: Column(children: [
      TextFormField(),
      SizedBox(height: 10),
      Container(
        height: 140,
        width: double.infinity,
        child: HtmlElementView(
          viewType: createdViewId,
        ),
      ),
      ElevatedButton(onPressed: () {}, child: Text('Submit'))
    ]),
  ),
);
}
}