Home > Blockchain >  Refreshing a screen to update data in Flutter
Refreshing a screen to update data in Flutter

Time:01-10

I am trying to understand how to refresh my app screen with new data. The app is a dashboard that has several job cards and when another user applies something to the card there is a refresh button in the app that all users can press to get the latest version of the update. Stupid fix I know but I am clueless atm.... its summer and very hot any guidance will be very very appreciated. I have a function refreshLists, within this function I have a bunch of calls to functions that send a request off to my API for data. My problem. I am unable to understand how to send a refresh request from my asp.net 6 web API so that the screen refreshes when data has updated. My solution so far was to use an IconButton and within the on pressed it goes like this

onpressed() async {
 await refreshLists();
 setstate(){};
}

Why do I have to click the button twice for the screen to update with the new data. instead of running the function then when the lists are all updated then the screen is rebuilt. Cheers for any help all answers will be appreciated.

CodePudding user response:

  1. A simple fix to this problem is that make a stream builder and set the stream as your function to refresh the list.

  2. Or you can use any state management so that it will notify all the listeners when there is a data change

CodePudding user response:

You describe 2 problems. To trigger data update from the server, you need to establish a web-socket connection or use a 3rd party service, like firebase.

In addition, the "set state" is a basic flutter building block that you should use for specific cases. Usually, when you build an app, you would like to work with stateless widgets and a state manager that tells the UI when and what to refresh

  •  Tags:  
  • Related