From 197ab89c71b1312575777d93767e30641ab0c21c Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Wed, 19 Jun 2024 18:07:15 +0900 Subject: [PATCH] Keep key value in pending method map --- .../lib/src/lwe_webview.dart | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart index f45659849..c8c694ed7 100644 --- a/packages/webview_flutter_lwe/lib/src/lwe_webview.dart +++ b/packages/webview_flutter_lwe/lib/src/lwe_webview.dart @@ -51,7 +51,14 @@ class LweWebView { if (method == 'addJavaScriptChannel' || method == 'runJavaScript' || method == 'runJavaScriptReturningResult') { - _pendingMethodCalls['${method}_$arguments'] = arguments; + if (_pendingMethodCalls[method] == null) { + _pendingMethodCalls[method] = []; + } + final List argumentsList = + _pendingMethodCalls[method] as List; + if (!argumentsList.contains('$arguments')) { + argumentsList.add('$arguments'); + } } else { _pendingMethodCalls[method] = arguments; } @@ -79,14 +86,18 @@ class LweWebView { } _pendingMethodCalls.forEach((String method, dynamic arguments) { - if (method.contains('addJavaScriptChannel_')) { - _lweWebViewChannel.invokeMethod( - 'addJavaScriptChannel', arguments); - } else if (method.contains('runJavaScript_')) { - _lweWebViewChannel.invokeMethod('runJavaScript', arguments); - } else if (method.contains('runJavaScriptReturningResult_')) { - _lweWebViewChannel.invokeMethod( - 'runJavaScriptReturningResult', arguments); + if (method == 'addJavaScriptChannel' || + method == 'runJavaScript' || + method == 'runJavaScriptReturningResult') { + if (_pendingMethodCalls[method] != null) { + final List argumentsList = + _pendingMethodCalls[method] as List; + for (final String javaScriptMethodArguments in argumentsList) { + _lweWebViewChannel.invokeMethod( + method, javaScriptMethodArguments); + } + argumentsList.clear(); + } } else { _lweWebViewChannel.invokeMethod(method, arguments); }