Is there any way to get around 404 on Image.network? - flutter

I'm stuck with this for about 3 hours, and after a lot of research still can't do it.
FadeInImage(
image: NetworkImage(
"http://url.test/content/dam/images/aaf/products/_codepageff/${name}.png"),
height: 20,
placeholder: const AssetImage('assets/wait.png'),
imageErrorBuilder: (context, error, stackTrace) {
return Image.asset('assets/ups.png',
fit: BoxFit.fitWidth);
},
fit: BoxFit.fitWidth,
),
I've tried A lot of codes, and still without no success on 404. Is there a known error or am I missing anything?
Also I'm building this inside a StatelessWidget class.

Give absolute url for NetworkImage. 404 means that the image is not found from that url.

Related

CachedNetworkImage is not displaying image though image is not null

I am facing this weird error, though imageUrl is not null, placeholder is getting triggered instead of image build.
Container(
height: specialOfferTileHeight,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: CachedNetworkImage(
fit: BoxFit.cover,
imageUrl: homeSpecialModel.image.url,
placeholder: (context, url) => Text(url),
errorWidget: (context, url, error) => Text(error)),
)
Output:
imageUrl is url
It took me about 25s to load the image for the first time. And for flutter, it may take more than 25s, you can try with a lighter image to try
I doubt that you are specifying correct url. Try to debug with print(homeSpecialModel.image.url);. Check that it is exact url that you provided. Or you can directly put String value of url like
imageUrl: "https://res.cloudinary.com/dpurb6xes/image/upload/v1668425797/vivans/ijynvhpdy7hms8z2vuhh.png",
If the url is correct, but still you are getting this error then provide with screenshots please.
After restart it started working as expected !

cached_network_image throw Invalid image data exception if url is 404

I am using CachedNetworkImage in book list. If image url is wrong or 404, it is throw Invalid image data exception in firebase Crashlytics report. But in app, image in list is showing black container that in written in errorWidget. My question is how I can catch this error instead of throwing exception. You can even get the exception at debug mode.
Now firebase is keeping on sending the email alert, because of repetitive crashes.
CachedNetworkImage(
width: 110.0,
fit: BoxFit.cover,
imageUrl: ebook.thumbnail,
placeholder: (context, url) => Container(color: Colors.black12),
errorWidget: (context, url, error) =>
Container(color: Colors.black12),
)

Exception Flutter from fetch network Image without connection internet

after turning off the internet i gets this error: "Remove network images from cache on any exception during loading"
my app fetch pictures from api. how can i fix this bug how i prevent that?
return Column(children: [
GestureDetector(
child: Image.network(thumbnailUrl))])
You can use the Cached Network Image Plugin if you are developing for android and ios. In Web, the plugin is not working as expected.
Use the following as a widget for your application.
import 'package:cached_network_image/cached_network_image.dart';
Widget commonCacheImageWidget(String? url, {double? width, BoxFit? fit, double? height}) {
if (url!.startsWith('http')) {
return CachedNetworkImage(
placeholder: (context, url) => Image.asset('assets/path....', fit: BoxFit.cover),
imageUrl: url,
height: height,
width: width,
fit: fit,
);
} else {
return Image.asset(url, height: height, width: width, fit: fit);
}
}
In Placeholder you can have any widget, here am using a local image that is stored as an asset.
Or You can check whether the internet connection is there or not before loading the image and change that to some other widget.

Flutter : set default image in Image.file

I'm currently creating Updating Image process in Flutter app.
I already succeed getting image that pass from some widget defined in View.dart to UpdateScreen widget defined in Update_screen.dart by using Network Image.
CircleAvatar(
radius: 100,
backgroundImage: NetworkImage(
'${Urls.BASE_API_IMAGE}/${widget.imageUpdate}'),
),
My question is, how to set default image using Image.file() ? , because I must use Image.file() for updating data.
Thank's
My full source code :
My Full Source Code Here
you can use this package cached_network_image as it makes it simple to set a default image.
Example
CachedNetworkImage(
imageUrl: "your url",
placeholder: (context, url) =>Your default Image Widget(),
errorWidget: (context, url, error) => new Icon(Icons.error),
),

FadeInImage with unknown image at runtime

I have a FadeInImage in my app, with the image loaded in response to a user action. This means at runtime, I dont know the image, and just want the FadeInImage to not display anything.
If I pass in null for the image, or an empty string, I get a runtime error.
flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
flutter: The following ArgumentError was thrown resolving an image codec:
flutter: Invalid argument(s): No host specified in URI file:///
Here it the relevant Widget declaration:
Container(
height: 100,
child:FadeInImage.memoryNetwork(
placeholder: kTransparentImage,
image: _d2apiModel.emblemUrl,
fit: BoxFit.fitWidth,
),
(where _d2apiModel is a Provider which is updated based on user actions).
I know I could put a default image in the asset bundle, copy it out of the bundle to the doc storage, get the file URI for the image, and use that as the default but 1) that seems like overkill, 2) i run into some async issues.
It seems like I am missing something obvious, but I cant figure out the approach. Any suggestions would be appreciated.
You can show a regular Image with kTransparentImage while your provider hasn't been updated, and then show your FadeInImage when it updates:
Container(
height: 100,
child: hasProviderBeenUpdated
? Image.memory(
kTransparentImage,
fit: BoxFit.fitWidth,
)
: FadeInImage.memoryNetwork(
placeholder: kTransparentImage,
image: _d2apiModel.emblemUrl,
fit: BoxFit.fitWidth,
),
),