'How to refresh datepicker when button is clicked?

I'm new to flutter so apologies if this is a simple question. I am attempting to create a date picker where the user can utilise either the date picker or a button ("today", "tomorrow",ect) to select the date. Whilst my current implementation works, when the user utilises the buttons, the date picker does not update. Strangely, when the user uses the date picker, the appropriate button is updated (shown as selected).

Is there a method, widget or controller that could perhaps be used to resolve this issue? I think the issue resides from the date picker widget only being updated on execution. Any help is appreciated. I did note from the pub.dev page that a controller can be used, however in my testing I didn't find this to resolve the issue.

All necessary code snippets are below. The date picker I am using is: https://pub.dev/packages/date_picker_timeline

Thanks in advance for any help.

Code for date variable:

DateTime date = fetchDate().getToday();

Code for DatePicker:

DatePicker(
          fetchDate().getToday(),
          initialSelectedDate: date,
          controller: _datecontroller,
          selectionColor: Colors.blue,
          height: 80,
          selectedTextColor: Colors.white,
          onDateChange: (dateValue) {
            // New date selected
            setState(() {
              date = dateValue;
            });
          },
        ),

Code for button : Please note button is wrapped in InkWell() widget and when button is tapped, date variable changes to the date of the button.

return Row(
children: [
  Chip(
    labelStyle: date.day == chipValue.day
        ? TextStyle(color: Colors.white)
        : TextStyle(color: Colors.black),
    backgroundColor: selected ? Colors.blue : Colors.grey[300],
    label: Text("today"),
    padding: EdgeInsets.all(5),
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(8))),
  ),
],


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source