enum CameraFeature { spotMetering, histogram, showFocalLength, } typedef CameraFeaturesConfig = Map; extension CameraFeaturesConfigJson on CameraFeaturesConfig { static CameraFeaturesConfig fromJson(Map data) { MapEntry valueOrBool(CameraFeature feature, {bool defaultValue = true}) => MapEntry( feature, data[feature.name] as bool? ?? defaultValue, ); return Map.fromEntries( [ valueOrBool(CameraFeature.spotMetering), valueOrBool(CameraFeature.histogram, defaultValue: false), valueOrBool(CameraFeature.showFocalLength), ], ); } Map toJson() => map((key, value) => MapEntry(key.name, value)); }