TrayIconImageDelegate.fromPath constructor

TrayIconImageDelegate.fromPath(
  1. {Uri? uri,
  2. String? path}
)

A TrayIconImageDelegate that uses a .ico file.

If both uri and path are given, uri takes precedence. path needs to use Windows style \\ notation.

Implementation

TrayIconImageDelegate.fromPath({Uri? uri, String? path}) {
  if (uri == null && path == null) {
    throw ArgumentError("Either uri or path must be specified.");
  }

  if (uri != null) {
    if (uri.scheme != 'file') {
      throw ArgumentError("Only file:// URIs are supported.");
    }

    path = uri.toFilePath(windows: true);
  }

  if (!path!.endsWith(".ico")) {
    _logger.warning("""'$path' is not an .ico file.
Continuing under the assumption that only the file extension is wrong""");
  }

  setIcon = (id, plugin) => plugin.setImageFromPath(id, path!);
}