serialize static method

Map<String, Object?> serialize(
  1. PlatformMenuItem item,
  2. PlatformMenuDelegate delegate,
  3. MenuItemSerializableIdGenerator getId
)

Converts the given PlatformMenuItem into a data structure accepted by the 'flutter/menu' method channel method 'Menu.SetMenu'.

This API is supplied so that implementers of PlatformMenuItem can share this implementation.

Implementation

static Map<String, Object?> serialize(
  PlatformMenuItem item,
  PlatformMenuDelegate delegate,
  MenuItemSerializableIdGenerator getId,
) {
  final MenuSerializableShortcut? shortcut = item.shortcut;
  return <String, Object?>{
    _kIdKey: getId(item),
    _kLabelKey: item.label,
    _kEnabledKey: item.onSelected != null || item.onSelectedIntent != null,
    if (shortcut != null)...shortcut.serializeForMenu().toChannelRepresentation(),
  };
}