Hello I have a Flutter app and a UserModel which was generated by Amplify. In the UserModel I have two fields named followers and following which are lists. I wish to add the userID to them when the user presses the follow button. I defined them as
...
followers: [],
following: [],
...
By my knowledge these two lists should be growable but when I press the follow button to follow a specific user I get an error saying:
Unsupported operation: Cannot add to a fixed-length list
The error points me to the function where I described the logic of following a user which is
void followOneUser(
User currentUser,
User user,
BuildContext context,
) async {
if (currentUser.following.contains(user.id)) {
currentUser.following.remove(user.id);
user.followers.remove(currentUser.id);
} else {
currentUser.following.add(user.id);
^^^^ // this is what causes the error
user.followers.add(currentUser.id);
}
currentUser = currentUser.copyWith(following: currentUser.following);
user = user.copyWith(followers: user.followers);
final result = await ref.watch(userRepoProvider.notifier).followUser(
currentUser,
user,
);
result.fold(
(l) => context.showError(
l,
),
(r) async {
final res =
await ref.watch(userRepoProvider.notifier).incrementFollowing(
currentUser,
user,
);
res.fold(
(l) => context.showError(
l,
),
(r) => null,
);
},
);
}
I checked how the following and followers fields were described in UserModel and I couldn't figure out where they were defined as ungrowable Lists. Please help me fix this issue.
Thank you in advance