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;
  num? res;
  await Picker(
    height: 240,
    backgroundColor: backgroundColor ?? Theme.of(context).colorScheme.surface,
    containerColor: backgroundColor ?? Theme.of(context).colorScheme.surface,
    headerColor: backgroundColor ?? Theme.of(context).colorScheme.surface,
    textStyle:
        TextStyle(color: color ?? Theme.of(context).colorScheme.onSurface),
    confirmText: confirmText,
    cancelText: cancelText,
    selecteds: [
      ((currentValue ?? defaultValue ?? 0) - begin) ~/ interval,
    ],
    adapter: PickerDataAdapter<num>(
      data: [
        ...List.generate(length, (m) {
          final val = (begin + m) * interval;
          return PickerItem<num>(
            text: Text(
              "$val$suffix",
              style: TextStyle(
                color: color ?? Theme.of(context).colorScheme.onSurface,
              ),
            ),
            value: val,
          );
        }),
      ],
    ),
    changeToFirst: true,
    hideHeader: false,
    onConfirm: (Picker picker, List<int> value) {
      res = (begin + value[0]) * interval;
    },
  ).showModal(context);
  return res;
}