Samuel Stanek
Samuel Stanek

Reputation: 43

How to show CircularProgressIndicator while build state is running in Flutter?

I have a HomePage with DataTable with several hundred rows, which takes a while to load. The HomePageState reloads every time I sort the data table - while building, the whole page freezes for a second or two.

Is it possible to add a progress indicator, build the new state in the background and show it after the build is done?

In other words, I want this to happen when a user sorts the table:

  1. CircularProgressIndicator shows up
  2. The new state is shown after the new state is built

Upvotes: 2

Views: 880

Answers (1)

Jitesh Mohite
Jitesh Mohite

Reputation: 34270

Hoping you are using FutureBuilder for getting data.

FutureBuilder(
        future: fetchData(),
        builder: (_, dataSnapshot) {
          if (dataSnapshot.connectionState == ConnectionState.waiting) {
            return Center(child: CircularProgressIndicator());
          } else {
            return Container(), // Your widgets code
            );
          }
        },
      )

inside else block get data like dataSnapshot.data -- Use this to render widgets.

Upvotes: 1

Related Questions