'How to solve exception caught by widgets library?
I want to use cached network image to display images in my flutter app, however it shows this:
═══════ Exception caught by widgets library ═══════════════════════════════════
Invalid argument (onError): Error handler must accept one Object or one Object and a StackTrace as arguments.: Closure: () => Null
The relevant error-causing widget was
CachedNetworkImage
lib/widgets/custom_image.dart:5
════════════════════════════════════════════════════════════════════════════════
custom_image.dart -
import 'package:flutter/material.dart';
Widget cachedNetworkImage(String mediaUrl) {
return CachedNetworkImage(
imageUrl: mediaUrl,
fit: BoxFit.cover,
placeholder: (context, url) => Padding(
child: CircularProgressIndicator(),
padding: EdgeInsets.all(20.0),
),
errorWidget: (context, url, error) => Icon(Icons.error),
);
}
Please help.
Solution 1:[1]
Wrap your CachedNetworkImage with a Container.
return Container(
width:...,
height:...,
child: CachedNetworkImage(..)));
Solution 2:[2]
After doing some research and trial and error.
I think the issue is in the package. The error you are getting was a bug in the old version of the HTTP package and I think your cached_network_image is outdated.
Try flutter pub upgrade, resolve any
dependency conflicts, do flutter clean, and flutter pub get.
Also, make sure your flutter SDK is updated as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Reham Alraee |
Solution 2 | sharib ahmed |