ScrollWheelTimeSelector constructor Null safety

ScrollWheelTimeSelector(
  1. {Key? key,
  2. required ValueSetter<TimeOfDay> onTimeChanged,
  3. List<String>? hours,
  4. List<String>? minutes,
  5. TimeOfDay? time,
  6. bool infiniteScroll = true,
  7. double height = 60,
  8. Duration? notificationDelay,
  9. required ScrollWheelTimeSelectorController controller,
  10. Color? color}
)

Implementation

ScrollWheelTimeSelector({
  Key? key,
  required this.onTimeChanged,
  List<String>? hours,
  List<String>? minutes,
  TimeOfDay? time,
  bool infiniteScroll = true,
  double height = 60,
  Duration? notificationDelay,
  required this.controller,
  this.color,
  // bool withNull = false,
}) : super(key: key) {
  // hours
  _hours = hours == null ? List.generate(24, (index) => index.toString()) : hours;
  if (time == null) {
    _hours.insert(0, '--');
  }

  // minutes
  _minutes = minutes == null ? List.from(['00', '15', '30', '45']) : minutes;

  if (time == null) {
    _minutes.insert(0, '--');
  }

  final initialHour = time == null ? 0 : _hours.indexOf(time.hour.toString());
  final initialMinute = time == null ? 0 : _minutes.indexOf(time.minute.toString().padLeft(2, '0'));

  _hourController = FixedExtentScrollController(initialItem: initialHour);
  _minuteController = FixedExtentScrollController(initialItem: initialMinute);
  _infiniteScroll = infiniteScroll;
  _height = height;
  // this.notificationDelay = notificationDelay ?? Duration(seconds: 2);
}