commentWithOptions method

  1. @override
Future<String> commentWithOptions(
  1. String parentAuthor,
  2. String parentPermlink,
  3. String permlink,
  4. String title,
  5. String body,
  6. String jsonMetadata,
  7. String options,
)
override

Implementation

@override
Future<String> commentWithOptions(
  String parentAuthor,
  String parentPermlink,
  String permlink,
  String title,
  String body,
  String jsonMetadata,
  String options,
) async {
  final completer = Completer<String>();
  headlessWebView.webViewController?.addJavaScriptHandler(
    handlerName: 'onCommentWithOptionsResult',
    callback: (args) {
      if (!completer.isCompleted) {
        completer.complete(args.isNotEmpty ? args[0].toString() : 'null');
      }
    },
  );
  await headlessWebView.webViewController?.evaluateJavascript(
    source: """
    (async () => {
      try {
        const res = await comment('$parentAuthor', '$parentPermlink', '$permlink', '$title', '$body', ${jsonMetadata.toString()}, ${options.toString()});
        window.flutter_inappwebview.callHandler('onCommentWithOptionsResult', res ?? 'null');
      } catch (e) {
        window.flutter_inappwebview.callHandler('onCommentWithOptionsResult', 'Error: ' + e.toString());
      }
    })()
    """,
  );
  return completer.future;
}