RangeError index Invalid value

HI, I am facing an issue when updating the ressource list. I some ressources that are related to specifc categories, and I want to display ressources based on their selected categories. When a selected category is selected this happens, the error gets caught only when moving from a category of let's say 4 to a category with less than 4 resources. It works fine when moving from a  category of let's say 4 to a category with more than 4 resources


 void displayCalendarByCategory() {
    List<CalendarResource> selectedRessources = [];
    List<CustomAppointment> appointments = [];
    // Iterate through each resource
    if (selectedCategoryIndex == 0) {
      setState(() {
        _events = DataSource(_appointmentsCollection, _employeeCollection);
      });
    } else {
      for (CalendarResource resource in _employeeCollection) {
        if (categories
            .elementAt(selectedCategoryIndex)
            .categoryToStaff
            .staffList
            .contains(resource.id.toString().toLowerCase())) {
          selectedRessources.add(resource);
          appointments.addAll(_appointmentsCollection
              .where((appointment) {
                return appointment.resourceIds!
                    .contains(resource.id.toString().toLowerCase());
              })
              .cast<CustomAppointment>()
              .toList());
        }
      }
      setState(() {
        _events = DataSource(appointments, selectedRessources);
      });
    }
  }

I get this error: 


#45 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:2657:14)
object.dart:2657
#46 RenderConstrainedLayoutBuilder.rebuildIfNecessary (package:flutter/src/widgets/layout_builder.dart:225:7)
layout_builder.dart:225
#47 _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:308:5)
layout_builder.dart:308
#48 RenderObject.layout (package:flutter/src/rendering/object.dart:2546:7)
object.dart:2546
#49 RenderBox.layout (package:flutter/src/rendering/box.dart:2389:11)
box.dart:2389
#50 ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:52:11)
layout_helper.dart:52
#51 RenderFlex._computeSizes (package:flutter/src/rendering/flex.dart:868:45)
flex.dart:868
#52 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:903:32)
flex.dart:903
#53 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2385:7)
object.dart:2385
#54 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1025:18)
object.dart:1025
#55 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1038:15)
object.dart:1038
#56 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:591:23)
binding.dart:591
#57 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:986:13)
binding.dart:986
#58 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)
binding.dart:457
#59 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)
binding.dart:1325
#60 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)
binding.dart:1255
#61 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)
binding.dart:1113
#62 _invoke (dart:ui/hooks.dart:312:13)
hooks.dart:312
#63 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)
platform_dispatcher.dart:383
#64 _drawFrame (dart:ui/hooks.dart:283:31)
hooks.dart:283
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════ Duplicate GlobalKey detected in widget tree. ════════════════════════════════════════════════════════════════════════════════

7 Replies

YG Yuvaraj Gajaraj Syncfusion Team January 30, 2024 02:40 PM UTC

Hi Ramti,


We already have a KB that explains how to handle the appointments for multiple resources and we have shared it below for your reference. Kindly cross-check this once and ensure you have achieved your sample as per KB guidance. We have also checked the shared issue stack trace and it is not related to our control. So, we kindly request you to share more details such as screenshots or screen recordings along with the sample to reproduce the issue that would be more helpful to us to provide a solution sooner.


KB, https://support.syncfusion.com/kb/article/10147/how-to-handle-appointments-for-multiple-resources-in-the-flutter-calendar


Regards,

Yuvaraj.



RR ramti ramti January 30, 2024 04:15 PM UTC

Hi , Thanks for getting back to me. I followed the instructions on the link but same issue here is the complete screenshot of the error and attached is a screen recording of the issue:





Attachment: Screen_Recording_20240130170521_b1ff1b98.zip


YG Yuvaraj Gajaraj Syncfusion Team January 31, 2024 09:16 AM UTC

Hi Ramti,


We tried to replicate the reported issue regarding the Range error exception when updating the resource list at our end. Unfortunately, we are not able to reproduce the reported issue, we can't go further without having a proper sample to reproduce the issue and we are not exactly sure in what scenario the issue is replicating. So, we kindly request you to try to replicate the reported issue in the below attached test sample and revert us so that it will help us assist you in a better way.


Regards,

Yuvaraj.


Attachment: f186473_5d4ff9b1.zip


RR ramti ramti February 1, 2024 08:58 AM UTC

HI,


Here is the modified version replicating the error. I tried to include comments as much as possible to help replicate the issue. The general Considerations are below:


This is code allows the user to see appointments of all ressources or choose to see the appointments of Dr.joseph
only.
The calendar is in Timeline View.

Here are the steps to Reproduce the error:
  1-Click on any calendar Cell To add additional Appointments for stephan.
  2- CLick on Dr Joseph only Switch.

Important Consideration!: This error only appear after adding additional appointments for stephan. However,
if you switch between all ressources and dr joseph after initial initialization, everything would work as expected.


Attachment: test_4c57f2d.zip


YG Yuvaraj Gajaraj Syncfusion Team February 2, 2024 12:54 PM UTC

Hi Ramti,


We have checked your sample and found that you have tried to show Dr Joseph's appointment when Dr Joseph only switch gets toggled and shows all the resources and its appointment when the All Resources switch gets toggled. In this process, every time you have removed all the resources and their appointments and again populate it then added it to the data source.

Instead of doing this, we request you to have a Dr Joseph resource and its appointment statically and remove and add Stephen's resource and appointment alone. When toggling the Dr Joseph only switch remove the resource and appointment of Stephen and Add the resource and appointment of Stephen's when the All Resource switch gets toggled.

So please try the shared steps above to add and remove appointments and let us know if the issue still gets reproduced.


Regards,

Yuvaraj.



RR ramti ramti March 2, 2024 11:14 PM UTC

Hi, Thank you for getting back. We have gone deeper into that, and we still have the same problem. It gets more complicated in our case since we are displaying resources by categories. And when we switch from one category to another, there are no common resources, so are unable what was suggested unfortunetly.  We have noticed that when the bottom cell of a calendar with let's say "6" row is selected. And we move to a category with 4 rows. The 6 th row is still selected and thus we get the error. It is like teh cell in the 6 row is still selected but the  code sees that there are only 4 rows and thus we get  "   RangeError (index): Invalid value: Not in inclusive range 0..3: 5



YG Yuvaraj Gajaraj Syncfusion Team March 4, 2024 10:40 AM UTC

Hi Ramti,


In the previous response, we suggest that instead of removing all the resources and appointments remove the required resource and its appointment and have another resource and its value static. We have checked the shared sample but still, the issue is not getting reproduced at our end. So, we kindly request you to reproduce the report in the following attached sample and get back to us.


Regards,

Yuvaraj.


Attachment: f186473_96437a35.zip

Loader.
Up arrow icon