1

In Flutter i try to call a web service to retrieve some data. When service works fills a list and show it on screen. I want to show a CircularProgressIndicator in full screen when if data is null (or trying to get data from service). Now CircularProgressIndicator is on the top on the page.

The code is

  Scaffold(
            body: Column(children: <Widget>[
              SafeArea(child: progress),
              loading == false ? rssi : indicator
            ]),



   final indicator = Container(
        child: Center(
      child: CircularProgressIndicator(
        valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
      ),
    ));

I want to show 'indicator' widget below 'progress' widget on the whole screen.

Any help?

El Hombre Sin Nombre
  • 2,906
  • 18
  • 49
  • 92

2 Answers2

2

You can create a common ProgressIndicator widget like this,

class ProgressDialogPrimary extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var brightness = MediaQuery
        .of(context)
        .platformBrightness == Brightness.light;
    ;
    return Scaffold(
      body: Center(
        child: CircularProgressIndicator(
          valueColor: new AlwaysStoppedAnimation<Color>(AppColors.themeColorSecondary),
        ),
      ),
      backgroundColor: brightness ? AppColors.colorWhite.withOpacity(
          0.70) : AppColors.colorBlack.withOpacity(
          0.70), // this is the main reason of transparency at next screen. I am ignoring rest implementation but what i have achieved is you can see.
    );
  }
}

Then do something like this

Scaffold(
 body: isLoading
          ? ProgressDialogPrimary()
          : Column(children: <Widget>[
...
]

Output:

enter image description here

Ravinder Kumar
  • 7,407
  • 3
  • 28
  • 54
  • I changed the code too: backgroundColor: brightness ? Colors.white.withOpacity(0.70) : Colors.black.withOpacity( – Golden Lion Oct 08 '21 at 14:06
  • the components work nicely. I replaced my overlay code because the debug complained it was outside the framework – Golden Lion Oct 08 '21 at 14:21
1

This works. Just tested on Dartpad:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: loading == false ? Text("loaded") : Container(
          constraints: BoxConstraints.expand(),
          child: CircularProgressIndicator()
        )
      )
    );
  }
Gazihan Alankus
  • 11,256
  • 7
  • 46
  • 57