- Hi, I am trying to organize my Github repository to include API calls. The problem is that, I don’t properly know how. I am trying to separate all API calls in a different file from the file that I use the widgets in. For example: YelpCalls.dart and YelpScreen.dart. An example of a function in the YelpCalls file would a Future function such as
Then in the widget file where it calls this file, I need to get access to this in the widgets file in the where I need to call setState() instead of using a FutureBuilder because of additional logic which needs to be done before I call the widget. Then I run into the error where you when you assign the result to a variable you need to create a future variable. What is the best practice for this specific use case?
A example of this would be, using FutureBuilder keeps calling the API over and over for some odd reason so I want to display the results using List Display instead. To call the results I first do it in the initState() and use setState() to save it to a global variable that the widget can access.
Please let me know if any more information is needed. I am just asking what best practices are, or if someone has a really good example of a repo that has really good practices. I just want to separate my code. A lot of examples I see just create the function for the REST call within the same file as the widget file.