toMap method

Map<String, dynamic> toMap({
  1. EnumMethod? enumMethod,
})

Implementation

Map<String, dynamic> toMap({EnumMethod? enumMethod}) {
  Map<String, dynamic> map = {
    "type": switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue => type.toNativeValue(),
      EnumMethod.value => type.toValue(),
      EnumMethod.name => type.name(),
    },
    "selector": selector,
  };

  map.keys
      .where(
        (key) =>
            map[key] == null ||
            (map[key] is List && (map[key] as List).length == 0),
      ) // filter keys
      .toList() // create a copy to avoid concurrent modifications
      .forEach(map.remove);

  return map;
}