build method

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

Build the picker.

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

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

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

Implementation

Future<num?> build(BuildContext context, num? currentValue) async {
  final length = ((end - begin) / interval.toDouble()).round();
  final selected =
      (((currentValue ?? defaultValue ?? 0) - begin) / interval.toDouble())
          .round();
  num? 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: [
      selected,
    ],
    adapter: _PickerDataAdapter<num>(
      data: [
        ...List.generate(length + 1, (m) {
          final val = begin + (m * interval);
          return _PickerItem<num>(
            text: Text(
              "${val.toStringAsFixed(fractionDigits)}$suffix",
              style: TextStyle(
                color: color ?? theme.colorScheme.onSurface,
              ),
            ),
            value: val,
          );
        }),
      ],
    ),
    changeToFirst: true,
    hideHeader: false,
    onConfirm: (_Picker picker, List<int> value) {
      res = begin + (value[0] * interval);
    },
  ).showModal(context);
  return res;
}