Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing text in the center of a CircularProgressIndicator

I'm trying to place a text countdown timer in the center of a CircularProgressIndicator. This is the code for the layout of the body:

return new Column(
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  children: <Widget>[
    Stack(
      children: <Widget>[
        Container(
          width: 200,
          height: 200,
          child: new CircularProgressIndicator(
            strokeWidth: 15,
            value: value,
          ),
        ),
        Align(
          alignment: FractionalOffset.center,
          child: Text("Test")
        )
      ],
    ),
    ...
  ],
);

Adding the Align() widget changes the layout from this: Before

to this: After

I've also tried

Align(
  alignment: Alignment.center,
  child: Text("Test")
)

and

Center(
  child: Text("Test"),
)

instead of the Align() widget, but they all produce the same result

like image 301
Kornel Avatar asked Dec 10 '18 17:12

Kornel


People also ask

How do you make a progress indicator in flutter?

Determinate. Determinate progress indicators have a specific value at each point in time, and the value should increase monotonically from 0.0 to 1.0, at which time the indicator is complete. To create a determinate progress indicator, use a non-null value between 0.0 and 1.0.


1 Answers

That's because your Stack doesn't have size, so to fix your issue, wrap your Stack inside SizedBox, set a height, and Center the Text.

    Column(
                children: <Widget>[
                  SizedBox(
                    height: 200.0,
                    child: Stack(
                      children: <Widget>[
                        Center(
                          child: Container(
                            width: 200,
                            height: 200,
                            child: new CircularProgressIndicator(
                              strokeWidth: 15,
                              value: 1.0,
                            ),
                          ),
                        ),
                        Center(child: Text("Test")),
                      ],
                    ),
                  ),
                ],
              )
like image 65
diegoveloper Avatar answered Oct 22 '22 11:10

diegoveloper