iamvivekkaushik/DatePickerTimelineFlutter

JumpToSelection

Closed this issue ยท 24 comments

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

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

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

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

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

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

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

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,
                                ),

@amith-patil Timezones.

@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

@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.

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.

also found this weird issue with the startDate

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

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.

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

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

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.

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...

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

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.

@rednikisfun you can use this

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

This issue is now fixed in the latest version.

the exact code that should work is

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

the exact code that should work is

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

Thanks! this worked.

the exact code that should work is

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

Do you know how to focus center?