I manage a ListView.builder
inside a Drawer
that should show all my friend requests. By clicking on any item in these friend requests, I can access another page (OtherProfilePage
) where I see the details of the friend request and can accept/decline the friend request.
However, when I accept/decline my friend request, I encounter the following error:
======== Exception caught by widgets library =======================================================
The following RangeError was thrown building OtherProfilePage(dirty, dependencies: [InheritedCupertinoTheme, MediaQuery, _InheritedTheme, _LocalizationsScope-[GlobalKey#d2179]], state: _OtherProfilePageState#0c87c):
RangeError (length): Invalid value: Valid value range is empty: 0
The relevant error-causing widget was:
OtherProfilePage OtherProfilePage:file:///C:/Users/Julien/StudioProjects/opinions/lib/main.dart:117:58
When the exception was thrown, this was the stack:
#0 List.[] (dart:core-patch/growable_array.dart)
#1 findFindRequestMap (package:opinions/utils/functions/friends_functions.dart:30:39)
#2 _OtherProfilePageState.build (package:opinions/pages/other_profile_page.dart:45:17)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:5729:27)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5617:15)
#5 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#6 Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#7 BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2693:15)
#8 BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2752:11)
#9 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3048:18)
#10 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1162:21)
#11 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:468:5)
#12 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#13 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1318:9)
#14 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#15 _invoke (dart:ui/hooks.dart:312:13)
#16 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#17 _drawFrame (dart:ui/hooks.dart:283:31)
====================================================================================================
Initially, I thought this error was due to passing my userAccount
as an extra
to OtherProfilePage
, and when the list becomes empty, the extra
also becomes empty, causing my other page to crash. However, after modifying my approach to use a provider for extra
, the error persists. I suspect this is due to the ListView.builder
not being able to handle the change in length, but I’m not sure…