tray_manager 0.1.2 copy "tray_manager: ^0.1.2" to clipboard
tray_manager: ^0.1.2 copied to clipboard

outdated

This plugin allows Flutter desktop apps to defines system tray.

tray_manager #

pub version

This plugin allows Flutter desktop apps to defines system tray.

Discord


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 #

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.

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.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
    }
  }
}

API #

TrayManager #

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. ✔️ ✔️ ✔️

License #

MIT License

Copyright (c) 2021 LiJianying <lijy91@foxmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
165
likes
0
pub points
95%
popularity

Publisher

verified publisherleanflutter.dev

This plugin allows Flutter desktop apps to defines system tray.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, path, uuid

More

Packages that depend on tray_manager