This plugin allows Flutter desktop apps to defines system tray.
| Linux | macOS | Windows |
|---|---|---|
| ✔️ | ✔️ | ✔️ |
Add this to your package's pubspec.yaml file:
dependencies:
tray_manager: ^0.1.2Or
dependencies:
tray_manager:
git:
url: https://github.com/leanflutter/tray_manager.git
ref: mainappindicator3-0.1
Run the following command
sudo apt-get install appindicator3-0.1 libappindicator3-dev
Register/Unregsiter a system/inapp wide hot key.
import 'package:tray_manager/tray_manager.dart';
await TrayManager.instance.setIcon(
Platform.isWindows
? 'images/tray_icon.ico'
: 'images/tray_icon.png',
);
List<MenuItem> items = [
MenuItem(
key: 'show_window',
title: 'Show Window',
),
MenuItem.separator,
MenuItem(
key: 'exit_app',
title: 'Exit App',
),
];
await TrayManager.instance.setContextMenu(items);Please see the example app of this plugin for a full example.
import 'package:flutter/material.dart';
import 'package:tray_manager/tray_manager.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with TrayListener {
@override
void initState() {
TrayManager.instance.addListener(this);
super.initState();
_init();
}
@override
void dispose() {
TrayManager.instance.removeListener(this);
super.dispose();
}
void _init() {
// ...
}
@override
Widget build(BuildContext context) {
// ...
}
@override
void onTrayIconMouseDown() {
// do something
}
@override
void onTrayIconRightMouseDown() {
// do something
}
@override
void onTrayIconRightMouseUp() {
// do something
}
@override
void onTrayMenuItemClick(MenuItem menuItem) {
if (menuItem.key == 'show_window') {
// do something
} else if (menuItem.key == 'exit_app') {
// do something
}
}
}| Method | Description | Linux | macOS | Windows |
|---|---|---|---|---|
| destroy | Destroys the tray icon immediately. | ✔️ | ✔️ | ✔️ |
| setIcon | Sets the image associated with this tray icon. | ✔️ | ✔️ | ✔️ |
| setContextMenu | - | ✔️ | ✔️ | ✔️ |
| popUpContextMenu | Pops up the context menu of the tray icon. When menu is passed, the menu will be shown instead of the tray icon's context menu. | ➖ | ✔️ | ✔️ |
| getBounds | Returns Rect The bounds of this tray icon. |
✔️ | ✔️ | ✔️ |