Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't center column

I can’t center content inside the column widget. If width of the component is normal it’s centered, but when width is too much, or infinity it doesn’t center.
Here is my code example:

return Center(
  child: Column(
    crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
      children:[
        Row(
          children: [
            Row(
              children: [
                Text(
                  "Available:",
                  style: TextStyle(color: Colors.grey, fontSize: 17),
                ),
                SizedBox(width: 10),
                Text("\$ " + availableWithFormat.format(widget.available),
                    style: TextStyle(fontFamily: 'SF Pro DIsplay')),
              ],
            ),
          ],
        ),
        Row(
          children: [
            Row(children: [
              Text("\$ ",
                  style: TextStyle(
                      fontSize: 24, fontFamily: 'SF Pro DIsplay')),
              Flexible(
                fit: FlexFit.loose,
                  flex: 1,
                child: Column(
                  children: [
                    TextField(
                      controller: myController,
                      onChanged: (String value) async {
                        setState(() {
                          double input =
                              double.parse((value).replaceAll(",", ""));
                          finalCommission =
                              (input / 100) * widget.commission;
                        });
                      },
                      keyboardType: TextInputType.numberWithOptions(
                          signed: false, decimal: true),
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        constraints: BoxConstraints.tightFor(
                          width: 150,
                        ),
                        hintText: "0.00",
                      ),
                      style: TextStyle(
                          fontSize: 24, fontFamily: 'SF Pro DIsplay'),
                    ),
                  ],
                ),
              ),
            ]),
          ],
        ),
        Row(
          children: [
            Row(
              children: <Widget>[
                if (widget.commission != 0)
                  Text(
                    "Commission:",
                    style: TextStyle(
                        color: Colors.grey, fontFamily: 'SF Pro DIsplay'),
                  ),
                if (widget.commission != 0) SizedBox(width: 10),
                if (widget.commission != 0)
                  Text("\$ " + availableWithFormat.format(finalCommission),
                      style: TextStyle(fontFamily: 'SF Pro DIsplay')),
              ],
            ),
          ],
        ),
      ],
    ),
);

Where is the problem? And how can I solve it?
enter image description here

Here is the image, when I set too much width
enter image description here
This is image, when width is normal

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A solution to your problem is to set the alignment for each of your row

Row(
  crossAxisAlignment: CrossAxisAlignment.center,
  mainAxisAlignment: MainAxisAlignment.center,
  children: [...]
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading