Home > Blockchain >  How do you run CircularProgreessIndicator for some time and then display some text like "Nothin
How do you run CircularProgreessIndicator for some time and then display some text like "Nothin

Time:05-29

I am trying to fetch data from DB, I want the circular progress to be shown for some seconds and display a text if nothing is fetched or else show the data

CodePudding user response:

Take a look at the FutureBuilder class. It allows you to display a loading widget if the request to your db is still pending, display the data if the request was successful, or display some error message if the request wasn't.

CodePudding user response:

a simple example with Futurebuilder

FutureBuilder(
    future: _databaseCall, // async work
    builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
       switch (snapshot.connectionState) {
         case ConnectionState.waiting: return CircularProgressIndicator();
         default:
           if (snapshot.hasError)
              return Text('Error: ${snapshot.error}');
           else
          return Text('Result: ${snapshot.data}');
//here your database data
        }
      },
    )
  • Related