title: Writing to a Local json file dart flutter
body: <p>I am creating an app that allows user to save small data. I have a json file in my assets folder and I would like to create an app that can write more json data to it. Path: assets/vault.json</p>
  
  <p>vault.json</p>
  
  <pre><code>[
    {
      "name":"Ash",
      "age":"22",
      "hobby" : "golf"
    },
    {
      "name":"philip",
      "age":"17",
      "hobby" : "fishing"
    },
    {
      "name":"charles",
      "age":"32",
      "hobby" : "drawing"
    }
  
  ]
  </code></pre>
  
  <p>However I am stuck at adding more list to the json file.</p>
  
  <p>In my main.dart, I created 3 textfield for input and a button onPress to trigger writeToFile(arg1,arg2,arg3).</p>
  
  <p>Here is what I have tried:</p>
  
  <pre><code>void writeToFile(String hobbyy, String agee, String namee) {
    print("Writing to file!");
  
    Map&lt;String, dynamic&gt; content = new Map();
    content1 = {name: namee};
    content2 = {age: agee};
    content3 = {hobby: hobbyy};
  
    content.addAll(content1);
    content.addAll(content2);
    content.addAll(content3);
  
  
    print(content);  //working fine
  }
  
  Future&lt;String&gt; _loadAVaultAsset() async {
    return await rootBundle.loadString('assets/vault.json');
  }
  
  Future loadVault() async {
    String jsonString = await _loadAVaultAsset();
    final jsonResponse = json.decode(jsonString);
    var add = jsonResponse.toString();
  
  
    add = add.replaceFirst(new RegExp(r'}]'), "},"+content.toString()+"]");
  
    print(add); //shows the full json string that I want. 
  
  //How to add/replace (add) into the json file?
  }
  </code></pre>
  
  <p>although I am getting the json string that I want, I am unable to reflect it in the json file.</p>
  
  <p>Here is my vault_model.dart (incase if there is any use):</p>
  
  <pre><code>class UsersList{
    final List&lt;Users&gt; user;
  
    UsersList({
      this.user,
    });
  
    factory UsersList.fromJson(List&lt;dynamic&gt; parsedJson){
  
      List&lt;Users&gt; entireList = new List&lt;Users&gt;();
  
      entireList = parsedJson.map((i)=&gt;Users.fromJson(i)).toList();
  
      return UsersList(
        user: entireList,
      );
    }
  }
  
  class Users{
    final String name;
    final String age;
    final String hobby;
  
    Users({
      this.name,
      this.age,
      this.hobby
  });
  
    factory Users.fromJson(Map&lt;String, dynamic&gt; json){
      return new Users(
        name: json['name'],
        age: json['age'],
        hobby: json['hobby'],
      );
    }
  
  }
  </code></pre>
  
  <p>Please teach me how to replace the old json string with the new string (add) in the assets/vault.json path.</p>