fluttercommunity / fluttercommunity/flutter_webview_plugin
i want to call custom flutter function from javascription fuction.
- Dominant language
- Java
- Stars
- 1.5k
- Forks
- 938
- PR merge metrics
- No merged PRs in 30d
Description
Here is my code.
MainActivity.kt
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
WebviewManager.java
webView.addJavascriptInterface(new WebAppInterface(), "Android");
//////////////
public class WebAppInterface {
@JavascriptInterface
public void getPostMessage(String value){
Map postMessageMap = new HashMap<>();
postMessageMap.put("postMessage", value);
FlutterWebviewPlugin.channel.invokeMethod("onPostMessage", postMessageMap);
}
}
dart file :
flutterWebViewPlugin.onStateChanged.listen((state) async {
if(state.type == WebViewState.finishLoad) {
String script = 'window.addEventListener("message", sendWhatsApp,false);' +
'function sendWhatsApp(msg) {Android.postMessage("data");}';
flutterWebViewPlugin.evalJavascript(script);
}
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the JavaScript-to-native-to-Dart flow described in MainActivity.kt, WebviewManager.java, and the Dart onStateChanged listener. Clarify the expected custom Flutter function and verify whether the existing JavaScript interface and FlutterWebviewPlugin channel can deliver that call; done means the requested invocation works with a documented example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, java, javascript, kotlin
- Domain
- mobile-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100