import 'dart:io';

import 'package:path_provider/path_provider.dart';

class JsonStorageClient {

  save(String filename, String data) async {
    File file = await _getJson(filename);
    await file.writeAsString(data);
  }

  Future<String> load(String filename) async {
    File file = await _getJson(filename);
    return file.readAsString();
  }

  delete(String filename) async {
    File file = await _getJson(filename);
    await file.delete();
  }

  Future<File> _getJson(String filename) async {
    final dir = await getApplicationDocumentsDirectory();
    final file = File('${dir.path}/$filename'); 
    if (!file.existsSync()) {
      file.createSync();
    }
    return file;
  }
}