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();
}
});
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