#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_FLUTTER_UTIL_H_ #define FLUTTER_INAPPWEBVIEW_PLUGIN_FLUTTER_UTIL_H_ #include #include #include #include "util.h" namespace flutter_inappwebview_plugin { static inline flutter::EncodableValue make_fl_value() { return flutter::EncodableValue(); } template static inline flutter::EncodableValue make_fl_value(const T& val) { return flutter::EncodableValue(val); } template static inline flutter::EncodableValue make_fl_value(const T* val) { return val == nullptr ? make_fl_value() : flutter::EncodableValue(val); } template static inline flutter::EncodableValue make_fl_value(const std::vector& vec) { auto encodableList = flutter::EncodableList{}; for (auto const& val : vec) { encodableList.push_back(make_fl_value(val)); } return encodableList; } template static inline flutter::EncodableValue make_fl_value(const std::map& map) { auto encodableMap = flutter::EncodableMap{}; for (auto const& [key, val] : map) { encodableMap.insert({ make_fl_value(key), make_fl_value(val) }); } return encodableMap; } template static inline flutter::EncodableValue make_fl_value(const std::optional& optional) { return optional.has_value() ? make_fl_value(optional.value()) : make_fl_value(); } template static inline flutter::EncodableValue make_fl_value(const std::optional>& optional) { if (!optional.has_value()) { return make_fl_value(); } auto& vecValue = optional.value(); auto encodableList = flutter::EncodableList{}; for (auto const& val : vecValue) { encodableList.push_back(make_fl_value(val)); } return encodableList; } template static inline flutter::EncodableValue make_fl_value(const std::optional>& optional) { if (!optional.has_value()) { return make_fl_value(); } auto& mapValue = optional.value(); auto encodableMap = flutter::EncodableMap{}; for (auto const& [key, val] : mapValue) { encodableMap.insert({ make_fl_value(key), make_fl_value(val) }); } return encodableMap; } template static inline T get_fl_map_value(const flutter::EncodableMap& map, const char* string) { return std::get(map.at(make_fl_value(string))); } template static inline std::optional get_optional_fl_map_value(const flutter::EncodableMap& map, const char* string) { return make_pointer_optional(std::get_if(&map.at(make_fl_value(string)))); } template static inline std::optional> get_optional_fl_map_value(const flutter::EncodableMap& map, const char* string) { auto flMap = std::get_if(&map.at(make_fl_value(string))); if (flMap) { auto mapValue = std::map{}; for (auto itr = flMap->begin(); itr != flMap->end(); itr++) { mapValue.insert({ std::get(itr->first), std::get(itr->second) }); } return make_pointer_optional>(&mapValue); } return std::nullopt; } } #endif //FLUTTER_INAPPWEBVIEW_PLUGIN_FLUTTER_UTIL_H_