Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using notifyListeners() inside onDateChange not working #17

Closed
psygo opened this issue Nov 1, 2019 · 3 comments
Closed

Using notifyListeners() inside onDateChange not working #17

psygo opened this issue Nov 1, 2019 · 3 comments

Comments

@psygo
Copy link
Contributor

psygo commented Nov 1, 2019

Describe the bug

Whenever the user changes the calendar date, something should happen in my program. At least a class I created to store my screen's data should change. In order to do so, I'm calling a method that changes the internal data and then calling notifyListeners() to update other fields. However, if I use notifyListeners(), the selected date on the calendar doesn't change; the data does change, but not the selected rectangle on the screen.

To Reproduce

The code in my app is quite long, but I believe the following should suffice...

The DatePickerTimeline call:

DatePickerTimeline(
  DateTime.now(),
  onDateChange: (newDate){
    data.changeDay(date: newDate);
  }

The method to update the data is something like:

void changeDay({DateTime date}){
  this.day = date;
  notifyListeners();
}

Expected behavior

Why is the selected rectangle not being selected? I've also tried to refactor the code to use the Provider package instead of setState() but it didn't work either.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Firefox

Smartphone (please complete the following information):

  • Device: Nexus 6
  • OS: Android 9.0
@psygo
Copy link
Contributor Author

psygo commented Nov 1, 2019

I'm leaning more and more on blaming the interaction of setState and notifyListeners. After wrapping the Container from the DatePickerTimeline widget source code and replacing widget.currentDate by a Consumer<> with data.currentDate (and adding notifyListeners), everything seems to work fine.

@iamvivekkaushik
Copy link
Owner

I am not sure why this is happening. onDateChange is called after data has been changed which should change the background to respective date.

@iamvivekkaushik
Copy link
Owner

This seems to be working fine make sure you are implementing it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants