title: Parsing object in dart (Unsupported operation: Cannot add to a fixed-length list)
body: <p>I have a user object which saved to the cloud firestore database when the user Sign In / Sign Up.
  So the user object is retrieved from the database when he signs in, and everything works until i try to do the 'add' operation on the list 'usersProject':</p>
  <pre><code>// Add the new project ID to the user's project list
  user.userProjectsIDs.add(projectID);
  </code></pre>
  <p>So i get the exception <code>Unhandled Exception: Unsupported operation: Cannot add to a fixed-length list</code>
  i believe the problem is when converting the user from json to object, because when the user is signing up the object is converted to json and stored in the database and the user will be automatically signed in using the object before converting.</p>
  <pre><code>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(&quot;Username is taken&quot;);
  
    // Create the user in the Authentication first
    final firebaseUser = await _auth.createUserWithEmailAndPassword(
        email: email.trim(), password: password.trim());
  
    // Encrypting the password
    String hashedPassword = Password.hash(password.trim(), new PBKDF2());
  
    // Create new list of project for the user
    List&lt;String&gt; userProjects = new List&lt;String&gt;();
  
    // Create new list of friends for the user
    List&lt;String&gt; friends = new List&lt;String&gt;();
  
    // Creating user object and assigning the parameters
    User _user = new User(
      userID: firebaseUser.uid,
      userName: username.toLowerCase().trim(),
      email: email.trim(),
      password: hashedPassword,
      name: name,
      birthDate: birthDate.trim(),
      userAvatar: '',
      userProjectsIDs: userProjects,
      friendsIDs: friends,
    );
  
    // Create a new user in the fire store database
    await UserProfileCollection().createNewUser(_user);
    
    // Assigning the user controller to the 'user' object
      Get.find&lt;UserController&gt;().user = _user;
      Get.back();
  
  } catch (e) {
    print(e.toString());
  }}
  </code></pre>
  <p>When the user is signed off then he signs in and try to make operation on the user object, here comes the problem some of the properties (the List type) can't be used.
  This code creates project and add <code>projectID</code> to the user's list</p>
  <pre><code>  Future&lt;void&gt; createNewProject(String projectName, User user) async {
  
  String projectID = Uuid().v1(); // Project ID, UuiD is package that generates random ID
  
  // Add the creator of the project to the members list and assign him as admin
  var member = Member(
    memberUID: user.userID,
    isAdmin: true,
  );
  List&lt;Member&gt; membersList = new List();
  membersList.add(member);
  
  // Save his ID in the membersUIDs list
  List &lt;String&gt; membersIDs = new List();
  membersIDs.add(user.userID);
  
  // Create chat for the new project
  var chat = Chat(chatID: projectID);
  
  // Create the project object
  var newProject = Project(
    projectID: projectID,
    projectName: projectName,
    image: '',
    joiningLink: '$projectID',
    isJoiningLinkEnabled: true,
    pinnedMessage: '',
    chat: chat,
    members: membersList,
    membersIDs: membersIDs,
  );
  
  
  // Add the new project ID to the user's project list
  user.userProjectsIDs.add(projectID);
  
  try {
    // Convert the project object to be a JSON
    var jsonUser = user.toJson();
  
    // Send the user JSON data to the fire base
    await Firestore.instance
        .collection('userProfile')
        .document(user.userID)
        .setData(jsonUser);
  
    // Convert the project object to be a JSON
    var jsonProject = newProject.toJson();
  
    // Send the project JSON data to the fire base
    return await Firestore.instance
        .collection('projects')
        .document(projectID)
        .setData(jsonProject);
  } catch (e) {
    print(e);
  }}
  </code></pre>
  <p>Here where the exception happens <strong>only when the user signs off then signs in</strong>, but when he signed up for the first time there will be no exception.</p>
  <pre><code> // Add the new project ID to the user's project list
  user.userProjectsIDs.add(projectID);
  </code></pre>
  <p>The sign in function</p>
  <pre><code>void signIn(String email, String password) async {
  try {
    // Signing in
    FirebaseUser firebaseUser = await _auth.signInWithEmailAndPassword(email: email.trim(), password: password.trim());
  
    // Getting user document form firebase
    DocumentSnapshot userDoc = await UserProfileCollection().getUser(firebaseUser.uid);
   
  
    // Converting the json data to user object and assign the user object to the controller
    Get.find&lt;UserController&gt;().user = User.fromJson(userDoc.data);
    print(Get.find&lt;UserController&gt;().user.userName);
  
  } catch (e) {
    print(e.toString());
  }}
  </code></pre>
  <p>I think the problem caused by <code>User.fromJson</code>
  why it makes the array from the firestore un-modifiable ?</p>
  <p>The user class</p>
  <pre><code>class User {
    String userID;
    String userName;
    String email;
    String password;
    String name;
    String birthDate;
    String userAvatar;
    List&lt;String&gt; userProjectsIDs;
    List&lt;String&gt; friendsIDs;
  
    User(
        {this.userID,
        this.userName,
        this.email,
        this.password,
        this.name,
        this.birthDate,
        this.userAvatar,
        this.userProjectsIDs,
        this.friendsIDs});
  
    User.fromJson(Map&lt;String, dynamic&gt; json) {
      userID = json['userID'];
      userName = json['userName'];
      email = json['email'];
      password = json['password'];
      name = json['name'];
      birthDate = json['birthDate'];
      userAvatar = json['UserAvatar'];
      userProjectsIDs = json['userProjectsIDs'].cast&lt;String&gt;();
      friendsIDs = json['friendsIDs'].cast&lt;String&gt;();
    }
  
    Map&lt;String, dynamic&gt; toJson() {
      final Map&lt;String, dynamic&gt; data = new Map&lt;String, dynamic&gt;();
      data['userID'] = this.userID;
      data['userName'] = this.userName;
      data['email'] = this.email;
      data['password'] = this.password;
      data['name'] = this.name;
      data['birthDate'] = this.birthDate;
      data['UserAvatar'] = this.userAvatar;
      data['userProjectsIDs'] = this.userProjectsIDs;
      data['friendsIDs'] = this.friendsIDs;
      return data;
    }
  }
  
  </code></pre>