runJavaScriptReturningResult method

  1. @override
Future<Object> runJavaScriptReturningResult(
  1. String javaScript
)

Runs the given JavaScript in the context of the current page, and returns the result.

The Future completes with an error if a JavaScript error occurred, or if the type the given expression evaluates to is unsupported. Unsupported values include certain non-primitive types on iOS, as well as undefined or null on iOS 14+.

Implementation

@override
Future<Object> runJavaScriptReturningResult(String javaScript) async {
  final String? result = await _webView.evaluateJavascript(javaScript);

  if (result == null) {
    return '';
  } else if (result == 'true') {
    return true;
  } else if (result == 'false') {
    return false;
  }

  return num.tryParse(result) ?? result;
}