serialize method Null safety

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

Converts the supplied object to the correct channel representation for the 'flutter/menu' channel.

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

Implementation

static Map<String, Object?> serialize(
  PlatformMenu item,
  PlatformMenuDelegate delegate,
  MenuItemSerializableIdGenerator getId,
) {
  final List<Map<String, Object?>> result = <Map<String, Object?>>[];
  int index = 0;
  for (final MenuItem childItem in item.menus) {
    result.addAll(childItem.toChannelRepresentation(
      delegate,
      index: index,
      count: item.menus.length,
      getId: getId,
    ));
    index += 1;
  }
  return <String, Object?>{
    _kIdKey: getId(item),
    _kLabelKey: item.label,
    _kEnabledKey: item.menus.isNotEmpty,
    _kChildrenKey: result,
  };
}