title: How to make my flutter app read upadated json file instead of old json file?
body: <p>I made a app where I have to first read local json file and updated some content of it inside app and save that file and without closing the app I want to display the changes by reading updated json file.
  I am able to read my json file, save changes in that file but when I try to see my changes without closing the app by reading that json file, it always show my previous data. But if I close my app and open it again It show read new updated file.
  How can I show changes by reading updated json file without closing the app??</p>
  <p>This is my code:
  First I read json file inside initstate:</p>
  <pre><code>Future&lt;void&gt; readJson() async {
  final String response =
      await rootBundle.loadString('jsonfile/primary_values.json');
  
  final data = jsonDecode(response);
  
  var values = PrimaryValueJson.fromJson(data);
  setState(() {
    if (primaryKey == 'Doctor SSN :') {
      widget.primaryIndex = values.doc_ssn;
      widget.primaryValue = 'DC0${widget.primaryIndex}';
      print(widget.primaryValue);
      print('this is readjson');
    }
  });
  </code></pre>
  <p>}</p>
  <pre><code>@override
    void initState() {
      super.initState();
      print(&quot;I am doctor init screen&quot;);
      readJson();
    }
  </code></pre>
  <p>And then I increment Doc.ssn by 1 and write it by clicking a button. Function associated with that button is:</p>
  <pre><code>_writeJson() async {
      print(&quot;this is 1st line writejson: ${widget.primaryIndex}&quot;);
      String response =
          await rootBundle.loadString('jsonfile/primary_values.json');
      File path = File('jsonfile/primary_values.json');
  
      var data = jsonDecode(response);
      var values = PrimaryValueJson.fromJson(data);
      final PrimaryValueJson doctor = PrimaryValueJson(
        doc_ssn: values.doc_ssn + 1,
        phar_id: values.phar_id,
        ssn: values.ssn,
      );
      final update = doctor.toJson();
      path.writeAsStringSync(json.encode(update));
      print('this is writejson:${doctor.doc_ssn}');
  
      nameController.text = '';
      specialityController.text = '';
      experienceController.text = '';
      widget.primaryIndex = doctor.doc_ssn;
      widget.primaryValue = 'DC0${doctor.doc_ssn}';
    }
  
    Future&lt;void&gt; insertRecord(context) async {
      count = count + 1;
     
      if (nameController.text == '' ||
          specialityController.text == '' ||
          experienceController.text == '') {
        print(&quot;Please fill all fields&quot;);
      } else {
        try {
          String uri = &quot;http://localhost/hospital_MS_api/insert_doctor.php&quot;;
  
          var res = await http.post(Uri.parse(uri), body: {
            &quot;Doc_SSN&quot;: widget.primaryValue,
            &quot;name&quot;: nameController.text,
            &quot;speciality&quot;: specialityController.text,
            &quot;experience&quot;: experienceController.text,
          });
          setState(() {
            _writeJson();
          });
  
          var response = jsonDecode(res.body);
          if (response[&quot;success&quot;] == &quot;true&quot;) {
            print(&quot;Record Inserted&quot;);
          } else {
            print(&quot;Record not inserted&quot;);
          }
        } catch (e) {
          print(e);
        }
      }
    }
  </code></pre>