Skip to content

Commit

Permalink
display images without file ending
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Nov 12, 2024
1 parent e91bc13 commit 63512f0
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions lib/presentation_layer/atoms/my_profile_picture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,43 @@ class UserImage extends StatelessWidget {
Widget build(BuildContext context) {
final pictureUrl = imageUrl ?? "${Dicebear.baseUrl}$pubkey";

if (pictureUrl.contains(".png") ||
pictureUrl.contains(".jpg") ||
pictureUrl.contains(".jpeg") ||
(!disableGif && pictureUrl.contains(".gif")) ||
pictureUrl.contains(".webp") ||
pictureUrl.contains(".avif")) {
// Check if it's a GIF and should be disabled
if (disableGif && pictureUrl.toLowerCase().endsWith('.gif')) {
// Return a placeholder or static image for disabled GIFs
return ClipOval(
child: SizedBox.fromSize(
size: Size.fromRadius(size / 2),
child: Container(
color: Palette.background,
child: CachedNetworkImage(
imageUrl: pictureUrl,
filterQuality: filterQuality,
progressIndicatorBuilder: (context, url, downloadProgress) =>
const CircularProgressIndicator(
color: Palette.darkGray,
),
errorWidget: (context, url, error) => const Icon(Icons.error),
memCacheWidth: cacheHeight ?? 150,
maxHeightDiskCache: cacheHeight ?? 150,
maxWidthDiskCache: cacheHeight ?? 150,
alignment: Alignment.center,
fit: BoxFit.cover,
),
child: const Icon(Icons.image, color: Palette.darkGray),
),
),
);
}

if (pictureUrl.contains(".svg")) {
return Container(
height: size,
width: size,
decoration: const BoxDecoration(
color: Palette.primary,
shape: BoxShape.circle,
// For all other cases, use CachedNetworkImage
return ClipOval(
child: SizedBox.fromSize(
size: Size.fromRadius(size / 2),
child: Container(
color: Palette.background,
child: CachedNetworkImage(
imageUrl: pictureUrl,
filterQuality: filterQuality,
progressIndicatorBuilder: (context, url, downloadProgress) =>
const CircularProgressIndicator(
color: Palette.darkGray,
),
errorWidget: (context, url, error) => const Icon(Icons.error),
cacheKey: pictureUrl,
memCacheWidth: cacheHeight ?? 150,
maxHeightDiskCache: cacheHeight ?? 150,
maxWidthDiskCache: cacheHeight ?? 150,
alignment: Alignment.center,
fit: BoxFit.cover,
),
),
child: SvgPicture.network(pictureUrl),
);
}

return Container(
height: size,
width: size,
decoration: const BoxDecoration(
color: Palette.primary,
shape: BoxShape.circle,
),
child: SvgPicture.network("${Dicebear.baseUrl}$pubkey"),
);
}
}

0 comments on commit 63512f0

Please sign in to comment.