Fabrizio Beccaceci
Fabrizio Beccaceci

Reputation: 440

Can't align icon and text baseline

I'm trying to align an icon and a text with CrossAxisAlignment.baseline but I can't get it right.

What I want

enter image description here

What I get

enter image description here

This is my code:

Row(
  crossAxisAlignment: CrossAxisAlignment.baseline,
  textBaseline: TextBaseline.alphabetic,
  children: [
    Icon(Icons.cloud_outlined),
    Text(
      "Cloud",
      style: TextStyle(fontSize: 18),
    )
  ],
)

Upvotes: 5

Views: 1975

Answers (2)

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14885

You can used ListTile insted of Row

Using ListTile

 ListTile(
        leading: Icon(Icons.cloud_outlined),
        title: Text(
          "Cloud",
          style: TextStyle(fontSize: 18),
        ),
      ),

Using Row:

     Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: const [
            Icon(Icons.cloud_outlined),
            SizedBox(width: 10),
            Text(
              "Cloud",
              style: TextStyle(fontSize: 18),
            )
          ],
        ),

Result-> image

Upvotes: -1

Deepak Lohmod
Deepak Lohmod

Reputation: 2282

Simply change the cross axis alignment to end

Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                textBaseline: TextBaseline.alphabetic,
                children: [
                  Icon(Icons.cloud_outlined, size: 20),
                  SizedBox(width: 5),
                  Text(
                    "Cloud",
                    style: TextStyle(fontSize: 18),
                  )
                ],
              ),

Result:-

enter image description here

Upvotes: 2

Related Questions