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
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();
}