iamvivekkaushik / DatePickerTimelineFlutter

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

JumpToSelection #28

Closed kristimeculi closed 3 years ago

kristimeculi commented 4 years ago

Is your feature request related to a problem? Please describe. The problem is in the beginning because users must go in the selected date when the DatePicker has appeared and for the moment we only can go in the selected date after we use _controller.jumpToSelection(); in DatePicker View.

Describe the solution you'd like Maybe we can call _controller.jumpToSelection() in initState

Ludwigvsch commented 4 years ago

Hi, I have the same problem but would love to use this package. How can I implement this?

iamvivekkaushik commented 4 years ago

Hi, I haven't yet looked at the issue. I Will update once I do. Currently, you can't use the controller inside initState()

SpajicM commented 4 years ago

I had the same issue, fixed by using WidgetsBinding.addPostFrameCallback(() {})

Ludwigvsch commented 4 years ago

I had the same issue, fixed by using WidgetsBinding.addPostFrameCallback(() {})

Can you give me an example of where to use this?

Ludwigvsch commented 4 years ago

@SpajicM where do I need to use this is in my code?

amith-patil commented 4 years ago

I noticed a weird issue where the jumpToSelection() function jumps to the date + 1 field on first run. for example, if the date is 11th, I call the jumpToSelection() via the controller using a button, the timeline will jump to the 12th. any idea why?

code is below :


                          _startDate,
                          controller: _dpc,
                          initialSelectedDate: _selectedDate,
                          width: Size_Config.blockSizeHorizontal * 15,
                          height: Size_Config.blockSizeVertical * 12,
                          monthTextStyle: TextStyle(fontFamily: 'Montserrat',color: Colors.white54,fontSize: Size_Config.blockSizeHorizontal * 3),
                          dateTextStyle: TextStyle(fontFamily: 'MontSerrat',fontSize: Size_Config.blockSizeHorizontal * 5,fontWeight: FontWeight.bold,color: Colors.white54),
                          dayTextStyle: TextStyle(fontFamily: 'Montserrat',color: Colors.white54,fontSize: Size_Config.blockSizeHorizontal * 3),
                          onDateChange:(date) { _pc.open(); setState(() {
                            _selectedDate = date;
                          });},
                        ),

.......

child: IconButton(
                                 onPressed: () { _pc.close();_dpc.animateToSelection();},
                                  icon: Icon(CustomIcons.filter),
                                  color: Colors.white54,
                                  //iconSize: 40,
                                ),
SpajicM commented 4 years ago

@amith-patil Timezones.

amith-patil commented 4 years ago

@amith-patil Timezones.

I'm not sure how that comes into the picture. Could you elaborate? edit: this happens only on the first time I run jumpToSelection(). after I update the date via onDateChanged() , jumpToSelection shows the right date. I can upload an example if you'd like

SpajicM commented 4 years ago

@amith-patil alright, attach an example, I will look into it, but those off by one errors for me were often caused by time offset.

If I had to guess, you set start day as May 1, initial date as DateTime.now(), Let's say May 11 03:00.

Jump to selection takes the number of days from start day (1 day = 24h). Between May 1 and 11 are 10 days. And those 3 hours after midnight makes it 11. So it makes it jump +1 of what you would expect.

amith-patil commented 4 years ago

I'm inclined to believe it's got something to do with the timestamp, because at midnight right now, it's jumping to the correct date.

amith-patil commented 4 years ago

also found this weird issue with the startDate

SpajicM commented 4 years ago

To fix it, any set time to 00:00 on any DateTime instance you are using.

amith-patil commented 4 years ago

To fix it, any set time to 00:00 on any DateTime instance you are using.

gotcha. I figured that's where the issue was.

iamvivekkaushik commented 4 years ago

Thanks for bringing this to my attention, I'll take a look at it and update you guys here.

amith-patil commented 4 years ago

Thanks for bringing this to my attention, I'll take a look at it and update you guys here.

Hey Vivek, I'm seeing the jump to be very unpredictable with the offset, I've tried to set the time to 00:00:00, but the start date still moves right to the next date. Do you want me to open this as a separate issue for you? ezgif-3-3c6cb3f8f3af

iamvivekkaushik commented 4 years ago

Thanks for bringing this to my attention, I'll take a look at it and update you guys here.

Hey Vivek, I'm seeing the jump to be very unpredictable with the offset, I've tried to set the time to 00:00:00, but the start date still moves right to the next date. Do you want me to open this as a separate issue for you? ezgif-3-3c6cb3f8f3af

Yes please, create a new issue.

Ludwigvsch commented 4 years ago

How do I use the controller to see the right date when the screen loads, what argument needs it in init State, and how to use it, please help...

Ludwigvsch commented 4 years ago

Thats the error message when using jumpToSelection

The method 'jumpToSelection' was called on null. Receiver: null Tried calling: jumpToSelection()

When the exception was thrown, this was the stack

0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)

1 _Main_pageState.build.

package:day_planner/screeens/mainpage.dart:218

2 _InkResponseState._handleTap

package:flutter/…/material/ink_well.dart:989

3 _InkResponseState.build.

package:flutter/…/material/ink_well.dart:1095

4 GestureRecognizer.invokeCallback

package:flutter/…/gestures/recognizer.dart:182 ... Handler: "onTap" Recognizer: TapGestureRecognizer#ea023 debugOwner: GestureDetector state: possible

rednikisfun commented 3 years ago

I have an issue which I think would be suitable here. I am trying to call _datePickerController.animateToDate(DateTime.now()); or _datePickerController.jumpToSelection(); in initState of the page, but get

DatePickerController is not attached to any DatePicker View. 'package:date_picker_timeline/date_picker_widget.dart': Failed assertion: line 201 pos 12: '_datePickerState != null'

I only show dates from 6 days before till today and need a way to show today which is in the end of the Date Picker.

iamvivekkaushik commented 3 years ago

@rednikisfun you can use this

@override
void initState() {
    WidgetsBinding.addPostFrameCallback(() {
        // Do Something here
        _datePickerController.animateToDate(DateTime.now());
    })
}
iamvivekkaushik commented 3 years ago

This issue is now fixed in the latest version.

chrisvidal commented 2 years ago

the exact code that should work is

 WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
   // Do Something here
        _datePickerController.jumpToSelection();
    });
Meet-05 commented 2 years ago

the exact code that should work is

 WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
   // Do Something here
        _datePickerController.jumpToSelection();
    });

Thanks! this worked.

gamcho3 commented 2 years ago

the exact code that should work is

 WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
   // Do Something here
        _datePickerController.jumpToSelection();
    });

Do you know how to focus center?