pushDynamicShortcut method

  1. @override
Future<bool> pushDynamicShortcut(
  1. Map<String, Object?> shortcut
)
override

Publishes a launcher shortcut the app manages itself.

Returns whether the platform did anything. False on iOS, and not as a stand-in for an error: there is nothing there to publish to. The iOS counterpart of the same intention is donate, which is a different mechanism rather than the same one under another name — see DynamicShortcut.

Implementation

@override
Future<bool> pushDynamicShortcut(Map<String, Object?> shortcut) async {
  if (shortcutSlots == 0) return false;
  final id = shortcut['id'];
  // Same id replaces in place rather than appending, which is what
  // ShortcutManager does and what a test asserting on a list needs to see.
  final existing = shortcuts.indexWhere((s) => s['id'] == id);
  if (existing >= 0) {
    shortcuts[existing] = Map.unmodifiable(shortcut);
    return true;
  }
  if (shortcuts.length >= shortcutSlots) return false;
  shortcuts.add(Map.unmodifiable(shortcut));
  return true;
}