0

I want to fetch from multiple Futures in one sitting. So I use Future.wait. But I can't get Future2 value if Future1 throws error.

Is there a solution to this with or without Future.wait ?

FutureBuilder(
                  future: Future.wait([Future1,Future2]),
                  builder: (context, snapshot) {
                    switch (snapshot.connectionState) {
                      case ConnectionState.none:
    
                      case ConnectionState.active:
    
                      case ConnectionState.waiting:
                        return SizedBox(height: 600, child: LoadingIndicator());
                      case ConnectionState.done:
                       // snapshot.data will come as null because there is an error
                        
                        ...
Umut Arpat
  • 454
  • 1
  • 6
  • 18
  • this might be helpful for u:https://stackoverflow.com/questions/54465359/future-wait-for-multiple-futures – gretal Dec 03 '21 at 07:39

1 Answers1

0

Use catchError:

Future.wait([
  // fake future 1
  Future.delayed(const Duration()).catchError((e) {
    // add your error handler
  }),
  // fake future 2
  Future.delayed(const Duration()).catchError((e) {
    // add your error handler
  }),
]);
聂超群
  • 1,659
  • 6
  • 14