title: How to update data in local JSON file in Flutter (Dart)
body: <p>I am using a local JSON file in my  flutter app. On a button click I want to change one item in same JSON file. The JSON file (UserData.json) is:</p>
  <pre><code>        {
              &quot;name&quot;: &quot;name1&quot;,
              &quot;companyName&quot;: &quot;companyName1&quot;,
              &quot;designation&quot;: &quot;designation1&quot;,
              &quot;isAdmin&quot;: &quot;FALSE&quot;
          },
          {
              &quot;name&quot;: &quot;name2&quot;,
              &quot;companyName&quot;: &quot;companyName2&quot;,
              &quot;designation&quot;: &quot;designation2&quot;,
              &quot;isAdmin&quot;: &quot;FALSE&quot;
          },
          {
              &quot;name&quot;: &quot;name3&quot;,
              &quot;companyName&quot;: &quot;companyName3&quot;,
              &quot;designation&quot;: &quot;designation3&quot;,
              &quot;isAdmin&quot;: &quot;FALSE&quot;
          },
          {
              &quot;name&quot;: &quot;name4&quot;,
              &quot;companyName&quot;: &quot;companyName4&quot;,
              &quot;designation&quot;: &quot;designation4&quot;,
              &quot;isAdmin&quot;: &quot;FALSE&quot;
          }
    ]
  </code></pre>
  <p>The model (user_model.dart) is:</p>
  <pre><code>  final String name;
    final String companyName;
    final String designation;
    final String isAdmin;
  
    User({
      this.name,
      this.companyName,
      this.designation,
      this.isAdmin,
    });
  
    factory User.fromJson(Map&lt;String, dynamic&gt; json) {
      return User(
        name: json['name'] as String,
        companyName: json['companyName'] as String,
        designation: json['designation'] as String,
        isAdmin: json['isAdmin'] as String,
      );
    }
  
    Map&lt;String, dynamic&gt; toJson() {
      return &lt;String, dynamic&gt;{
        'name': name,
        'companyName': companyName,
        'designation': designation,
        'isAdmin': isAdmin,
      };
    }
  }
  </code></pre>
  <p>For testing purpose, I want to update the 'companyName' of the first user in JSON file. The method(not complete yet) called on button press to  is:</p>
  <pre><code>updateJson() async {
      var rawJSON = await json.decode(await DefaultAssetBundle.of(context)
          .loadString('user_data/UserData.json'));
  
      rawJSON[0]['companyName'] = &quot;NewCompany&quot;;
      var var1 = json.encode(rawJSON);
    }
  </code></pre>
  <p>Please help me with the code to update the JSON file</p>