loadJson<T> function

Future<T?> loadJson<T>(
  1. String fileName, {
  2. bool cache = true,
})

Load a json file from the assets folder.

Implementation

Future<T?> loadJson<T>(String fileName, {bool cache = true}) async {
  try {
    String data = await rootBundle.loadString(fileName, cache: cache);
    dynamic dataJson = jsonDecode(data);
    if (!([String, int, double, dynamic].contains(T))) {
      return dataToModel<T>(data: dataJson);
    }
    return dataJson;
  } on Exception catch (e) {
    NyLogger.error(e.toString());
    return null;
  }
}