@@ -145,20 +145,27 @@ int ExtractIntFromMap(const flutter::EncodableValue& arguments,
145
145
}
146
146
return -1 ;
147
147
}
148
- double ExtractDoubleFromMap (const flutter::EncodableValue& arguments,
149
- const char * key) {
150
- if (std::holds_alternative<flutter::EncodableMap>(arguments)) {
151
- flutter::EncodableMap values = std::get<flutter::EncodableMap>(arguments);
152
- flutter::EncodableValue value = values[flutter::EncodableValue (key)];
153
- if (std::holds_alternative<double >(value)) return std::get<double >(value);
148
+
149
+ template <typename T>
150
+ bool GetValueFromEncodableMap (const flutter::EncodableValue& arguments,
151
+ std::string key, T* out) {
152
+ if (auto pmap = std::get_if<flutter::EncodableMap>(&arguments)) {
153
+ auto iter = pmap->find (flutter::EncodableValue (key));
154
+ if (iter != pmap->end () && !iter->second .IsNull ()) {
155
+ if (auto pval = std::get_if<T>(&iter->second )) {
156
+ *out = *pval;
157
+ return true ;
158
+ }
159
+ }
154
160
}
155
- return - 1 ;
161
+ return false ;
156
162
}
157
163
158
164
WebView::WebView (flutter::PluginRegistrar* registrar, int viewId,
159
165
flutter::TextureRegistrar* texture_registrar, double width,
160
- double height, flutter::EncodableMap& params)
161
- : PlatformView(registrar, viewId),
166
+ double height, flutter::EncodableMap& params,
167
+ void * platform_window)
168
+ : PlatformView(registrar, viewId, platform_window),
162
169
texture_registrar_(texture_registrar),
163
170
webview_instance_(nullptr ),
164
171
width_(width),
@@ -823,9 +830,13 @@ void WebView::HandleMethodCall(
823
830
LOG_DEBUG (" WebView::HandleMethodCall : %s \n " , method_name.c_str ());
824
831
825
832
if (method_name.compare (" loadUrl" ) == 0 ) {
826
- std::string url = ExtractStringFromMap (arguments, " url" );
827
- webview_instance_->LoadURL (url);
828
- result->Success ();
833
+ std::string url;
834
+ if (GetValueFromEncodableMap (arguments, " viewType" , &url)) {
835
+ webview_instance_->LoadURL (url);
836
+ result->Success ();
837
+ return ;
838
+ }
839
+ result->Error (" Invalid Arguments" , " Invalid Arguments" );
829
840
} else if (method_name.compare (" updateSettings" ) == 0 ) {
830
841
if (std::holds_alternative<flutter::EncodableMap>(arguments)) {
831
842
auto settings = std::get<flutter::EncodableMap>(arguments);
@@ -896,15 +907,23 @@ void WebView::HandleMethodCall(
896
907
} else if (method_name.compare (" getTitle" ) == 0 ) {
897
908
result->Success (flutter::EncodableValue (webview_instance_->GetTitle ()));
898
909
} else if (method_name.compare (" scrollTo" ) == 0 ) {
899
- int x = ExtractIntFromMap (arguments, " x" );
900
- int y = ExtractIntFromMap (arguments, " y" );
901
- webview_instance_->ScrollTo (x, y);
902
- result->Success ();
910
+ int x = 0 , y = 0 ;
911
+ if (GetValueFromEncodableMap (arguments, " x" , &x) &&
912
+ GetValueFromEncodableMap (arguments, " y" , &y)) {
913
+ webview_instance_->ScrollTo (x, y);
914
+ result->Success ();
915
+ return ;
916
+ }
917
+ result->Error (" Invalid Arguments" , " Invalid Arguments" );
903
918
} else if (method_name.compare (" scrollBy" ) == 0 ) {
904
- int x = ExtractIntFromMap (arguments, " x" );
905
- int y = ExtractIntFromMap (arguments, " y" );
906
- webview_instance_->ScrollBy (x, y);
907
- result->Success ();
919
+ int x = 0 , y = 0 ;
920
+ if (GetValueFromEncodableMap (arguments, " x" , &x) &&
921
+ GetValueFromEncodableMap (arguments, " y" , &y)) {
922
+ webview_instance_->ScrollBy (x, y);
923
+ result->Success ();
924
+ return ;
925
+ }
926
+ result->Error (" Invalid Arguments" , " Invalid Arguments" );
908
927
} else if (method_name.compare (" getScrollX" ) == 0 ) {
909
928
result->Success (flutter::EncodableValue (webview_instance_->GetScrollX ()));
910
929
} else if (method_name.compare (" getScrollY" ) == 0 ) {
0 commit comments