Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antler119/system_tray
A Flutter package that makes it easy to customize and work with your Flutter desktop app's system tray.
https://github.com/antler119/system_tray
flutter linux macos windows
Last synced: 3 months ago
JSON representation
A Flutter package that makes it easy to customize and work with your Flutter desktop app's system tray.
- Host: GitHub
- URL: https://github.com/antler119/system_tray
- Owner: antler119
- License: mit
- Created: 2021-07-16T06:13:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-19T10:45:19.000Z (4 months ago)
- Last Synced: 2024-07-23T02:41:38.544Z (4 months ago)
- Topics: flutter, linux, macos, windows
- Language: C++
- Homepage:
- Size: 1.89 MB
- Stars: 214
- Watchers: 3
- Forks: 48
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-flutter-desktop - system_tray - system_tray that makes it easy to customize tray and work with your Flutter desktop app. (Packages)
README
# system_tray
[![Pub](https://img.shields.io/pub/v/system_tray.svg)](https://pub.dartlang.org/packages/system_tray)
A [Flutter package](https://github.com/antler119/system_tray.git) that enables support for system tray menu for desktop flutter apps. **on Windows, macOS, and Linux**.
## Install
In the pubspec.yaml of your flutter project, add the following dependency:
```yaml
dependencies:
...
system_tray: ^2.0.3
```In your library add the following import:
```dart
import 'package:system_tray/system_tray.dart';
```## Prerequisite
### Linux
```bash
sudo apt-get install appindicator3-0.1 libappindicator3-dev
```
or```bash
// For Ubuntu 22.04 or greater
sudo apt-get install libayatana-appindicator3-dev
```## Example App
### Windows
### macOS
### Linux
## API
Method
Description
Windows
macOS
Linux
initSystemTray
Initialize system tray
✔️
✔️
✔️
setSystemTrayInfo
Modify the tray info
- icon
- toolTip
- title
- icon
- toolTip
- icon
setImage
Modify the tray image
✔️
✔️
✔️
setTooltip
Modify the tray tooltip
✔️
✔️
➖
setTitle / getTitle
Set / Get the tray title
➖
✔️
➖
setContextMenu
Set the tray context menu
✔️
✔️
✔️
popUpContextMenu
Popup the tray context menu
✔️
✔️
➖
destroy
Destroy the tray
✔️
✔️
✔️
registerSystemTrayEventHandler
Register system tray event
- click
- right-click
- double-click
- click
- right-click
➖
## Menu
Type
Description
Windows
macOS
Linux
MenuItemLabel
✔️
✔️
✔️
MenuItemCheckbox
✔️
✔️
✔️
SubMenu
✔️
✔️
✔️
MenuSeparator
✔️
✔️
✔️
## Usage
```dart
Future initSystemTray() async {
String path =
Platform.isWindows ? 'assets/app_icon.ico' : 'assets/app_icon.png';
final AppWindow appWindow = AppWindow();
final SystemTray systemTray = SystemTray();
// We first init the systray menu
await systemTray.initSystemTray(
title: "system tray",
iconPath: path,
);
// create context menu
final Menu menu = Menu();
await menu.buildFrom([
MenuItemLabel(label: 'Show', onClicked: (menuItem) => appWindow.show()),
MenuItemLabel(label: 'Hide', onClicked: (menuItem) => appWindow.hide()),
MenuItemLabel(label: 'Exit', onClicked: (menuItem) => appWindow.close()),
]);
// set context menu
await systemTray.setContextMenu(menu);
// handle system tray event
systemTray.registerSystemTrayEventHandler((eventName) {
debugPrint("eventName: $eventName");
if (eventName == kSystemTrayEventClick) {
Platform.isWindows ? appWindow.show() : systemTray.popUpContextMenu();
} else if (eventName == kSystemTrayEventRightClick) {
Platform.isWindows ? systemTray.popUpContextMenu() : appWindow.show();
}
});
}
```
## Additional Resources
Recommended library that supports window control:
- [bitsdojo_window](https://pub.dev/packages/bitsdojo_window)
- [window_size (Google)](https://github.com/google/flutter-desktop-embedding/tree/master/plugins/window_size)
## Q&A
1. Q: If you encounter the following compilation error
```C++
Undefined symbols for architecture x86_64:
"___gxx_personality_v0", referenced from:
...
```
A: add **libc++.tbd**
```bash
1. open example/macos/Runner.xcodeproj
2. add 'libc++.tbd' to TARGET runner 'Link Binary With Libraries'
```