rwbr / flutter_neat_and_clean_calendar

Simple and clean flutter calendar with ability to slide up/down to show weekly/monthly calendar. Forked from [flutter_clean_calender](https://pub.dev/packages/flutter_clean_calendar)
MIT License
106 stars 55 forks source link

Events not being displayed when not expanded #36

Closed badrinadh closed 2 years ago

badrinadh commented 2 years ago

Events were not being displayed within the calendar with the dots when it's minimized, only when expanded the whole functionality is working. even when I select a date its not show evens when minimized.

IMG_1740 IMG_1741

rwbr commented 2 years ago

I can't reproduce that behavior. Are you able to demonstrate that with the example code? Are there any prerequisites to that? Did you change anything?

badrinadh commented 2 years ago

Even when I run the project from the GIT directory I still face the same issue.

badrinadh commented 2 years ago

Simulator Screen Shot - iPhone 13 - 2022-03-30 at 16 35 16 Simulator Screen Shot - iPhone 13 - 2022-03-30 at 16 35 27 Simulator Screen Shot - iPhone 13 - 2022-03-30 at 16 35 32

badrinadh commented 2 years ago

It's the example script that I compiled on the emulator.

rwbr commented 2 years ago

When you run the example it logs some messages in the terminal. Are there log messages like that in the terminal:

flutter: Date selected: 2022-03-30 00:00:00.000
flutter: === Summary: Allday Event B
flutter: AllDayEvent - Allday Event B
flutter: === Summary: MultiDay Event A
flutter: MultiDayEvent: start - MultiDay Event A
flutter: SingleDayEvent
rwbr commented 2 years ago

Do you run the example completely unmodified, like a fresh clone? Or with your own additions? Did you use the eventListBuilder property of the class? Or the daybuilder property?

badrinadh commented 2 years ago

it's completely a clone of the example no changes were done, ran it directly on the example.

rwbr commented 2 years ago

OK, I see. But I don't have an idea, how I can help without further informations. The screenshots you posted here were definitely not taken from the example application. However, could you provide more informations on you environment? What does flutter doctor print out? Are there any log messages about exceptions when running your project? Do you run your project in the debugger or from the terminal?

aniket-github commented 2 years ago

I am facing 2 issues,

  1. If collapse events are not visible, only visible if it is expanded
  2. onMonthChanged: (dateTime) => updateEvent(dateTime) is not reflected on calendar

updateEvent(dateTime){ _events = fetched events from selected month using API }

@rwbr

aniket-github commented 2 years ago

I am facing 2 issues,

  1. If collapse events are not visible, only visible if it is expanded
  2. onMonthChanged: (dateTime) => updateEvent(dateTime) is not reflected on calendar

updateEvent(dateTime){ _events = fetched events from selected month using API }

@rwbr

  1. check gif -> https://medium.com/@pmcarlosdev/flutter-calendar-with-flutter-clean-calendar-9b3ddb9f61b1

  2. @override
    Widget build(BuildContext context) {
    print('build, _eventList:${_eventList.length}');
    return Scaffold(
      body: SafeArea(
        child: Calendar(
          startOnMonday: true,
          weekDays: ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'],
          eventsList: _eventList,
          isExpandable: true,
          eventDoneColor: Colors.green,
          selectedColor: Colors.pink,
          selectedTodayColor: Colors.green,
          todayColor: Colors.blue,
          eventColor: null,
          locale: 'de_DE',
          todayButtonText: 'Heute',
          allDayEventText: 'Ganztägig',
          multiDayEndText: 'Ende',
          isExpanded: true,
          expandableDateFormat: 'EEEE, dd. MMMM yyyy',
          datePickerType: DatePickerType.date,
          onMonthChanged: (dateTime) => getShipments(dateTime),
          dayOfWeekStyle: TextStyle(
              color: Colors.black, fontWeight: FontWeight.w800, fontSize: 11),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        child: const Icon(Icons.add),
        backgroundColor: Colors.green,
      ),
    );
    }

updateEvent(dateTime){
// NOTE: add event from last month or next month
    setState(() {
      _eventList = [
        NeatCleanCalendarEvent('MultiDay Event Acccccc',
            startTime: DateTime(DateTime.now().year, DateTime.now().month,
                DateTime.now().day, 15, 0),
            endTime: DateTime(DateTime.now().year, DateTime.now().month,
                DateTime.now().day + 2, 18, 0),
            color: Colors.yellow,
            isMultiDay: true),
        NeatCleanCalendarEvent('Allday Event Bcccccc',
            startTime: DateTime(DateTime.now().year, DateTime.now().month,
                DateTime.now().day - 12, 14, 30),
            endTime: DateTime(DateTime.now().year, DateTime.now().month,
                DateTime.now().day  - 12, 17, 0),
            color: Colors.yellow,
            isAllDay: true),
      ];
      print('update _eventList:${_eventList.length}');
    });
}
rwbr commented 2 years ago

Fixed with commit c5c7e3cfeae35c06f4af848f62022b9c4c8c9d01

ghost commented 1 year ago

I facing same issue is there anyone solved this?

rwbr commented 1 year ago

I facing same issue is there anyone solved this?

On which version are you? This was fixed in #37. The fix was included from version v0.3.6+19. Please check, if you are using the latest version of the package.

ghost commented 1 year ago

I facing same issue is there anyone solved this?

On which version are you? This was fixed in #37. The fix was included from version v0.3.6+19. Please check, if you are using the latest version of the package.

Okay will check updated document and update here. Thanks @rwbr

ghost commented 1 year ago

@rwbr Still not working. I used latest version.

FYI I download project from github and run without any changes.

Please see below Screenshot. image

rwbr commented 1 year ago

In this case you could help me with debugging the package. The widgets for colored dots for the events are added in calendar_tile.dart in the code from line 131 on. Could you please run the example and set a breakpoint on line 131.

It's this line:

                events != null && events!.length > 0

Then please check the value of events. In your case events could be null or have the length of 0.

If that is the case we can move on to find out, why it has that value.

ghost commented 1 year ago

I found the issue. When isExpanded == false then day value is = 2022-12-18 00:30:00.000 and isExpanded == true then day value is 2022-12-18 00:00:00.000.

day not match with event day because of minute value is different. @rwbr

rwbr commented 1 year ago

Thank you for analyzing the problem. That's strange. But at least it gives an explanation.

rwbr commented 1 year ago

Unfortunately I don't see, where that comes from. I'm not even able to reproduce the same behavior. In my environment all works as expected. @MohammadAliK On which position in the code did you watch the value of the day?

ghost commented 1 year ago

@rwbr have you check this part of code in flutter_neat_and_clean_calendar.dart file? I add comment where time was different 30 minutes. please set breakpoint at eventsMap[day].

calendarDays.forEach(
      (day) {
        if (day.hour > 0) {
          day = day.toLocal();
          day = day.subtract(new Duration(hours: day.hour));
        }

        if (monthStarted && day.day == 01) {
          monthEnded = true;
        }

        if (Utils.isFirstDayOfMonth(day)) {
          monthStarted = true;
        }

        if (this.widget.dayBuilder != null) {
          // Use the dayBuilder widget passed as parameter to render the date tile
          dayWidgets.add(
            NeatCleanCalendarTile(
              defaultDayColor: widget.defaultDayColor,
              defaultOutOfMonthDayColor: widget.defaultOutOfMonthDayColor,
              selectedColor: widget.selectedColor,
              selectedTodayColor: widget.selectedTodayColor,
              todayColor: widget.todayColor,
              eventColor: widget.eventColor,
              eventDoneColor: widget.eventDoneColor,
              events: eventsMap[day],
              child: widget.dayBuilder(context, day),
              date: day,
              onDateSelected: () => handleSelectedDateAndUserCallback(day),
            ),
          );
        } else {
          dayWidgets.add(
            NeatCleanCalendarTile(
                defaultDayColor: widget.defaultDayColor,
                defaultOutOfMonthDayColor: widget.defaultOutOfMonthDayColor,
                selectedColor: widget.selectedColor,
                selectedTodayColor: widget.selectedTodayColor,
                todayColor: widget.todayColor,
                eventColor: widget.eventColor,
                eventDoneColor: widget.eventDoneColor,
                events: eventsMap[day], //isExpanded == false day = 2022-12-18 00:30:00.000 and isExpanded == true day = 2022-12-18 00:00:00.000
                onDateSelected: () => handleSelectedDateAndUserCallback(day),
                date: day,
                dateStyles: configureDateStyle(monthStarted, monthEnded),
                isSelected: Utils.isSameDay(selectedDate, day),
                inMonth: day.month == selectedDate.month),
          );
        }
      },
    );
rwbr commented 1 year ago

The only lines that manipulate the day variable are:

        if (day.hour > 0) {
          day = day.toLocal();
          day = day.subtract(new Duration(hours: day.hour));
        }

But I don't see how isExpanded could influence these calculation. @MohammadAliK Cloud you please check, if there is some strange timezone effect causing the problem at your spot? BTW, my I ask in which timezone you are right now? I test the application while being in Europe, so my timezone is CET.

A few lines above that code snippet there is a line that collects the list of calendarDays.

List<DateTime> calendarDays = isExpanded ? selectedMonthsDays : selectedWeekDays as List<DateTime>;

Here isExpanded has an influence. @MohammadAliK Maybe you could also check, if calendarDays has a proper value?

In my case selectedMonthsDays has the value of:

List (35 items)
[0]:
DateTime (2022-11-28 00:00:00.000)
[1]:
DateTime (2022-11-29 00:00:00.000)
[2]:
DateTime (2022-11-30 00:00:00.000)
[3]:
DateTime (2022-12-01 00:00:00.000)
[4]:
DateTime (2022-12-02 00:00:00.000)
[5]:
DateTime (2022-12-03 00:00:00.000)
[6]:
DateTime (2022-12-04 00:00:00.000)
[7]:
DateTime (2022-12-05 00:00:00.000)
[8]:
DateTime (2022-12-06 00:00:00.000)
[9]:
DateTime (2022-12-07 00:00:00.000)
[10]:
DateTime (2022-12-08 00:00:00.000)
[11]:
DateTime (2022-12-09 00:00:00.000)
[12]:
DateTime (2022-12-10 00:00:00.000)
[13]:
DateTime (2022-12-11 00:00:00.000)
[14]:
DateTime (2022-12-12 00:00:00.000)
[15]:
DateTime (2022-12-13 00:00:00.000)
[16]:
DateTime (2022-12-14 00:00:00.000)
[17]:
DateTime (2022-12-15 00:00:00.000)
[18]:
DateTime (2022-12-16 00:00:00.000)
[19]:
DateTime (2022-12-17 00:00:00.000)
[20]:
DateTime (2022-12-18 00:00:00.000)
[21]:
DateTime (2022-12-19 00:00:00.000)
[22]:
DateTime (2022-12-20 00:00:00.000)
[23]:
DateTime (2022-12-21 00:00:00.000)
[24]:
DateTime (2022-12-22 00:00:00.000)
[25]:
DateTime (2022-12-23 00:00:00.000)
[26]:
DateTime (2022-12-24 00:00:00.000)

while selectedWeekDays has the value of:

List (7 items)
[0]:
DateTime (2022-12-26 12:00:00.000Z)
[1]:
DateTime (2022-12-27 12:00:00.000Z)
[2]:
DateTime (2022-12-28 12:00:00.000Z)
[3]:
DateTime (2022-12-29 12:00:00.000Z)
[4]:
DateTime (2022-12-30 12:00:00.000Z)
[5]:
DateTime (2022-12-31 12:00:00.000Z)
[6]:
DateTime (2023-01-01 12:00:00.000Z)
ghost commented 1 year ago

Finally I resolve the issue.

I just change below code and it's working perfect: day = day.toLocal(); TO day = DateFormat("yyyy-MM-dd HH:mm:ssZZZ").parse(day.toString()).toLocal();

selectedWeekDays returns UTC Time but selectedMonthsDays is not a UTC time so simply I convert UTC time to local time.

Checkout the screenshot: image image

@rwbr Thank you so much for quick response and for this wonderful plugin.

rwbr commented 1 year ago

Great! @MohammadAliK Thank you for your help. I appreciate your support very well. I'll include your contributed code in the coming patch, so that this issue is fixed for everybody. Sorry for the delay in the beginning, but it was hard to understand the problem without being able to see this bug in my simulation.