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

Align Text Widgets In Custom List Tile Vertically In Flutter

I am supporting an app for landscape mode in which I want to align Text widgets in my custom List Tile(a container widget), but for some reason the alignment does not match and I get the following output
unaccepted

The out put I want is as follows

accepted
I use the following code to display the first output.

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

  Container buildTile(Employee employee) {
    return Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(25),
            border: Border.all(color: Colors.black, width: 1),
            boxShadow: [
              //BoxShadow
              BoxShadow(
                color: Colors.white,
                offset: const Offset(0.0, 0.0),
                blurRadius: 0.0,
                spreadRadius: 0.0,
              ),
            ]),
        width: MediaQuery.of(context).size.width * 0.7,
        height: MediaQuery.of(context).size.height * 0.1,
        margin: EdgeInsets.only(top: 10),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              child: Column(
                mainAxisSize: MainAxisSize.min,
  
                children: [
                  Text("ID:${employee.employeeId}",
                      style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 24)),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text("Mobile Number:",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 20)),
                      Text("${employee.employeePhone}",
                          style: TextStyle(
                              fontWeight: FontWeight.normal, fontSize: 20))
                    ],
                  ),
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(
                  left: MediaQuery.of(context).size.height * 0.25),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text("Name:",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 24)),
                      Text("${employee.employeeName}",
                          style: TextStyle(
                              fontWeight: FontWeight.normal, fontSize: 24))
                    ],
                  ),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text("Weekly Off:",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 20)),
                      Text("${employee.employeeWeeklyOff}",
                          style: TextStyle(
                              fontWeight: FontWeight.normal, fontSize: 20))
                    ],
                  ),
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(
                  left: MediaQuery.of(context).size.width * 0.10),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    "${employee.employeeRole}",
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: 24,
                    ),
                  ),
                  Text("    ")
                ],
              ),
            ),
          ],
        ));
  }

I tried wrapping the column in alignment widget but that didn’t work. When I try to add margin/padding the entire tile contents are shifted.
Please help

>Solution :

In each column set crossAxisAlignment to start like this:

Column(
                crossAxisAlignment: CrossAxisAlignment.start, // <-- add this
                mainAxisSize: MainAxisSize.min,
  
                children: [
                  Text("ID:${employee.employeeId}",
                      style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 24)),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text("Mobile Number:",
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 20)),
                      Text("${employee.employeePhone}",
                          style: TextStyle(
                              fontWeight: FontWeight.normal, fontSize: 20))
                    ],
                  ),
                ],
              )
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