Get Method Call arguments in flutter window

304

you could use something like below

 if (method_call.method_name().compare("launch") == 0) {
    std::string url = GetUrlArgument(method_call);
    if (url.empty()) {
      result->Error("argument_error", "No URL provided");
      return;
    }

    std::optional<std::string> error = LaunchUrl(url);
    if (error) {
      result->Error("open_error", error.value());
      return;
    }
    result->Success(EncodableValue(true));
  

For more read here from url_launcher

Share:
304
David Abraham
Author by

David Abraham

Updated on January 04, 2023

Comments

  • David Abraham
    David Abraham over 1 year

    Does anyone know how to get an argument pass by MethodChannel in windows? Here is my code to send and receive data. I need to get data value in string type

    String data = "Some data";
    await platform.invokeMethod("OpenViewer", {"data":data});
    
    channel->SetMethodCallHandler([](const flutter::MethodCall<>& call, std::unique_ptr<flutter::MethodResult<>> result)
            {
                // check method name called from dart
                if (call.method_name().compare("OpenViewer") == 0) {
                    
                }
                else {
                    result->NotImplemented();
                }
            });
    
    
  • David Abraham
    David Abraham over 1 year
    Thank you, i had to merge and split strings to send parameters every time :D