DavidLee
DavidLee

Reputation: 45

Can flutter native side use eventchannel transfer the MAP data?

I am running the flutter platform channel "Eventchannel" with windows platform

I know this not mention in official platform channel document

but I found some example that work with windows and I test it.

Now, I can transfer the single data from below code:

void initEventChannel(flutter::FlutterEngine* flutter_instance) {
    const static std::string event_channel_name("getFromWinsBrowsingDevice");
    const flutter::StandardMethodCodec& codec = flutter::StandardMethodCodec::GetInstance();
    flutter::EventChannel event_channel_name_(flutter_instance->messenger(), event_channel_name, &codec);
    event_channel_name_.SetStreamHandler(
        std::make_unique<flutter::StreamHandlerFunctions<flutter::EncodableValue>>(on_listen, on_cancel));
}
std::unique_ptr<flutter::StreamHandlerError<flutter::EncodableValue>> on_listen(
    const flutter::EncodableValue* agruments,
    std::unique_ptr<flutter::EventSink<flutter::EncodableValue>>&& events) {
    
    std::thread BrowsingThread(sentBrowsingEvent, std::move(events));
    BrowsingThread.detach();
    return NULL;
}


void sentBrowsingEvent(std::unique_ptr<flutter::EventSink<flutter::EncodableValue>>&& events) {
    //Browsing_Check_routine, &browsing_test

    //creat MAP in Browsing_Check_routine to feedback the event to UI
    while (1) {
            Browsing_Check_routine()
            events.get()->Success(flutter::EncodableValue(BrowsingDeviceMap)); // This will fail while send all MAP data
        }
        std::this_thread::sleep_for(std::chrono::seconds(1));
#endif
    }
}

I want to receive some help, how should I fix this error to pass the MAP data to flutter side?

events.get()->Success(flutter::EncodableValue(BrowsingDeviceMap)); // This will fail while send all MAP data

Thank you!

Edit: I realize my map is c++ type, if I want to pass the map with the EncodableValue, the variable must declare in EncodableMap type.

Upvotes: 2

Views: 502

Answers (0)

Related Questions