4

I've a flutter desktop linux app and I want to set icon app so when I build the app by typing this command flutter build linux the executable file got this icon and this icon appears at the taskbar.

At this moment the executable file has set a generic icon and when the app is running then the taskbar shows an empty icon.

enter image description here

I've read the answer on https://stackoverflow.com/a/73134323/9301998 but this only shows the icon on the taskbar if I run the app typing the command flutter run -d linux but when I build the app by typing this command flutter build linux it's not assign the icon that I want.

The image that I want to set as icon I've added as assets in the pubspec.yaml file.

Then I've created a my_app.desktop file with:

[Desktop Entry]
Version=1.0
Type=Application
Name=my_app
Exec=/home/pepe/my_app/build/linux/x64/release/bundle/my_app
Icon=/home/pepe/my_app/build/linux/x64/release/bundle/data/flutter_assets/assets/images/logo.ico
Comment=Welcome to the flutterverse!
Categories=Development;
Terminal=false
StartupNotify=true;

Then I can see the icon on the desktop, I still add the app as favorite to the taskbar, but when I click on the icon to run the app it runs but it continues adding an empty icon in the taskbar.

This article explains How to change icon of linux desktop app but it's through snapstore and I would like to do this when I build the app by typing this command flutter build linux directly.

its-me-mahmud
7091 gold badge7 silver badges15 bronze badges
asked May 27, 2023 at 5:20
2
  • @nategurutech, No yet. Commented Apr 10, 2024 at 19:25
  • @kumar, no so far. Commented Apr 23, 2024 at 12:37

1 Answer 1

2

I found a workaround to update the generated code in 'linux/my_application.cc' file. Hope this can help you.

// Implements GApplication::activate.
static void my_application_activate(GApplication* application) {
 MyApplication* self = MY_APPLICATION(application);
 GtkWindow* window =
 GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
 // set icon 
 GdkPixbuf* icon = gdk_pixbuf_new_from_file("/home/mingxi/Work/Code/flutter-projects/flutter_application_1/assets/images/flutter_logo.png", NULL);
 if (icon != NULL) {
 gtk_window_set_icon(GTK_WINDOW(window), icon);
 g_object_unref(icon);
 }
 // Use a header bar when running in GNOME as this is the common style used
 // by applications and is the setup most users will be using (e.g. Ubuntu
 // desktop).
 // If running on X and not using GNOME then just use a traditional title bar
 // in case the window manager does more exotic layout, e.g. tiling.
 // If running on Wayland assume the header bar will work (may need changing
 // if future cases occur).
 gboolean use_header_bar = TRUE;

click here for details

answered Apr 28, 2024 at 7:37
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.