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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set a new image url can not refresh #31

Closed
Jon2066 opened this issue Jul 11, 2023 · 10 comments
Closed

set a new image url can not refresh #31

Jon2066 opened this issue Jul 11, 2023 · 10 comments
Labels
question Further information is requested

Comments

@Jon2066
Copy link

Jon2066 commented Jul 11, 2023

_FastCachedImageState call _loadAsync only once,
when i set a new image url , new image will not be loaded.

I added this code

@override
  Widget build(BuildContext context) {
    if (_imageResponse?.error != null && widget.errorBuilder != null) {
      _logErrors(_imageResponse?.error);
      return widget.errorBuilder!(context, Object, StackTrace.fromString(_imageResponse!.error!));
    }
    if (_cachedUrl != widget.url) {
      _cachedUrl = widget.url;
      _loadAsync(_cachedUrl);
    }
@CHRISTOPANANJICKAL
Copy link
Owner

Can you explain how to recreate this issue?

@ghost ghost added the question Further information is requested label Jul 14, 2023
@PeterCore
Copy link

me to

@ShafiqSadat
Copy link

Same Issue!
can't update URL!

ShafiqSadat added a commit to ShafiqSadat/fast_cached_network_image that referenced this issue Sep 21, 2023
@ghost
Copy link

ghost commented Sep 21, 2023

@ShafiqSadat Please post a sample code here to reproduce this issue

@ShafiqSadat
Copy link

bandicam.2023-09-21.19-17-35-937.mp4

Check this video
and code

@ShafiqSadat
Copy link

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

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

  @override
  State<TestScreen> createState() => _TestScreenState();
}

String url = "https://wallpaperswide.com/download/color_test-wallpaper-2560x1440.jpg";

TextEditingController urlController = TextEditingController();
class _TestScreenState extends State<TestScreen> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          TextField(
            controller: urlController,
            onSubmitted: (value) {
              setState(() {
                url = value;
                print("IMAGE URL CHANGED TO: $url");
              });
            },
            style: TextStyle(
              color: Colors.white,
            ),
            cursorColor: Colors.white,
            decoration: const InputDecoration(
              labelStyle: TextStyle(
                color: Color(0xc5ffffff),
              ),
              enabledBorder: UnderlineInputBorder(
                borderSide: BorderSide(
                  color: Color(0x51ffffff),
                  width: 2.0,
                ),
              ),
              focusedBorder: UnderlineInputBorder(
                borderSide: BorderSide(
                  color: Color(0xFFffffff),
                  width: 2.0,
                ),
              ),
              labelText: 'New URL',
              prefixIcon: Icon(
                Icons.person,
                color: Color(0xFFffffff),
              ),
            ),
          ),

          FastCachedImage(
              url: url,
            height: 500,
              width: 500,
          ),
        ],
      ),
    );
  }
}

@ShafiqSadat
Copy link

@christoPBG

@ghost
Copy link

ghost commented Sep 21, 2023

@ShafiqSadat did you try adding a key to the widget?
FastCachedImage(
url: url,
key:Key(url),
height: 500,
width: 500,
),

@muccy-timeware
Copy link

Sorry @CHRISTOPANANJICKAL. I stumbled on the same problem and I'm asking myself if adding the key is a real solution. It seems to like a good workaround. Maybe I could look into it if you want, because we are developing an app relying on this plugin and otherwise we should create a wrapper in order to set the key everytime

@CHRISTOPANANJICKAL
Copy link
Owner

IMHO it's always good to use any service with a wrapper or like a DI model. The advantage is, in future if you try to change the package or if there comes a major update in the same package which affects the current usage code, you can change it in one place instead for changing it in all other widgets.

I am sorry to say that I am very busy these days. Ill address the issues once I am free. 🫰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants