loadJson<T> function
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;
}
}