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

ImageNetwork is not reloading on state changes #17

Open
nietsmmar opened this issue May 22, 2023 · 4 comments
Open

ImageNetwork is not reloading on state changes #17

nietsmmar opened this issue May 22, 2023 · 4 comments

Comments

@nietsmmar
Copy link

I am using RiverPod to set a new state, replacing the URL in my ImageNetwork. But nothing happens. With normal Image.Network etc. it works well. But ImageNetwork just won't be build with the new URL.

@gabrielpatricksouza
Copy link
Owner

Send me an example code for me to test and solve,
Thanks in advance for your comment.

@haisul
Copy link

haisul commented Aug 23, 2023

I've encapsulated the ImageNetwork into a widget and established a callback function for the onTap event. Subsequently, I utilize this widget within another widget. To update the display, I use setState to replace the original widget and then override it. You can refer to below:

class NetImage extends StatelessWidget {
  final String filePath;
  final void Function() onPressed;

  const NetImage({Key? key, required this.filePath, required this.onPressed})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, constraints) {
      return ImageNetwork(
        image: filePath,
        width: constraints.maxWidth,
        height: constraints.maxHeight,
        fitWeb: BoxFitWeb.scaleDown,
        onTap: () => onPressed(),
      );
    });
  }
}

//another widget
void getImage() async {
  XFile? xfile = await ImagePicker.picker();
  if (xfile != null) {
    setState(() {
      filePath = xfile.path;
      widget.getFilePath(xfile.path);
      inner = NetImage(
        filePath: filePath,
        onPressed: () {
          setState(() {
            inner = addImage;
          });
          getImage();
        },
      );
    });
  }
}

@Coder-Manuel
Copy link

Any update on this....
Experiencing the same using getx

@sygem
Copy link

sygem commented Oct 12, 2023

I was having a similar issue, but solved it using a UniqueKey() on the ImageNetwork widget.

Any update on this.... Experiencing the same using getx

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

5 participants