How to work with progress indicator in flutter?

后端 未结 12 820
面向向阳花
面向向阳花 2020-12-02 05:29

I\'m newbie in flutter and wanted to know what is better way to add CircularProgressIndicator in my layout. For example, my login view. This view have username,

12条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 05:49

    You can use FutureBuilder widget instead. This takes an argument which must be a Future. Then you can use a snapshot which is the state at the time being of the async call when loging in, once it ends the state of the async function return will be updated and the future builder will rebuild itself so you can then ask for the new state.

    FutureBuilder(
      future:  myFutureFunction(),
      builder: (context, AsyncSnapshot> snapshot) {
        if (!snapshot.hasData) {
          return Center(
            child: CircularProgressIndicator(),
          );
        } else {
         //Send the user to the next page.
      },
    );
    

    Here you have an example on how to build a Future

    Future myFutureFunction() async{
     await callToApi();}
    

提交回复
热议问题