werner-scholtz / kalender

An elegantly crafted Flutter calendar UI package.
MIT License
107 stars 29 forks source link

Some functions broken after navigating through 31 of March (Europe DST date) #32

Closed kluverua closed 7 months ago

kluverua commented 8 months ago

Notice very strange behavior

Reproducing: Open: https://werner-scholtz.github.io/kalender/ In "date picker" set the date to 30.03.2024 and click "Ok" grid navigated to the specified date but you can't create new Events on this date (by taping on the grid)

If you set another date e.g. 01.04.2024 or 28.03.2024 everything works fine and you can create new events.

What is wrong with these dates? :)

werner-scholtz commented 8 months ago

That is weird I can't seem to reproduce it. Is the view configuration setup like this ? image

kluverua commented 8 months ago

I don't change any settings. Enable Reschedule = true Enable Resize = true

https://github.com/werner-scholtz/kalender/assets/13339896/e0e579e3-27bc-474b-90cd-2fea4d046225

kluverua commented 8 months ago

It reproduced in my project on Android/iOS Here is some stack trace from my project, maybe it can help

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞════════════════════════════════════════════
The following assertion was thrown during performLayout():
BoxConstraints forces an infinite width.
These invalid constraints were provided to RenderStack's layout() function by the following
function, which probably computed the invalid constraints in question:
  RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:516:11)
The offending constraints were:
  BoxConstraints(w=Infinity, h=1008.0)

The relevant error-causing widget was:
  Stack
  Stack:file:///C:/Users/*/lib/src/views/multi_day_view/multi_day_page_content.dart:162:20

When the exception was thrown, this was the stack:
#0      BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError (package:flutter/src/rendering/box.dart:519:9)
#1      BoxConstraints.debugAssertIsValid.<anonymous closure> (package:flutter/src/rendering/box.dart:569:11)
#2      BoxConstraints.debugAssertIsValid (package:flutter/src/rendering/box.dart:577:6)
#3      RenderObject.layout (package:flutter/src/rendering/object.dart:2439:24)
#4      RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#5      RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:516:11)
#6      RenderStack.performLayout (package:flutter/src/rendering/stack.dart:621:30)
#7      RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#8      RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#9      _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:310:14)
#10     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#11     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#12     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#13     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#14     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#15     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#16     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#17     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#18     RenderSliverFixedExtentBoxAdaptor.performLayout (package:flutter/src/rendering/sliver_fixed_extent_list.dart:309:19)
#19     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#20     RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:139:12)
#21     _RenderSliverFractionalPadding.performLayout (package:flutter/src/widgets/sliver_fill.dart:160:11)
#22     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#23     RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:601:13)
#24     RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1554:12)
#25     RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1463:20)
#26     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#27     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#28     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#29     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#30     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#31     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#32     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#33     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#34     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#35     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#36     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#37     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#38     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#39     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#40     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#41     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#42     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#43     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#44     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#45     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#46     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#47     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#48     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#49     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#50     RenderCustomPaint.performLayout (package:flutter/src/rendering/custom_paint.dart:569:11)
#51     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#52     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#53     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:21)
#54     RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
#55     RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
#56     RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:516:11)
#57     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:621:30)
#58     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2385:7)
#59     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1025:18)
#60     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1038:15)
#61     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:591:23)
#62     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:986:13)
#63     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)
#64     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)
#65     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)
#66     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)
#70     _invoke (dart:ui/hooks.dart:314:10)
#71     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)
#72     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 3 frames from dart:async)
kluverua commented 8 months ago

I found problem

\lib\src\extensions.dart:10

start.startOfDay.difference(end.endOfDay).inDays //returns 1 instead of 2 In case when start = 2024-03-30 00:00:00.000 end = 2024-03-31 00:00:00.000

because of Daylight saving time (DST) because start.startOfDay.difference(end.endOfDay).inHours = 47 hours instead of 48 hours

here is possible workaround:

final startDay = DateTime.utc(start.year, start.month, start.day);
final endDay = DateTime.utc(end.year, end.month, end.day);
return (endDay - startDay).inDays;

P.S. I think this is not the only place where this error occurs and need to check all other places

werner-scholtz commented 8 months ago

Hi thanks for bringing this to my attention I don't experience daylight savings myself and for debugging will take a closer look at this.

kluverua commented 8 months ago

Here is another example, select the Custom period (in fact it is 2 days) and select the date March 29-30 we see that only one column is drawn image

werner-scholtz commented 8 months ago

Thanks I was able to replicate the issues by changing my timezone, I cannot fix it right now but should be able to fix it this weekend or next.

werner-scholtz commented 8 months ago

Hi should be fixed now.

kluverua commented 8 months ago

Thank you! Much better now! but some little problems persist... Case Open: https://werner-scholtz.github.io/kalender/ In "date picker" set the date to 01.04.2024 and click "Ok" expected to see 01/04/2024 date but for now I see 31/03/2024

werner-scholtz commented 7 months ago

Time to write some more tests :test_tube: