@@ -26,7 +26,8 @@ mixin FieldsHolder {
2626
2727 /// The complete schema of the [FieldsHolder] 's [fields] .
2828 dynamic get fieldSchema => {
29- for (final MapEntry (: key, : value) in fields.entries) key: value.fieldSchema,
29+ for (final MapEntry (: key, : value) in fields.entries)
30+ key: value.fieldSchema,
3031 };
3132}
3233
@@ -304,3 +305,40 @@ final class RadiusFieldAccess extends FieldAccess<CornerRadius> {
304305 @override
305306 void setValue (Object ? value) => setter (value.typedValue <CornerRadius >()! );
306307}
308+
309+ /// A field accessor for variants.
310+ final class VariantAccess extends FieldAccess <String > {
311+ /// Constructs a new [VariantAccess] instance with the given parameters.
312+ const VariantAccess (
313+ super .label,
314+ super .description,
315+ super .getValue,
316+ super .setter, {
317+ required super .defaultValue,
318+ // Variant ID -> Variant Name.
319+ required FieldOptionsGetter <String > options,
320+ }) : getOptions = options;
321+
322+ /// The options of the field. Variant ID -> Variant Name.
323+ final FieldOptionsGetter <String > getOptions;
324+
325+ @override
326+ String get dynamicKeyType => 'options' ;
327+
328+ @override
329+ dynamic serialize (String ? obj) => obj;
330+
331+ @override
332+ Map <String , dynamic > get supplementarySchema => {
333+ 'options' : {
334+ for (final String name in getOptions ()) name: name,
335+ },
336+ };
337+
338+ @override
339+ void setValue (Object ? value) {
340+ if (value case String ? value) {
341+ setter (value ?? getDefaultValue !());
342+ }
343+ }
344+ }
0 commit comments