Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 2 tasks
olaripihlak opened this issue Feb 27, 2024 · 0 comments

Comments

@olaripihlak
Copy link

olaripihlak commented Feb 27, 2024

馃敊 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<MyImageWidget> {
  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:

  • 馃摫 iOS
  • 馃 Android
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant