Created
January 10, 2025 20:44
-
-
Save loic-sharma/45aa1f5820264c929e31a193f2359413 to your computer and use it in GitHub Desktop.
Headless Flutter Windows app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <flutter/dart_project.h> | |
#include <flutter/flutter_view_controller.h> | |
#include <flutter/generated_plugin_registrant.h> | |
#include <windows.h> | |
#include "flutter_window.h" | |
#include "utils.h" | |
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<std::string> command_line_arguments = | |
GetCommandLineArguments(); | |
project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); | |
// Create an engine and launch it. | |
flutter::FlutterEngine engine(project); | |
if (!engine.Run()) { | |
return EXIT_FAILURE; | |
} | |
::MSG msg; | |
while (::GetMessage(&msg, nullptr, 0, 0)) { | |
::TranslateMessage(&msg); | |
::DispatchMessage(&msg); | |
} | |
::CoUninitialize(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment