How to hide header and footer in webview in Flutter.?

前端 未结 1 642
南方客
南方客 2021-01-07 05:27

I\'m beginner to flutter , I want to hide section of website in my flutter application . I added flutter flutter_webview_plugin in pubspec.yaml fil

1条回答
  •  孤街浪徒
    2021-01-07 06:17

    This is likely due to your webpage not being loaded, and therefore the element not existing, at the point you call that method in your code.

    A solution would be to wait until the page is loaded before attempting to remove the element using the onStateChanged stream.

    StreamSubscription _onStateChanged;
    
    @override
    void initState(){
      super.initState();
      flutterWebviewPlugin.evalJavascript("alert('Hi, I just executed')");
    
      _onStateChanged =
        flutterWebViewPlugin.onStateChanged.listen((WebViewStateChanged state) {
          if(state.type == WebViewState.finishLoad) {
            flutterWebviewPlugin.evalJavascript("document.getElementById('header04-2j').style.display = 'none';");
          }
        }
      );
    }
    
    @override
    void dispose() {
      _onStateChanged.cancel();
      flutterWebviewPlugin.dispose();
      super.dispose();
    }
    

    0 讨论(0)
提交回复
热议问题