timeRangeScrollPicker method

Widget timeRangeScrollPicker(
  1. BuildContext context,
  2. List<TimeOfDay> times, {
  3. Duration timeRange = const Duration(minutes: 60),
  4. required dynamic onTimeSelected(
    1. TimeOfDay timeSelected
    ),
  5. double pickerHeight = 180,
})

Implementation

Widget timeRangeScrollPicker(BuildContext context, List<TimeOfDay> times,
    {Duration timeRange = const Duration(minutes: 60),
    required Function(TimeOfDay timeSelected) onTimeSelected,
    double pickerHeight = 180}) {
  return SizedBox(
      height: pickerHeight,
      child: Row(children: [
        Expanded(
            child: CupertinoPicker(
          onSelectedItemChanged: (int value) {
            onTimeSelected(times[value]);
          },
          itemExtent: 48,
          children: List.generate(times.length, (index) {
            var secondRange = times[index].plusMinutes(timeRange.inMinutes);
            return SizedBox(
              height: 48,
              child: Center(
                child: DUI.text.title3(context,
                    '${times[index].format(context)} - ${secondRange.format(context)} h'),
              ),
            );
          }),
        ))
      ]));
}