Launching LIB/MAIN.dart on Linux in Debug Mode ...
main.dart: 1
Connecting to VM Service at WS: //127.0.0.1: 43941/ys2xpakwnnq =/WS
Method Call Initappwindow
Method Call initsystemtray
Lost Connection to Device.
My pubspec.yaml
assets:
- assets/
MyCode
Future<void> initSystemTray() async {
String path = Platform.isWindows ? 'assets/zip.ico' : 'assets/zip.png';
final AppWindow appWindow = AppWindow();
final SystemTray systemTray = SystemTray();
// We first init the systray menu
try {
await systemTray.initSystemTray(title: "system tray", iconPath: path, toolTip: 'test');
} catch (err) {
debugPrint("Err: $err");
}
// 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();
}
});
}
Hello, guys!
I just copied the Github code of the example and include a try/catch.
When it enters the line: Below the program closes alone.
Await systemtray.initsystemtray (title: "System tray," iconpath: Path, Tooltip: 'Test');
VSCODE -> Debug Console
My pubspec.yaml
MyCode
# Trying another way![image](https://user-images.githubusercontent.com/82031362/233710429-610c57ae-8ea9-42f3-a248-8209756df5e6.png)