updateResizedImage method
Implementation
Future<void> updateResizedImage(
final String key,
final int? width,
final int? height,
) async {
if (state.uiImages.isEmpty ||
isAnimatedImage ||
!state.uiImages.keys.contains(key)) return;
final tWidth = getTargetSize(width, imageInfo.width!);
final tHeight = getTargetSize(height, imageInfo.height!);
if (tHeight == null && tWidth == null) {
WidgetsBinding.instance.addPostFrameCallback((final _) {
state.uiImages.update(key, (final oldImage) {
oldImage.dispose();
return state.uiImages['']!.clone();
});
state = state.copyWith(isLoading: false);
});
return;
}
final completer = Completer<_ImageResolverResult>();
_ImageDecoder.schedule(
bytes: imageInfo.imageBytes!,
completer: completer,
height: tHeight,
width: tWidth,
);
final result = await completer.future;
if (mounted) {
state.uiImages.update(key, (final oldImage) {
oldImage.dispose();
return result.image;
});
state = state.copyWith(isLoading: false);
} else {
result.image.dispose();
}
}