Skip to content

This plugin allows Flutter desktop apps to defines system tray.

License

Notifications You must be signed in to change notification settings

Arne1346/tray_manager

 
 

Repository files navigation

tray_manager

pub version

This plugin allows Flutter desktop apps to defines system tray.


English | 简体中文


Platform Support

Linux macOS Windows
✔️ ✔️ ✔️

Quick Start

Installation

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

dependencies:
  tray_manager: ^0.1.2

Or

dependencies:
  tray_manager:
    git:
      url: https://github.com/leanflutter/tray_manager.git
      ref: main

⚠️ Linux requirements

  • appindicator3-0.1

Run the following command

sudo apt-get install appindicator3-0.1 libappindicator3-dev

Usage

import 'package:tray_manager/tray_manager.dart';

await trayManager.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.setContextMenu(items);

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';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with TrayListener {
  @override
  void initState() {
    trayManager.addListener(this);
    super.initState();
    _init();
  }

  @override
  void dispose() {
    trayManager.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
    }
  }
}

Who's using it?

API

TrayManager

Method Description Linux macOS Windows
destroy Destroys the tray icon immediately. ✔️ ✔️ ✔️
setIcon Sets the image associated with this tray icon. ✔️ ✔️ ✔️
setToolTip Sets the hover text for this tray icon. ✔️ ✔️
setContextMenu Sets the context menu for this icon. ✔️ ✔️ ✔️
popUpContextMenu Pops up the context menu of the tray icon. ✔️ ✔️
getBounds Returns Rect The bounds of this tray icon. ✔️ ✔️

License

MIT

About

This plugin allows Flutter desktop apps to defines system tray.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 51.0%
  • CMake 19.6%
  • Dart 14.6%
  • Swift 9.4%
  • C 3.0%
  • Ruby 2.4%