File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
android/src/main/java/com/flutter_webview_plugin Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 10
10
import android .view .View ;
11
11
import android .view .ViewGroup ;
12
12
import android .webkit .CookieManager ;
13
+ import android .webkit .JavascriptInterface ;
13
14
import android .webkit .ValueCallback ;
14
15
import android .webkit .WebChromeClient ;
15
16
import android .webkit .WebSettings ;
@@ -171,6 +172,7 @@ public boolean onShowFileChooser(
171
172
return true ;
172
173
}
173
174
});
175
+ webView .addJavascriptInterface (new WebAppInterface (), "Android" );
174
176
}
175
177
176
178
private void clearCookies () {
@@ -339,4 +341,13 @@ void stopLoading(MethodCall call, MethodChannel.Result result){
339
341
webView .stopLoading ();
340
342
}
341
343
}
344
+
345
+ public class WebAppInterface {
346
+ @ JavascriptInterface
347
+ public void getPostMessage (String value ){
348
+ Map <String , Object > orderMap = new HashMap <>();
349
+ orderMap .put ("order" , value );
350
+ FlutterWebviewPlugin .channel .invokeMethod ("onOrderRequest" , orderMap );
351
+ }
352
+ }
342
353
}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ class FlutterWebviewPlugin {
29
29
final _onScrollXChanged = StreamController <double >.broadcast ();
30
30
final _onScrollYChanged = StreamController <double >.broadcast ();
31
31
final _onHttpError = StreamController <WebViewHttpError >.broadcast ();
32
+ final _lightningLinkStream = StreamController <String >.broadcast ();
32
33
33
34
Future <Null > _handleMessages (MethodCall call) async {
34
35
switch (call.method) {
@@ -54,6 +55,9 @@ class FlutterWebviewPlugin {
54
55
case 'onHttpError' :
55
56
_onHttpError.add (WebViewHttpError (call.arguments['code' ], call.arguments['url' ]));
56
57
break ;
58
+ case 'onOrderRequest' :
59
+ _lightningLinkStream.add (call.arguments['order' ]);
60
+ break ;
57
61
}
58
62
}
59
63
@@ -76,6 +80,8 @@ class FlutterWebviewPlugin {
76
80
77
81
Stream <WebViewHttpError > get onHttpError => _onHttpError.stream;
78
82
83
+ Stream <String > get lightningLinkStream => _lightningLinkStream.stream;
84
+
79
85
/// Start the Webview with [url]
80
86
/// - [headers] specify additional HTTP headers
81
87
/// - [withJavascript] enable Javascript or not for the Webview
@@ -188,6 +194,7 @@ class FlutterWebviewPlugin {
188
194
_onScrollXChanged.close ();
189
195
_onScrollYChanged.close ();
190
196
_onHttpError.close ();
197
+ _lightningLinkStream.close ();
191
198
_instance = null ;
192
199
}
193
200
You can’t perform that action at this time.
0 commit comments