Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flutter_cache_manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [3.5.1] - 2026-12-03

* Fixes the next `getImageFile` call with `maxWidth` or `maxHeight` ending without a file or an error after a listener stopped listening early, for example on a download error ([#439](https://github.com/Baseflow/flutter_cache_manager/issues/439)).

## [3.5.0] - 2026-11-04

* **DEPRECATION** Deprecates `supportedFileNames`: whether an image is resized is now decided by the image engine from the file's content instead of from the file extension derived from the `Content-Type` header of the response ([#475](https://github.com/Baseflow/flutter_cache_manager/pull/475))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ mixin ImageCacheManager on BaseCacheManager {
).asBroadcastStream();
_runningResizes[resizedKey] = runningResize;
}
yield* runningResize;
_runningResizes.remove(resizedKey);
try {
yield* runningResize;
} finally {
// Also when the listener cancels, for example on a download error.
// Otherwise the next call would get the finished stream and no file.
_runningResizes.remove(resizedKey);
}
}

final Map<String, Stream<FileResponse>> _runningResizes = {};
Expand Down
2 changes: 1 addition & 1 deletion flutter_cache_manager/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_cache_manager
description: Generic cache manager for flutter. Saves web files on the storages of the device and saves the cache info using sqflite.
version: 3.5.0
version: 3.5.1
homepage: https://github.com/Baseflow/flutter_cache_manager
topics:
- cache
Expand Down
33 changes: 33 additions & 0 deletions flutter_cache_manager/test/image_cache_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';

import 'cache_manager_test.dart';
import 'helpers/config_extensions.dart';
import 'helpers/mock_file_service.dart';
import 'helpers/test_configuration.dart';
import 'test_images.dart';

Expand Down Expand Up @@ -127,6 +129,37 @@ void main() {
config.verifyDownloadCall();
expect(progress, isNotEmpty);
});

test('Resized image should download again after an error', () async {
var config = createTestConfig();
var error = HttpExceptionWithStatus(
500,
'Invalid statusCode: 500',
uri: Uri.parse(fileUrl),
);
var calls = 0;
when(
config.mockFileService.get(any, headers: anyNamed('headers')),
).thenAnswer((_) async {
calls++;
if (calls == 1) throw error;
return TestResponse();
});
var cacheManager = TestCacheManager(config);

// Stops listening at the error, like CachedNetworkImage does.
await expectLater(
cacheManager.getImageFile(fileUrl, maxWidth: 100).first,
throwsA(error),
);
var result =
await cacheManager.getImageFile(fileUrl, maxWidth: 100).last
as FileInfo;

var image = await result.file.readAsBytes();
await verifySize(image, 100, 100);
config.verifyDownloadCall(2);
});
});

group('Test image detection', () {
Expand Down