简体   繁体   中英

Circular progress indicator without Future Builder flutter

How can I add circular progress indicator by the time I press the Elevated Button while I am waiting for my data to show? It would be possible without the need of implementing Future Builder?

    ElevatedButton(
        onPressed: (() async {
          await postML(
              _mySelectionFeat1,
              _mySelectionFeat2,
              _mySelectionFeat3,
              _mySelectionValue1,
              _mySelectionValue2,
              _mySelectionValue3);
        }),
        child: Text('Post')),

    ShowDogCard == false
        ? const Center(
            child: Text('Please select features and values'),
          )
        : Container(
            child: ListCard(
              screen: 'ML',
              doglist: BreedList,
              index: idxBreedListPredicted,
            ),
          ),

A way is to have a boolean variable what you set true when you wanna start showing the CircularProgressIndicator, and then set false when you don't want to show it anymore:

bool _loading = true;

build() {
  return _loading ? CircularProgressIndicator() : mainWidget();
}

But the best way is to use FutureBuilder. That's what it is for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM