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

Calendar disappears with setState #18

Open
PINHOf opened this issue Dec 7, 2020 · 4 comments
Open

Calendar disappears with setState #18

PINHOf opened this issue Dec 7, 2020 · 4 comments

Comments

@PINHOf
Copy link

PINHOf commented Dec 7, 2020

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
	});
},
@mduccc
Copy link
Owner

mduccc commented Jan 11, 2021

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 mduccc closed this as completed Jan 11, 2021
@roccoe
Copy link

roccoe commented Apr 23, 2021

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

@jagdishjadeja
Copy link

i have similar issue

@mduccc mduccc reopened this Sep 30, 2021
@lyngbach
Copy link

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.

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

5 participants