RealmList: Cannot set late final field on realm object

Hi, we are in the process of rewriting our app and moving to flutter. We are making use of Realm as our data was already with MongoDB.

One of our collections stores an array of objects that is basically a form. This form is variable. We have mapped this to the Realm model as follows;

Late <List questionnaire;

The form essentially has various sections, each of which has questions etc.

When we attempt to update the form, if we trying to replace the list with the updated list which is the updated form, we get this error:

Cannot set late final field on realm object

We are able to iterate through the sections in the form and update them, but i don’t like this as unless we check the uuid of each section i feel it is too loose and could create risk.

Is it not possible to replace a RealmList?

1 Like

I encountered this issue today actually i found a work around by clearing the realmlist and adding a the new list to the realmlist

Repository.write(() async{
if(tempUserData.userPreferences.categories != updatedUserData.userPreferences.categories && updatedUserData.userPreferences.categories != null){
tempUserData.userPreferences.categories.clear();
tempUserData.userPreferences.categories.addAll(updatedUserData.userPreferences.categories);
}
});

in the above code i had this list of strings categories , before operating on it id check if it actually needed the update after which like i said earlier i cleared the list so looked something like this then i .addAll() to add the new list in its place , i hope this helps.