platformNetworkImage function
Platform-aware network image widget.
On web: uses native HTML via HtmlElementView to bypass CanvasKit CORS.
On mobile: uses CachedNetworkImage for disk caching + better UX.
Implementation
Widget platformNetworkImage({
required String imageUrl,
Key? key,
BoxFit fit = BoxFit.cover,
double? height,
double? width,
Widget? placeholder,
Widget? errorWidget,
}) {
final optimizedUrl = _optimizeGoogleImageUrl(imageUrl);
if (kIsWeb) {
return buildWebNativeImage(
imageUrl: optimizedUrl,
fit: fit,
height: height,
width: width,
placeholder: placeholder,
errorWidget: errorWidget,
);
}
return CachedNetworkImage(
key: key,
imageUrl: optimizedUrl,
fit: fit,
height: height,
width: width,
placeholder: (context, url) =>
placeholder ?? const Center(child: CircularProgressIndicator(strokeWidth: 2)),
errorWidget: (context, url, error) =>
errorWidget ?? const Icon(Icons.image_not_supported),
);
}