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

Avoid doing network calls in Widget build method? #1

Open
camillo777 opened this issue Nov 17, 2019 · 2 comments
Open

Avoid doing network calls in Widget build method? #1

camillo777 opened this issue Nov 17, 2019 · 2 comments

Comments

@camillo777
Copy link

camillo777 commented Nov 17, 2019

Flutter best practices advice to avoid doing network calls in Widget build method; you did it by loading the avatar image from the network:

backgroundImage: NetworkImage( appState.getResponseJson()[index][‘avatar’]), ),

I am struggling with it myself, is this code correct or could be improved?
What is supposed to be a best practice to load images as well?
Downloading the image directly in the state as well?
Thank you for your help!
Camillo

@ponnamkarthik
Copy link
Owner

Hai @camillo777 This line of code just get already retrieved JSON from a variable it doesn't trigger any background task

NetworkImage widget we can use it in build method

@camillo777
Copy link
Author

@ponnamkarthik thank you!
I was saying about the network image widget.
Flutter can call build method many times without a purpose, does this mean that every time it goes to the network and fetch the image?
Am I wrong?

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

2 participants