💄 Optimize the link embed
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blurhash/flutter_blurhash.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
class UniversalImage extends StatelessWidget {
|
||||
final String uri;
|
||||
@@ -9,6 +10,8 @@ class UniversalImage extends StatelessWidget {
|
||||
final double? width;
|
||||
final double? height;
|
||||
final bool noCacheOptimization;
|
||||
final bool isSvg;
|
||||
final bool useFallbackImage;
|
||||
|
||||
const UniversalImage({
|
||||
super.key,
|
||||
@@ -18,10 +21,26 @@ class UniversalImage extends StatelessWidget {
|
||||
this.width,
|
||||
this.height,
|
||||
this.noCacheOptimization = false,
|
||||
this.isSvg = false,
|
||||
this.useFallbackImage = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isSvgImage = isSvg || uri.toLowerCase().endsWith('.svg');
|
||||
|
||||
if (isSvgImage) {
|
||||
return SvgPicture.network(
|
||||
uri,
|
||||
fit: fit,
|
||||
width: width,
|
||||
height: height,
|
||||
placeholderBuilder:
|
||||
(BuildContext context) =>
|
||||
Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
int? cacheWidth;
|
||||
int? cacheHeight;
|
||||
if (width != null && height != null && !noCacheOptimization) {
|
||||
@@ -50,13 +69,15 @@ class UniversalImage extends StatelessWidget {
|
||||
child: CircularProgressIndicator(value: progress.progress),
|
||||
);
|
||||
},
|
||||
errorWidget: (context, url, error) {
|
||||
return Image.asset(
|
||||
'assets/images/media-offline.jpg',
|
||||
fit: BoxFit.cover,
|
||||
key: Key('image-broke-$uri'),
|
||||
);
|
||||
},
|
||||
errorWidget:
|
||||
(context, url, error) =>
|
||||
useFallbackImage
|
||||
? Image.asset(
|
||||
'assets/images/media-offline.jpg',
|
||||
fit: BoxFit.cover,
|
||||
key: Key('image-broke-$uri'),
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user