build method
Build the picker.
context
is passed BuildContext. currentDateTime
is passed the currently selected DateTime.
ピッカーのビルドを行ないます。
context
にBuildContextが渡されます。currentDateTime
に現在選択されているDateTimeが渡されます。
Implementation
Future<DateTime?> build(
BuildContext context,
DateTime? currentDateTime,
) async {
final theme = Theme.of(context);
DateTime? res;
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: [
(currentDateTime?.month ?? defaultDateTime?.month ?? 1) - 1,
(currentDateTime?.day ?? defaultDateTime?.day ?? 1) - 1,
],
adapter: _PickerDataAdapter<int>(
data: [
...List.generate(12, (m) {
final month = DateTime(1970, m + 2, 0);
return _PickerItem(
text: Text(
"${month.format(monthFormat)}$monthSuffix",
style: TextStyle(
color: color ?? theme.colorScheme.onSurface,
),
),
value: m + 1,
children: List.generate(
month.day,
(d) => _PickerItem(
text: Text(
"${(d + 1).format("00")}$daySuffix",
style: TextStyle(
color: color ?? theme.colorScheme.onSurface,
),
),
value: d + 1,
),
),
);
}),
],
),
changeToFirst: true,
hideHeader: false,
onConfirm: (_Picker picker, List<int> value) {
final now = DateTime.now();
res = DateTime(now.year, value[0] + 1, value[1] + 1);
},
).showModal(context);
return res;
}