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

How to load a new url in WebviewScaffold? #98

Closed
jow-ct opened this issue Jun 14, 2018 · 4 comments
Closed

How to load a new url in WebviewScaffold? #98

jow-ct opened this issue Jun 14, 2018 · 4 comments

Comments

@jow-ct
Copy link

jow-ct commented Jun 14, 2018

Hi,

I don't get it how to load a new url when using WebviewScaffold. I put some IconButton in the appBar.actions, but what to do there?

I tried

  String url = "http:...";
  final webView = FlutterWebviewPlugin();

  ...new WebviewScaffold(
    url: url,
  ...
    onPressed: () => setState(() => url = "http:newone...")
  ...
    onPressed: () {webView.launch(newurl);}
  ...
    onPressed: () {webView.close(); webview.launch(newurl);}
    }

But all three ways did not work.

setState did not reload a new URL. Only launch throws an error java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. And the close/launch idea made the webview fullscreen over the appBar.

Is there a solution?

@splitbrain
Copy link

I'm facing the same problem. I have buttons in the bottomNavigationBar that open a new activity. To make that activity visible I had to call webView.close(), but I don't see how I can reopen the webView() when I return to the WebviewScaffold activity.

@zoechi
Copy link

zoechi commented Jun 22, 2018

Looks like setState() is called on a different component. If you use bottomNavigationBar it's probably not a parent of the widget that contains new WebviewScaffold() and therefore won't be rebuilt. You might need to use a Stream and a StreamBuilder around new FlutterWebviewPlugin() and to notify the right widget to rebuild.

@jordansilva
Copy link
Contributor

I don't know if it's correct, but I'm doing this way (I know this is by far not the best way to make this work properly, but it's working now):

Future openNewActivity(BuildContext context) async {
    _flutterWebView.hide();

    await Navigator.push(context, new NavigationRoute(builder: (context) => new ListScreen()));

    Future.delayed(Duration(milliseconds: 350), () => _flutterWebView.show());
  }

_flutterWebView is FlutterWebviewPlugin.

@dao-wkm
Copy link

dao-wkm commented Oct 22, 2019

Try to use _flutterWebViewPlugin.reloadUrl(newUrl);

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

6 participants