getAvatar method
Implementation
Future<ImageProvider?> getAvatar([bool useCache = false]) async {
try {
FileInfo? cached;
if (useCache && getAvatarUrl() != null) {
cached = await DefaultCacheManager().getFileFromCache(getAvatarUrl()!);
if (cached != null) {
return MemoryImage(cached.file.readAsBytesSync());
}
}
if (getAvatarUrl() != null) {
Uint8List? bytes = await _getImageBytes(getAvatarUrl()!);
if (bytes != null) {
if (useCache && getAvatarUrl() != null) {
await DefaultCacheManager()
.putFile(getAvatarUrl()!, bytes, maxAge: Duration(days: 7));
}
return MemoryImage(bytes);
}
}
} catch (e) {}
return null;
}