FutureBuilder                   in            Flutter

Scribbled Arrow

FutureBuilder helps use for managing the asynchronous data. It helps us to build our User Interface depending on the Future State. It helps us what to show when the data is being received from the APIs and what to show when the data is received or if there is an error what to show then.

FutureBuilder(            future: fuctionName,            builder: (context, snapshot) {          switch       (snapshot.connectionState) {        case ConnectionState.none:                 return Text('fetch data.');        case ConnectionState.active:    return CircularProgressIndicator();           case ConnectionState.waiting:         return CircularProgressIndicator();        case ConnectionState.done:                 if (snapshot.hasError) {                   return Text('Error:                    ${snapshot.error}');                 }                 else {                                       return Text('Data:                   ${snapshot.data}');                 }                        }                  },             ),        ),

Example