@@ -603,9 +603,18 @@ class ParseLiveList<T extends ParseObject> {
603603 // Setting the object will mark it as loaded and emit it to the stream
604604 _list[index].object = response.results! .first;
605605 } else if (response.error != null ) {
606- // Emit error to the element's stream so listeners can handle it
607- // Use _list[index] to ensure we emit to the current element at this index
608- _list[index].emitError (response.error! , StackTrace .current);
606+ // Emit error to the element's stream so listeners can handle it.
607+ // Guard against list mutations so we don't emit on the wrong element.
608+ final currentElement = _list[index];
609+ if (currentElement.object.objectId != element.object.objectId) {
610+ if (_debug) {
611+ print (
612+ 'ParseLiveList: Element at index $index changed during load (error)' ,
613+ );
614+ }
615+ return ;
616+ }
617+ currentElement.emitError (response.error! , StackTrace .current);
609618 if (_debug) {
610619 print (
611620 'ParseLiveList: Error loading element at index $index : ${response .error }' ,
@@ -786,7 +795,7 @@ class ParseLiveListElement<T extends ParseObject> {
786795 bool loaded = false ,
787796 Map <String , dynamic >? updatedSubItems,
788797 }) : _loaded = loaded,
789- _isLoading = false {
798+ isLoading = false {
790799 _updatedSubItems = _toSubscriptionMap (
791800 updatedSubItems ?? < String , dynamic > {},
792801 );
@@ -799,7 +808,7 @@ class ParseLiveListElement<T extends ParseObject> {
799808 final StreamController <T > _streamController = StreamController <T >.broadcast ();
800809 T _object;
801810 bool _loaded = false ;
802- bool _isLoading = false ;
811+ bool isLoading = false ;
803812 late Map <PathKey , dynamic > _updatedSubItems;
804813 LiveQuery ? _liveQuery;
805814 final Future <void > _subscriptionQueue = Future <void >.value ();
@@ -928,9 +937,6 @@ class ParseLiveListElement<T extends ParseObject> {
928937
929938 bool get loaded => _loaded;
930939
931- bool get isLoading => _isLoading;
932- set isLoading (bool value) => _isLoading = value;
933-
934940 /// Emits an error to the stream for listeners to handle.
935941 /// Used when lazy loading fails to fetch the full object data.
936942 void emitError (Object error, StackTrace stackTrace) {
0 commit comments