我有一个用户对象,当用户登录/注册时,该对象保存到云 Firestore 数据库中。因此,当用户登录时,将从数据库中检索用户对象,并且一切正常,直到我尝试对列表“usersProject”执行“添加”操作:
// Add the new project ID to the user's project list
user.userProjectsIDs.add(projectID);
Run Code Online (Sandbox Code Playgroud)
所以我得到了例外,Unhandled Exception: Unsupported operation: Cannot add to a fixed-length list
我相信问题出在将用户从 json 转换为对象时,因为当用户注册时,对象被转换为 json 并存储在数据库中,并且用户将在转换之前使用该对象自动登录。
void createUser(String email, String password, String username, String name, String birthDate) async {
try {
// Check first if username is taken
bool usernameIsTaken = await UserProfileCollection()
.checkIfUsernameIsTaken(username.toLowerCase().trim());
if (usernameIsTaken) throw FormatException("Username is taken");
// Create the user in the Authentication first
final firebaseUser = await _auth.createUserWithEmailAndPassword(
email: email.trim(), …Run Code Online (Sandbox Code Playgroud)