Skip to content

Instantly share code, notes, and snippets.

@petlyh
Last active December 5, 2025 20:18
Show Gist options
  • Select an option

  • Save petlyh/0b52d80028534364ce89b62beae6c51c to your computer and use it in GitHub Desktop.

Select an option

Save petlyh/0b52d80028534364ce89b62beae6c51c to your computer and use it in GitHub Desktop.
Simple guide on how to setup app icon for Flutter on Linux

How to setup app icon for Flutter on Linux

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.png

Next, 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_X11

Finally, 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 used

If 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()
// linux/my_application.cc
// at the start of the file
#include <filesystem>
using namespace std;
using namespace std::filesystem;
// inside my_application_activate after the window declaration
const string iconFilename = "<ICON_ASSET_PATH>";
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);
@exoad
Copy link

exoad commented Dec 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment