RawSettings constructor

RawSettings(
  1. String appName
)

Loads the data into the class

Implementation

RawSettings(String appName){
  //Prevent the use of backslashes or slashes in the appname to prevent errors with the file system path
  appName = appName.replaceAll("/", "_");
  appName = appName.replaceAll("\\", "_");
  //Get the temporary directory
  Directory appTemporaryDirectory = Directory.systemTemp;
  //Define the Settings
  this._settingsPath = "${appTemporaryDirectory.path}/$appName/settings.json";
  //Read the file contents
  String json;
  //Prevent errors
  try{
    json = File(_settingsPath).readAsStringSync();
  }catch(error){
    json = "{}";
  }
  //Parse the json
  try{
    _settings = jsonDecode(json);
  }catch(error){
    _settings = {};
  }
  //Just to check that the settings are loaded
  //print(_settings);
}