小编Fai*_*sal的帖子

dart中解析对象(不支持的操作:无法添加到固定长度列表)

我有一个用户对象,当用户登录/注册时,该对象保存到云 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)

arrays json dart flutter google-cloud-firestore

13
推荐指数
3
解决办法
2万
查看次数

标签 统计

arrays ×1

dart ×1

flutter ×1

google-cloud-firestore ×1

json ×1