TrayIconWidget constructor

TrayIconWidget({
  1. Key? key,
  2. required Widget child,
  3. bool? visible = true,
  4. bool addToContext = true,
  5. String? tooltip,
  6. EventCallback? onTap,
  7. EventCallback? onSecondaryTap,
  8. EventCallback? onTapDown,
  9. EventCallback? onSecondaryTapDown,
  10. EventCallback? onTertiaryTapDown,
  11. EventCallback? onTapUp,
  12. EventCallback? onSecondaryTapUp,
  13. EventCallback? onTertiaryTapUp,
  14. EventCallback? onDoubleTap,
  15. EventCallback? onSecondaryDoubleTap,
  16. EventCallback? onTertiaryDoubleTap,
  17. EventCallback? onPointerMove,
  18. TrayIconImageDelegate? imageDelegate,
  19. ByteBuffer? imagePixels,
  20. String? imageAsset,
  21. Uri? imagePath,
  22. StockIcon? stockIcon,
  23. WinIcon? winIcon,
})

Manages a TrayIcon as a StatefulWidget.

The underlying resource will automatically be disposed according to the lifecycle of the StatefulWidget.

Rebuilding this TrayIconWidget will different parameters will update the icon.

Contrary to TrayIcon.setImage, if tooltip or any of the image related fields are null, the current values are kept. This is to ensure that rebuilds don't interfere with using the TrayIcon widget directly through. TrayIcon.of(BuildContext context).

For pixels, you should note that {@macro betrayal.image.pixels}

For more information on the parameters, check out TrayIconImageDelegate.

Implementation

TrayIconWidget(
    {Key? key,
    required this.child,
    this.visible = true,
    this.addToContext = true,
    this.tooltip,
    EventCallback onTap,
    EventCallback onSecondaryTap,
    EventCallback onTapDown,
    EventCallback onSecondaryTapDown,
    EventCallback onTertiaryTapDown,
    EventCallback onTapUp,
    EventCallback onSecondaryTapUp,
    EventCallback onTertiaryTapUp,
    EventCallback onDoubleTap,
    EventCallback onSecondaryDoubleTap,
    EventCallback onTertiaryDoubleTap,
    EventCallback onPointerMove,
    TrayIconImageDelegate? imageDelegate,
    ByteBuffer? imagePixels,
    String? imageAsset,
    Uri? imagePath,
    StockIcon? stockIcon,
    WinIcon? winIcon})
    : super(key: key) {
  if (imageDelegate != null) {
    _delegate = imageDelegate;
  } else if (imagePixels != null) {
    _delegate = TrayIconImageDelegate.fromBytes(imagePixels);
  } else if (imageAsset != null) {
    _delegate = TrayIconImageDelegate.fromAsset(imageAsset);
  } else if (imagePath != null) {
    _delegate = TrayIconImageDelegate.fromPath(uri: imagePath);
  } else if (stockIcon != null) {
    _delegate = TrayIconImageDelegate.fromStockIcon(stockIcon);
  } else if (winIcon != null) {
    _delegate = TrayIconImageDelegate.fromWinIcon(winIcon);
  } else {
    _delegate = null;
  }

  _callbacks = {
    WinEvent.select: onTap,
    WinEvent.leftButtonDoubleClick: onDoubleTap,
    WinEvent.leftButtonDown: onTapDown,
    WinEvent.leftButtonUp: onTapUp,
    WinEvent.contextMenu: onSecondaryTap,
    WinEvent.rightButtonDown: onSecondaryTapDown,
    WinEvent.rightButtonUp: onSecondaryTapUp,
    WinEvent.rightButtonDoubleClick: onSecondaryDoubleTap,
    WinEvent.middleButtonDown: onTertiaryTapDown,
    WinEvent.middleButtonUp: onTertiaryTapUp,
    WinEvent.middleButtonDoubleClick: onTertiaryDoubleTap,
    WinEvent.mouseMove: onPointerMove,
  };
}