build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Builds the enum selection UI based on the configured mode, rendering either a themed Select dropdown or a CardCarousel of interactive cards, wrapped in ArcaneFieldWrapper<T>.

This method retrieves the current T value from the ArcaneField<T> provider, determines the mode (auto if null), and constructs the appropriate widget tree. For dropdown, it uses a Card container with Select<T> , applying a stacked itemBuilder for dynamic popup sizing via PopoverConstraint.anchorMaxSize, and populates SelectPopup with SelectItemButton children. For cards, it creates a CardCarousel with tappable Card widgets, using cardBuilder or fallback, highlighting the selected with border and color from theme. On change, updates provider with new value or default if null. Returns a Widget optimized for form integration; no side effects beyond provider sets; efficient with const elements where possible.

Implementation

@override
Widget build(BuildContext context) {
  ArcaneField<T> field = context.pylon<ArcaneField<T>>();
  return ArcaneFieldWrapper<T>(
      builder: (context) => switch (mode ??
              (options.length > 3
                  ? ArcaneEnumFieldType.dropdown
                  : ArcaneEnumFieldType.cards)) {
            ArcaneEnumFieldType.dropdown => Card(
                padding: EdgeInsetsGeometry.zero,
                borderColor: Colors.transparent,
                borderWidth: 0,
                filled: true,
                fillColor:
                    Theme.of(context).colorScheme.card.withOpacity(0.5),
                child: Select<T>(
                  itemBuilder: (context, item) {
                    return Stack(
                      children: [
                        ...options
                            .where((e) => e.ename.length > item.ename.length)
                            .map((e) => Opacity(
                                opacity: 0,
                                child: itemBuilder?.call(context, e) ??
                                    Text(e.ename))),
                        itemBuilder?.call(context, item) ?? Text(item.ename)
                      ],
                    );
                  },
                  popupWidthConstraint: PopoverConstraint.anchorMaxSize,
                  onChanged: (value) => field.provider.setValue(
                      field.meta.effectiveKey,
                      value ?? field.provider.defaultValue),
                  value: field.provider.subject.valueOrNull ??
                      field.provider.defaultValue,
                  popup: SelectPopup(
                    items: SelectItemList(
                      children: [
                        ...options.map((i) => SelectItemButton(
                              value: i,
                              child: itemBuilder?.call(context, i) ??
                                  Text(i.ename),
                            )),
                      ],
                    ),
                  ).call,
                ),
              ),
            ArcaneEnumFieldType.cards => CardCarousel(
                featherColor: Theme.of(context).colorScheme.card,
                children: [
                  ...options
                      .map((e) =>
                          cardBuilder?.call(
                              context,
                              e,
                              field.provider.subject.valueOrNull ??
                                  field.provider.defaultValue) ??
                          Card(
                            filled: true,
                            fillColor: Theme.of(context)
                                .colorScheme
                                .card
                                .withOpacity(0.5),
                            borderWidth:
                                field.provider.subject.valueOrNull == e
                                    ? 2
                                    : null,
                            borderColor:
                                field.provider.subject.valueOrNull == e
                                    ? Theme.of(context)
                                        .colorScheme
                                        .primary
                                        .withOpacity(0.5)
                                    : null,
                            onPressed: () => field.provider
                                .setValue(field.meta.effectiveKey, e),
                            child: itemBuilder?.call(context, e) ??
                                Text(e.ename),
                          ))
                      .whereType<Widget>()
                      .joinSeparator(Gap(8))
                ],
              )
          });
}