Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whats the best way to call a custom javascript function in a flutter app #96

Closed
manujbahl opened this issue Jun 12, 2018 · 3 comments
Closed

Comments

@manujbahl
Copy link

OK .. So i tried the following code

        final flutterWebviewPlugin = new FlutterWebviewPlugin();  
        var code = "function myFunction(x, y) { return x + y;}  return myFunction(2, 3);";
        await flutterWebviewPlugin.launch("http://www.google.com", withJavascript: true, hidden: true);
        var ret = await flutterWebviewPlugin.evalJavascript(code);

and when i did into the error on the channel i see the following error out of the webview evaluateJavaScript call
error NSError * domain: @"WKErrorDomain" - code: 4 0x00006000002528d0

I am assuming I would have to build a local html file with the javascript function included it that and then call that post url load. Is that correct? Any examples on how to launch a local html ?

Any ideas ?

@ishammahajan
Copy link

How did you manage to fix this?

@efreibe
Copy link

efreibe commented Apr 26, 2019

This code is working for me on android:

  final flutterWebviewPlugin = FlutterWebviewPlugin();
  try {
    var code = "function myFunction(x, y) { return x + y;} myFunction(2, 3);";
    await flutterWebviewPlugin.launch("about:blank", withJavascript: true, hidden: true);
    var ret = await flutterWebviewPlugin.evalJavascript(code);
    print(ret);
  } catch (e) {
    print(e.toString());
  }
  flutterWebviewPlugin.close();
  flutterWebviewPlugin.dispose();

@charafau
Copy link
Collaborator

This is now added to the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants