notify method

Future<Notification> notify(
  1. String summary, {
  2. String body = '',
  3. String appName = '',
  4. String appIcon = '',
  5. int expireTimeoutMs = -1,
  6. int replacesId = 0,
  7. List<NotificationHint> hints = const [],
  8. List<NotificationAction> actions = const [],
})

Sends a notification with a summary and optional body.

appName is a human readable name for the application that generated the notification, e.g. 'Firefox Browser'. appIcon is either a URI (e.g. 'file:///usr/share/icons/firefox.png') or an icon theme name (e.g. 'web-browser'). expireTimeoutMs specified the expiration timeout in milliseconds with -1 used for the system default and 0 for no expiration. replacesId is the ID of an existing notification this notification replaces. actions is a list of actions the user can perform on this notification. hints is a list of hints about how the notification should be shown.

Returns an object representing the notification.

Implementation

Future<Notification> notify(String summary,
    {String body = '',
    String appName = '',
    String appIcon = '',
    int expireTimeoutMs = -1,
    int replacesId = 0,
    List<NotificationHint> hints = const [],
    List<NotificationAction> actions = const []}) async {
  _subscribeSignals();

  var actionsValues = <String>[];
  for (var action in actions) {
    actionsValues.add(action.key);
    actionsValues.add(action.label);
  }
  var hintsValues = <String, DBusValue>{};
  for (var hint in hints) {
    if (hint.key == '*location') {
      var locationValues = (hint.value as DBusStruct).children;
      hintsValues['x'] = locationValues.elementAt(0);
      hintsValues['y'] = locationValues.elementAt(1);
    } else {
      hintsValues[hint.key] = hint.value;
    }
  }
  var result = await _object.callMethod(
      'org.freedesktop.Notifications',
      'Notify',
      [
        DBusString(appName),
        DBusUint32(replacesId),
        DBusString(appIcon),
        DBusString(summary),
        DBusString(body),
        DBusArray.string(actionsValues),
        DBusDict.stringVariant(hintsValues),
        DBusInt32(expireTimeoutMs)
      ],
      replySignature: DBusSignature('u'));
  var id = (result.returnValues[0] as DBusUint32).value;

  return Notification(this, id);
}