iamvivekkaushik / DatePickerTimelineFlutter

Flutter Date Picker Library that provides a calendar as a horizontal timeline
Apache License 2.0
283 stars 198 forks source link

Select dates from the past #10

Closed mrwwalmsley closed 4 years ago

mrwwalmsley commented 4 years ago

Is your feature request related to a problem? Please describe. I am wanting to use this fantastic widget to select dates from the past. At present it seems to only work for future dates.

Describe the solution you'd like Perhaps you could add a stateDate parameter that is set to today by default.

Describe alternatives you've considered Fork the code and add the feature.

Additional context

iamvivekkaushik commented 4 years ago

Hi @mrwwalmsley, if you want the date to start at some previous time, then you can just pass that date to the constructor.

DatePickerTimeline(
  DateTime.now(),
  onDateChange: (date) {
    // New date selected
    print(date.day.toString());
  },
),

Instead of date.now() you can pass any date and the calendar will start from that particular date.

iamvivekkaushik commented 4 years ago

Hi @mrwwalmsley, can you confirm if this resolves your issue?

iamvivekkaushik commented 4 years ago

I am closing this issue.

mrwwalmsley commented 4 years ago

Sorry for the late reply, I'm just getting on to implementing this functionality, and it doesn't seem to be working as I would like.

I want to set the current date to today... but allow the user to scroll back to select a day in the past.

The calendar timeline always starts on the current date.

See line 58 in date_picker_timeline.dart DateTime _date = DateTime.now().add(Duration(days: index));

hinterlandcreative commented 4 years ago

Any update on this? Can this PR #12 get merged in please?

iamvivekkaushik commented 4 years ago

I had no time to implement this, #12 have it implemented, you can use that version until it gets merged.

dependencies:
  date_picker_timeline:
    git:
      url: https://github.com/psygo/DatePickerTimelineFlutter.git
HannHank commented 4 years ago

I tried to pass the date like this DateTime.now().add(Duration(days: -10) to get the last week, but still see future dates.

Mallington commented 4 years ago

@HannHank Did you find a fix for this?

HannHank commented 4 years ago

@Mallington nope, still facing that problem.

Mallington commented 4 years ago

@HannHank I have posted a fix here: https://github.com/Mallington/DatePickerTimelineFlutter. You can modify your pubspec.yaml to use:

date_picker_timeline:
      git:
        url: https://github.com/Mallington/DatePickerTimelineFlutter

I'd recommend forking the repository for long term use, just in case I delete it 😄

HannHank commented 4 years ago

@Mallington thanks 👍

Mallington commented 4 years ago

@HannHank There was an issue with my original commit. I have moved to setting the startDate in the constructor See Example:

DatePickerTimeline(
   DateTime.now().add(Duration(days: -10)),
         onDateChange: (date) {
           // New date selected
           print(date.day.toString());
         },
         startDate: DateTime.now().add(Duration(days: -10)),
         daysCount: 10,
       )
iamvivekkaushik commented 4 years ago

Hi everyone, this option is now added to the library, just specify the startDate and the calendar will start from that particular date. I have also added a controller to move to any specific date.