Я использую Flutter 3.16.9 и создаю приложение для Windows, Linux и Macos.
Я попробовал настроить канал платформы на cpp. К сожалению, импортировать «std» не удалось. Этот код был сгенерирован Chatgpt.
#include
#include
#include
#include "flutter_window.h"
#include "utils.h"
#include
#include
#include
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command)
{
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent())
{
CreateAndAttachConsole();
}
// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data");
std::vector command_line_arguments =
GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.Create(L"Default_Title", origin, size))
{
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);
// Настройка платформенного канала
auto channel = std::make_unique(
window.flutter_controller()->engine(), "com.example/window_title",
&flutter::StandardMethodCodec::GetInstance());
channel->SetMethodCallHandler(
[](const flutter::MethodCall &call,
std::unique_ptr result)
{
if (call.method_name() == "changeWindowTitle")
{
const auto *arguments = std::get_if(call.arguments());
if (arguments)
{
HWND hwnd = GetActiveWindow();
if (hwnd)
{
SetWindowTextA(hwnd, arguments->c_str());
result->Success();
}
else
{
result->Error("WINDOW_NOT_FOUND", "Could not find the window.");
}
}
else
{
result->Error("INVALID_ARGUMENT", "Argument is not a string.");
}
}
else
{
result->NotImplemented();
}
});
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}
В этом коде есть две ошибки:
- ни один экземпляр перегруженной функции "std::make_unique" не соответствует список аргументов;
- класс «FlutterWindow» не имеет члена «flutter_controller».
class WindowService {
static const platform = MethodChannel('com.example/window_title');
static Future changeWindowTitle(String? title) async {
try {
await platform.invokeMethod('changeWindowTitle', title ?? 'Default Title');
} on PlatformException catch (e) {
print(e);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... pp-flutter
Мобильная версия