Center Text in a Flutter Column

Viewed 46

I am looking for help in centering the "mytitle" text in a column.

I tried centerTitle: true, between 'mytitle' and 'overflow', but it did not work:

Card(
 child: Container(
  child: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
          Padding(
              child:
                Text(
                  mytitle,
                  overflow: TextOverflow.ellipsis,
                  style: CustomTheme.bodyText1.override(
                  fontFamily: 'Noto Sans',
                  fontSize: 24,
                  color: txtcolor),               
                )
            )
        ]
    )
  )
)
1 Answers

try to use crossAxisAlignment as follow:

Container(
alignment: Alignment.center,
Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
          Padding(
              child:
                Text(
                  mytitle,
                  textAlign: TextAlign.center,
                  overflow: TextOverflow.ellipsis,
                  style: CustomTheme.bodyText1.override(
                  fontFamily: 'Noto Sans',
                  fontSize: 24,
                  color: txtcolor),               
                )
            )
        ]
    )
)

for more information see this. In summary, you can set the layout of Column in two directions. The first one is the vertical axis (MainAxis) and the second one is the horizontal (crossAxis) direction. Row has the same feature but its mainAixs and crossAxis is opposite.

Related