Dart: optimizing simultaneous data fetching
Let’s say we have a class ProductService , which is a singleton, like this: class ProductService { static ProductService? _instance; static ProductService get instance => _instance!; Future<List<Product>> fetchProducts() async { // Perform the HTTP request and transform the result } } In various places, we can call the method fetchProducts as: ProductService.instance.fetchProducts().then((v) { ... }); The problem is that this method might be called from various places simultaneously, including in multiple FutureBuilders for example, which will be wasting bandwidth and unnecessarily loading the server, and potentially slowing the app down....