nnnggel / gCaptcha

A flutter plugin for reCAPTCHA v2 - android. The FREE anti-abuse service.
https://pub.dev/packages/g_captcha
Apache License 2.0
3 stars 11 forks source link

fatal error: 'gCaptcha-Swift.h' file not found #import "gCaptcha-Swift.h" #6

Open Reza-Piri opened 2 years ago

Reza-Piri commented 2 years ago

is there any advice?

error: /Developer/flutter/.pub-cache/hosted/pub.dartlang.org/g_captcha-1.0.0/ios/Classes/GCaptchaPlugin.m:8:9: fatal error: 'gCaptcha-Swift.h' file not found

import "gCaptcha-Swift.h"

skalex4 commented 2 years ago

Any update on this ??

RakeshCodeNinja commented 2 years ago

I am also waiting for update.. unable to run ios build.

Reza-Piri commented 2 years ago

i found the solution. to fix this error, by changing "gCaptcha" to "g_Captcha" in all files and classes.

( gCaptcha/ios/Classes/GCaptchaPlugin.m and gCaptcha/ios/Classes/SwiftGCaptchaPlugin.swift )

this helps to build your project in xcode with no error. but you will get error on runtime!

missingpluginexception(no implementation found for method recaptcha on channel com.yuanchongyu.g_captcha)

finally i just give up and decided to use flutter webview to handle google recaptcha:

1) create a html file and deploy it on server :

<head>
<title>reCAPTCHA</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<div class="container">
<form action="?" method="POST">
<div class="g-recaptcha" 
data-sitekey="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
data-callback="captchaCallback"
data-theme="light"

</div>
</form>
</div>
<script>
function captchaCallback(response){
if(typeof Captcha!=="undefined"){
Captcha.postMessage(response);
}
}
</script>
</body>

2) then crate a flutter widget to load this page in webview :


 class CaptchaDilogContent extends StatefulWidget {
   const CaptchaDilogContent({Key key}) : super(key: key);

   @override
   _CaptchaDilogContentState createState() => _CaptchaDilogContentState();
 }

 class _CaptchaDilogContentState extends State<CaptchaDilogContent> {
   var isLoading = true;
   final Completer<WebViewController> _controller =
       Completer<WebViewController>();

   @override
   void initState() {
     super.initState();
     // Enable hybrid composition.
     if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
   }

   @override
   Widget build(BuildContext context) {
     var url = "https://youdomain/cp.html";
     var height = MediaQuery.of(context).size.height * 0.5;
    return Container(
       height: height,
       child: Stack(
         children: [
           WebView(
             initialUrl: url,
             javascriptMode: JavascriptMode.unrestricted,
             javascriptChannels: Set.from([
               JavascriptChannel(
                   name: 'Captcha',
                   onMessageReceived: (JavascriptMessage message) {
                     Navigator.pop(context, message.message);
                   })
             ]),
             onWebViewCreated: (WebViewController webViewController) {
               _controller.complete(webViewController);
             },
             onPageFinished: (finish) {
               setState(() {
                 isLoading = false;
               });
             },
           ),
           isLoading
               ? Center(
                   child: CircularProgressIndicator(),
                 )
               : Stack(),
         ],
       ),
     );
   }
 }

3) and this widget to load a popup dialog:


 Future<String> captchaDialog() async {
     String captchaResponse = "";
     return (await showDialog(
           context: context,
           builder: (context) => AlertDialog(
             content: CaptchaDilogContent(),
           ),
         )) ??
         captchaResponse;
  }

4) then you can use it like :


 var gRecaptchaResponse = await captchaDialog();