Skip to content

Repository files navigation

⚠️ Migration Notice: This plugin is being migrated to libnativeapi/nativeapi-flutter

The new version is based on a unified C++ core library (libnativeapi/nativeapi), providing more complete and consistent cross-platform native API support. r

pub version

This plugin allows Flutter desktop apps to defines system tray.

English | 简体中文


Platform Support

LinuxmacOSWindows
✔️✔️✔️

Screenshots

macOSLinuxWindows
image

Known Issues

Not Working with app_links

When using the app_links package together with tray_manager, the plugin may not work properly. This is because older versions of app_links internally block event propagation, preventing menu click events from being triggered.

To resolve this issue:

  1. Make sure your app_links package version is greater than or equal to 6.3.3
dependencies:
app_links: ^6.3.3
  1. Use protocol_handler package instead of app_links package.

Not Showing in GNOME

In GNOME desktop environment, the AppIndicator extension may be required to display the icon.

Quick Start

Installation

Add this to your package's pubspec.yaml file:

dependencies:
tray_manager: ^0.5.2

Or

dependencies:
tray_manager:
git:
url: https://github.com/leanflutter/tray_manager.gitref: mainpath: packages/tray_manager

Linux requirements

  • ayatana-appindicator3-0.1 or appindicator3-0.1

Run the following command

sudo apt-get install libayatana-appindicator3-dev

Or

sudo apt-get install appindicator3-0.1 libappindicator3-dev

Usage

import'package:flutter/material.dart'hide MenuItem;
import'package:tray_manager/tray_manager.dart';
await trayManager.setIcon(
Platform.isWindows
?'images/tray_icon.ico':'images/tray_icon.png',
);
Menu menu =Menu(
items: [
MenuItem(
key:'show_window',
label:'Show Window',
),
MenuItem.separator(),
MenuItem(
key:'exit_app',
label:'Exit App',
),
],
);
await trayManager.setContextMenu(menu);

Please see the example app of this plugin for a full example.

Listening events

import'package:flutter/material.dart';
import'package:tray_manager/tray_manager.dart';
classHomePageextendsStatefulWidget {
@override_HomePageStatecreateState() =>_HomePageState();
}
class_HomePageStateextendsState<HomePage> withTrayListener {
@overridevoidinitState() {
trayManager.addListener(this);
super.initState();
_init();
}
@overridevoiddispose() {
trayManager.removeListener(this);
super.dispose();
}
void_init() {
// ...
}
@overrideWidgetbuild(BuildContext context) {
// ...
}
@overridevoidonTrayIconMouseDown() {
// do something, for example pop up the menu
trayManager.popUpContextMenu();
}
@overridevoidonTrayIconRightMouseDown() {
// do something
}
@overridevoidonTrayIconRightMouseUp() {
// do something
}
@overridevoidonTrayMenuItemClick(MenuItem menuItem) {
if (menuItem.key =='show_window') {
// do something
} elseif (menuItem.key =='exit_app') {
// do something
}
}
}

Who's using it?

API

TrayManager

MethodDescriptionLinuxmacOSWindows
destroyDestroys the tray icon immediately.✔️✔️✔️
setIconSets the image associated with this tray icon.✔️✔️✔️
setIconPositionSets the icon position of the tray icon.✔️
setToolTipSets the hover text for this tray icon.✔️✔️
setContextMenuSets the context menu for this icon.✔️✔️✔️
popUpContextMenuPops up the context menu of the tray icon.✔️✔️
getBoundsReturns Rect The bounds of this tray icon.✔️✔️

License

MIT

About

This plugin allows Flutter desktop apps to defines system tray.

Topics

Resources

Stars

303 stars

Watchers

3 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages