mytooyo / board_datetime_picker

Picker to select date and time for Flutter. It is both a calendar and a picker, offering a variety of options as a package.
BSD 3-Clause "New" or "Revised" License
6 stars 6 forks source link

Supporting Duration as DateTimePickerType #15

Closed matteoberla closed 7 months ago

matteoberla commented 7 months ago

Just asking if the following it's possible and could be a valid idea:

At the moment I'm using the library also as duration picker, but I need to convert every time the DateTime to a Duration which is fine, but not ideal.

I was wondering if it's possible to add duration as pickerType, pickers showed would be same as pickerType.time one, but the returned value would be a Duration.

mytooyo commented 7 months ago

@matteoberla Would it be better to have a callback with another type instead of the DateTime type for the time selection? It is true that it does not seem necessary to have a DateTime type for time only. For example, how about defining another class to receive the hour and minute in a callback?

class BoardDateTimeDurationResult {
  final int hour;
  final int minute;
}
matteoberla commented 7 months ago

Yes it makes a lot of sense to have a separate callback when time/duration mode is used, that would be perfect!

mytooyo commented 7 months ago

@matteoberla Implemented onResult method.

onResult: (val) {
  print('${val.hour}, ${val.minute});
}

In addition to the traditional showBoardDateTimePicker method, a method for each type has been defined. By using this one, you do not have to define the type of the onResult parameter, but it will return the one that matches the type you want to display.

We will release v1.4.0 with this issue, so please be patient!

matteoberla commented 7 months ago

This is a perfect solution. I'll test it as soon as you will release the new version. Thank you very much, I really appreciate it.