verify method

Future<String?> verify(
  1. RecaptchaArgs args, [
  2. Duration timeout = const Duration(seconds: 60)
])

Kick-off the recaptcha verifier and listen to changes emitted by HttpRequest.

Each event represents the current state of the verification in the broswer.

On desktop platforms calling this method will fire up the default browser.

Implementation

Future<String?> verify(
  RecaptchaArgs args, [
  Duration timeout = const Duration(seconds: 60),
]) async {
  final completer = Completer<String?>();

  final server = RecaptchaVerificationServer(args);

  server.onError = completer.completeError;
  server.onResponse = completer.complete;

  await server.start();

  await OpenUrlUtil().openUrl(server.url);

  return completer.future.whenComplete(server.close).timeout(
    timeout,
    onTimeout: () {
      server.close();
      return null;
    },
  );
}