Home > Net >  Circular progress indicator without Future Builder flutter
Circular progress indicator without Future Builder flutter

Time:07-10

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,
            ),
          ),

CodePudding user response:

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.

  • Related