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

_onStateChanged listener is only once? #42

Open
shinriyo opened this issue Mar 4, 2018 · 3 comments
Open

_onStateChanged listener is only once? #42

shinriyo opened this issue Mar 4, 2018 · 3 comments

Comments

@shinriyo
Copy link

shinriyo commented Mar 4, 2018

I wrote the example.
https://pub.dartlang.org/packages/flutter_webview_plugin#-example-tab-

I pushed "Open widget webview" button.
The example show log text onStateChanged: WebViewState.startLoad and onStateChanged: WebViewState.finishLoad in the bottom.

I pushed "Open widget webview" button again, but it didn't show log text again.
Why only once?

I just want to do is that call JS when WebviewScaffold's url finish.

@joelbrostrom
Copy link

I'm in the same scenario.
I listen for urls with https protocol, and the first on it finds it catches and reloads the web view with it.
After that all incoming urls are ignored.

I tried re-adding the listener, close and re-launch the flutterVebviewPlugin and even disposing of it an re-initiating it.
None makes a difference.

The only way I manage to reset it is by reseting the app.

@joelbrostrom
Copy link

joelbrostrom commented Jul 15, 2019

Ok, there seams to be away around this.
Set the onStateChanged listener INSIDE or your BUILD method so that it rebuilds every time your Web view does.
In my case I was using BLoC and tried setting it in the build method, but above the block builder, which resulted in it only being rebuilt when the block class itself was.

@override
  Widget build(BuildContext context) {
    final HomeBloc _homeBloc = BlocProvider.of<HomeBloc>(context);
    // my_webview_provider.addListenerWithBloc(_homeBloc); <--- BAD: setting .onSatusChanged build is not enough when using BLoC, since only the BLoC scope will rebuild when possible.
    return BlocBuilder<HomeEvent, HomeBlocState>(
      bloc: _homeBloc,
      builder: (BuildContext context, HomeBlocState state) {
        my_webview_provider.addListenerWithBloc(_homeBloc); <--- GOOD: setting .onSatusChanged inside of BlocBuilder scope.

        if (state is HomeWebview) {
          my_webview_provider.reloadWithUrl(_tabUrls[_currentTabIndex]);
    ...
    ...

@tegarkurniawan
Copy link

same issue

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

No branches or pull requests

4 participants