flutter_calendar_week icon indicating copy to clipboard operation
flutter_calendar_week copied to clipboard

Calendar disappears with setState

Open PINHOf opened this issue 4 years ago • 4 comments

I'm using the onWeekChanged event to add some logic & update some variables and if I use the setState function within this event, the calendar disappears. Firstly I thought it was due to my code, but it doesn't seem.

onWeekChanged: () {
	setState(() {
	  // Even with this empty, the calendar will disappear
	});
},

PINHOf avatar Dec 07 '20 18:12 PINHOf

I'm using the onWeekChanged event to add some logic & update some variables and if I use the setState function within this event, the calendar disappears. Firstly I thought it was due to my code, but it doesn't seem.

onWeekChanged: () {
	setState(() {
	  // Even with this empty, the calendar will disappear
	});
},

Hi! I tried your code in the example project. All is good. Please check your code again.

mduccc avatar Jan 11 '21 15:01 mduccc

I do have the same issue. On setState or when I perform a hot reload, the CalendarWeek widget disappears completely. Only if I navigate to a different screen and return back, the widget shows up again.

I put the CalenderWeek widget inside a SliverAppBar in a CustomScrollView. Here is a code example:

Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: CustomScrollView(
          slivers: [
            SliverAppBar(
              automaticallyImplyLeading: false,
              pinned: true,
              backgroundColor: Theme.of(context).colorScheme.primary,
              expandedHeight: 110,
              collapsedHeight: 110,
              elevation: 0,
              flexibleSpace: CalendarWeek(
                controller: CalendarWeekController(),
                minDate: firstDate.subtract(Duration(days: firstDate.weekday - 1)),
                maxDate: lastDate
                    .add(Duration(days: DateTime.daysPerWeek - lastDate.weekday)),
                onDatePressed: (DateTime selectedDate) {
                  BlocProvider.of<MeetingsBloc>(context)
                      .add(MeetingDaySelected(selectedDate));
                  setState(() {
                    _selectedDate = selectedDate;
                  },
              ),
            ),
          ],
        ),
      ),
    );
  }

Would be appreciated, if someone can check if they can reproduce the issue. I couldn't find anything in my code, what could be the culprit of this error. I also do not get any errors on the console.

Flutter Version: 2.0.5 Device: Nokia 6.1 with Android 10

roccoe avatar Apr 23 '21 15:04 roccoe

i have similar issue

jagdishjadeja avatar Sep 14 '21 13:09 jagdishjadeja

I was having the same issue and when I tried running the example app it was fine.

I eventually boiled it down to an controller issue in my code. When I removed the controller property it was working as expected.

I initial copied over from the example where

CalendarWeek(
    controller: CalendarWeekController(),
    ...
)

is set which does not give an immediate error but once I either removed the controller property or intialized the controller like in the example app it was working just fine.

final CalendarWeekController _controller = CalendarWeekController();

...

CalendarWeek(
    controller: _controller,
    ...
)

Hope this helps out others who might stumble upon this problem in the future.

Great plugin btw! Wish to see more styling options of the entire date column like rearrange of day title and the date, other day shapes etc.

lyngbach avatar Nov 21 '21 21:11 lyngbach