First, add your icon as a Flutter asset in pubspec.yaml if you haven't already:
flutter:
uses-material-design: true
assets:
- CHANGELOG.md
+ - assets/icon.pngNext, add the following #include and using statements to the start of linux/my_application.cc:
+#include <filesystem>
+using namespace std;
+using namespace std::filesystem;
#include "my_application.h"
#include <flutter_linux/flutter_linux.h>
#ifdef GDK_WINDOWING_X11Finally, in the same file, add the following code inside my_application_activate right after the window variable is declared. Make sure to replace assets/icon.png with the icon filename you specified in pubspec.yaml if it differs.
static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application);
GtkWindow* window =
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
+ const string iconFilename = "assets/icon.png";
+ path execDir = canonical(read_symlink("/proc/self/exe")).parent_path();
+ path iconPath = execDir / "data/flutter_assets" / iconFilename;
+ gtk_window_set_icon_from_file(GTK_WINDOW(window), iconPath.c_str(), NULL);
// Use a header bar when running in GNOME as this is the common style usedIf you get a compilation error telling you that the filesystem namespace could not be found, you'll have to update the C++ standard version to 17 by modifying linux/CMakeLists.txt:
function(APPLY_STANDARD_SETTINGS TARGET)
- target_compile_features(${TARGET} PUBLIC cxx_std_14)
+ target_compile_features(${TARGET} PUBLIC cxx_std_17)
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
endfunction()
Thank you! Works, however is there any other way to just pack another image with the Linux build? Similar to how the Windows build does already.