A Flutter package that that enables support for system tray menu for desktop flutter apps. on Windows, macOS and Linux.
Install the package using pubspec.yaml
Below we show how to use system_tray
Future<void> initSystemTray() async {
String path;
if (Platform.isWindows) {
path = p.joinAll([
p.dirname(Platform.resolvedExecutable),
'data/flutter_assets/assets',
'app_icon.ico'
]);
} else if (Platform.isMacOS) {
path = p.joinAll(['AppIcon']);
} else {
path = p.joinAll([
p.dirname(Platform.resolvedExecutable),
'data/flutter_assets/assets',
'app_icon.png'
]);
}
// We first init the systray menu and then add the menu entries
await _systemTray.initSystemTray("system tray",
iconPath: path, toolTip: "How to use system tray with Flutter");
await _systemTray.setContextMenu(
[
MenuItem(
label: 'Show',
onClicked: () {
appWindow.show();
},
),
MenuSeparator(),
SubMenu(
label: "SubMenu",
children: [
MenuItem(
label: 'SubItem1',
enabled: false,
onClicked: () {
print("click SubItem1");
},
),
MenuItem(label: 'SubItem2'),
MenuItem(label: 'SubItem3'),
],
),
MenuSeparator(),
MenuItem(
label: 'Exit',
onClicked: () {
appWindow.close();
},
),
],
);
}
}