-
Notifications
You must be signed in to change notification settings - Fork 936
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
I want to inject a button to HTML, then process interaction between webview and flutter #426
Comments
Injecting the button can be done via javascript, which in turn can inject your button. As mentioned in the readme file of this project, the WebView is above the regular widget tree, no widgets (like a snackbar) can be displayed above the WebView. My recommendation for this would be to inject the appropriate JS, HTML, and CSS to create a pseudo snackbar within the page you're visiting. If you wanted your button press to be registered by your flutter code (not just the sandbox of JS that you've injected), I haven't seen any good solutions yet. The only thing I've thought that may work is by encoding the response in the WebView URL. For example, your button on page Javascript injection function: // Loads the given JS class from assets
Future<String> loadJS(String name) async {
var givenJS = rootBundle.loadString('path/to/declared/assets/$name.js');
return givenJS.then((String js) {
flutterWebViewPlugin.onStateChanged.listen((viewState) async {
if (viewState.type == WebViewState.finishLoad) {
flutterWebViewPlugin.evalJavascript(js);
}
});
});
} This would evaluate your javascript located at |
@muffinjello thanks again. adding button with js and listeing to address changes is probably the only way of doing this. closing |
@muffinjello @charafau Great! thank you very much. |
I want to inject a button to HTML, if user click the button , flutter should be pop a snack bar, ,how to do these? thanks.
The text was updated successfully, but these errors were encountered: