lazyEnum static method

CustomLayout<Map<String, dynamic>, Map<String, dynamic>> lazyEnum(
  1. List<LazyVariantModel> variants, {
  2. IntegerLayout? discriminant,
  3. String? property,
  4. bool useKeyAndValue = true,
})

Implementation

static CustomLayout<Map<String, dynamic>, Map<String, dynamic>> lazyEnum(
  List<LazyVariantModel> variants, {
  IntegerLayout? discriminant,
  String? property,
  bool useKeyAndValue = true,
}) {
  final unionLayout = LazyUnion(discriminant ?? u8());
  variants
      .asMap()
      .forEach((index, variant) => unionLayout.addVariant(variant));
  return CustomLayout<Map<String, dynamic>, Map<String, dynamic>>(
      layout: unionLayout,
      decoder: (value) {
        if (useKeyAndValue) {
          return {"key": value.keys.first, "value": value.values.first};
        }
        return value;
      },
      encoder: (src) {
        return src;
      },
      property: property);
}