get method
Get the model of type T corresponding to the provided key.
-
Parameters:
- key: The key corresponding to the required data.
-
Returns: A Future containing model of type T or null if not found.
Implementation
Future<T?> get(String key) async {
try {
final cachedModel = modelCache.get(key);
if (cachedModel != null) return cachedModel;
final jsonData = await _fetchData();
if (jsonData.containsKey(key)) {
final modelJsonData = jsonData[key];
if (modelJsonData is Map<String, dynamic>) {
return _parseModel(key, modelJsonData);
}
}
} catch (error) {
debugLog('Failed to get $key', value: error);
}
return null;
}