Baseflow / Baseflow/flutter_cached_network_image

When an image not found error occurs, the image error is not cached when using memCacheHeight and memCacheWidth

Open
#928 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

## 🔙 Regression

In case of image error, error is not cached when using `memCacheHeight` and `memCacheWidth`.

Started with Flutter version 3.16 and also reproducible in 3.19. Works correctly with Flutter 3.13.

### Old (and correct) behavior
Image error is cached and network call is only made once when using `memCacheHeight` and `memCacheWidth`.

### Current behavior
Image error is not cached and network call is made every time when using `memCacheHeight` and `memCacheWidth`.

### Reproduction steps

```
import 'dart:async';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';

void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Reload Image')),
body: const MyImageWidget(),
),
));
}

class MyImageWidget extends StatefulWidget {
const MyImageWidget({super.key});

@override
MyImageWidgetState createState() => MyImageWidgetState();
}

class MyImageWidgetState extends State {
static const imageCacheKey = 'one_day_cached_network_image_key';

static CacheManager cacheManagerInstance = CacheManager(
Config(
imageCacheKey,
stalePeriod: const Duration(days: 1),
),
);

Timer? _timer;

@override
void initState() {
super.initState();
_startTimer();
}

@override
void dispose() {
_timer?.cancel();
super.dispose();
}

void _startTimer() {
const duration = Duration(seconds: 5);
_timer = Timer.periodic(duration, (timer) {
if (mounted) {
setState(() {});
}
});
}

@override
Widget build(BuildContext context) {
return CachedNetworkImage(
imageUrl: "https://random/icon.png",
memCacheHeight: 100,
memCacheWidth: 100,
imageBuilder: (context, imageProvider) => Image(image: imageProvider),
errorWidget: (context, url, error) => const Icon(Icons.nearby_error_outlined),
);
}
}

```

### Configuration

**Version:** 3.3.1

**Platform:**
- [ ] :iphone: iOS
- [x] :robot: Android

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.