Skip to content

Commit

Permalink
Keep key value in pending method map
Browse files Browse the repository at this point in the history
  • Loading branch information
JSUYA committed Jun 19, 2024
1 parent 6cc3bee commit 197ab89
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions packages/webview_flutter_lwe/lib/src/lwe_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ class LweWebView {
if (method == 'addJavaScriptChannel' ||
method == 'runJavaScript' ||
method == 'runJavaScriptReturningResult') {
_pendingMethodCalls['${method}_$arguments'] = arguments;
if (_pendingMethodCalls[method] == null) {
_pendingMethodCalls[method] = <String>[];
}
final List<String> argumentsList =
_pendingMethodCalls[method] as List<String>;
if (!argumentsList.contains('$arguments')) {
argumentsList.add('$arguments');
}
} else {
_pendingMethodCalls[method] = arguments;
}
Expand Down Expand Up @@ -79,14 +86,18 @@ class LweWebView {
}

_pendingMethodCalls.forEach((String method, dynamic arguments) {
if (method.contains('addJavaScriptChannel_')) {
_lweWebViewChannel.invokeMethod<void>(
'addJavaScriptChannel', arguments);
} else if (method.contains('runJavaScript_')) {
_lweWebViewChannel.invokeMethod<void>('runJavaScript', arguments);
} else if (method.contains('runJavaScriptReturningResult_')) {
_lweWebViewChannel.invokeMethod<void>(
'runJavaScriptReturningResult', arguments);
if (method == 'addJavaScriptChannel' ||
method == 'runJavaScript' ||
method == 'runJavaScriptReturningResult') {
if (_pendingMethodCalls[method] != null) {
final List<String> argumentsList =
_pendingMethodCalls[method] as List<String>;
for (final String javaScriptMethodArguments in argumentsList) {
_lweWebViewChannel.invokeMethod<void>(
method, javaScriptMethodArguments);
}
argumentsList.clear();
}
} else {
_lweWebViewChannel.invokeMethod<void>(method, arguments);
}
Expand Down

0 comments on commit 197ab89

Please sign in to comment.