build method

Future<TEnum?> build(
  1. BuildContext context,
  2. TEnum? currentValue
)

Build the picker.

context is passed BuildContext. currentValue is passed the currently selected TEnum.

ピッカーのビルドを行ないます。

contextBuildContextが渡されます。currentValueに現在選択されているTEnumが渡されます。

Implementation

Future<TEnum?> build(BuildContext context, TEnum? currentValue) async {
  TEnum? res;
  final theme = Theme.of(context);
  await _Picker(
    height: 240,
    backgroundColor: backgroundColor ?? theme.colorScheme.surface,
    containerColor: backgroundColor ?? theme.colorScheme.surface,
    headerColor: backgroundColor ?? theme.colorScheme.surface,
    textStyle: TextStyle(color: color ?? theme.colorScheme.onSurface),
    confirmText: confirmText,
    cancelText: cancelText,
    selecteds: [
      currentValue?.index ?? defaultValue?.index ?? 0,
    ],
    adapter: _PickerDataAdapter<TEnum>(
      data: [
        ...values.map((key) {
          return _PickerItem<TEnum>(
            text: Text(
              labelBuilder?.call(key) ?? key.name,
              style: TextStyle(
                color: color ?? theme.colorScheme.onSurface,
              ),
            ),
            value: key,
          );
        })
      ],
    ),
    changeToFirst: true,
    hideHeader: false,
    onConfirm: (_Picker picker, List<int> value) {
      res = values[value[0]];
    },
  ).showModal(context);
  return res;
}