How to Overwrite or Update Cache files in Flutter while using Path Provider

Solution for How to Overwrite or Update Cache files in Flutter while using Path Provider
is Given Below:

Below Code i have created for local caching using path provider

String fileName="pathString.json";
var dir=await getTemporaryDirectory();
File file=File(dir.path+"/"+fileName);

if(!file.existsSync()) {
        final http.Response response = await http.get(
            Uri.parse("https://*************.herokuapp.com/*********"));
        file.writeAsStringSync(
            response.body, flush: true, mode: FileMode.write);
        final data = file.readAsStringSync();
        responseData = json.decode(data);
      }else{
        final data = file.readAsStringSync();
        responseData = json.decode(data);
        final http.Response response = await http.get(
            Uri.parse("https://**************.herokuapp.com/*********"));
        file.writeAsStringSync(
            response.body, flush: true, mode: FileMode.write);
      }

for first time, File can be Created. But For Second time.. Once File is created, and API fetches latest response with updated data, Cache file not get overwritten.

It would be great, if anyone can help on this..

Thanks in Advance.