toChannelRepresentation method
- PlatformMenuDelegate delegate, {
- required MenuItemSerializableIdGenerator getId,
override
Converts the representation of this item into a map suitable for sending over the default "flutter/menu" channel used by DefaultPlatformMenuDelegate.
The delegate
is the PlatformMenuDelegate that is requesting the
serialization.
The getId
parameter is a MenuItemSerializableIdGenerator function that
generates a unique ID for each menu item, which is to be returned in the
"id" field of the menu item data.
Implementation
@override
Iterable<Map<String, Object?>> toChannelRepresentation(
PlatformMenuDelegate delegate, {
required MenuItemSerializableIdGenerator getId,
}) {
assert(() {
if (!hasMenu(type)) {
throw ArgumentError(
'Platform ${defaultTargetPlatform.name} has no platform provided menu for '
'$type. Call PlatformProvidedMenuItem.hasMenu to determine this before '
'instantiating one.',
);
}
return true;
}());
return <Map<String, Object?>>[
<String, Object?>{
_kIdKey: getId(this),
_kEnabledKey: enabled,
_kPlatformDefaultMenuKey: type.index,
},
];
}