I have a couple of GET requests to make from flutter to an API, optimally I would like to have this run as efficiently as possible. I'm still learning Flutter, and coming from a JS background, I went with a pattern similar to Promise.all([ ... ])
in Javascript but I feel like this is a hack rather than a solution.
If there is a better approach to this, I look forward to reading about it:
final apiProvider = new ApiProvider();
final apiData = await Future.wait([
apiProvider.getProducts(), // Returns Future<List<Product>>
apiProvider.getCategories(), // Returns Future<List<Category>>
apiProvider.getBrands(), // Returns Future<List<Brand>>
apiProvider.getCustomers(), // Returns Future<List<Customer>>
]);
List<Product> products = apiData[0];
List<Category> categories = apiData[1];
List<Brand> brands = apiData[2];
List<Customer> customers = apiData[3];