如何在Flutter中将文本垂直和水平居中? [英] How do I center text vertically and horizontally in Flutter?

查看:4691
本文介绍了如何在Flutter中将文本垂直和水平居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Flutter中将文本窗口小部件的内容垂直和水平居中。
我只知道如何使用 Center(child:Text( test))来使小部件本身居中,而不是内容本身,默认情况下它保持左对齐。在Android中,我相信实现此目的的TextView的属性称为 gravity

I'd like to know how to center the contents a Text widget vertically and horizontally in Flutter. I only know how to center the widget itself using Center(child: Text("test")) but not the content itself, it's by default left aligned. In Android, I believe the property of a TextView that achieves this is called gravity.

我想要的示例:

推荐答案

文本对齐中心属性仅设置水平对齐。

Text alignment center property setting only horizontal alignment.

我在下面的代码中使用了垂直设置文本和

I used below code to set text vertically and horizontally center.

代码:

      child: Center(
        child: Text(
          "Hello World",
          textAlign: TextAlign.center,
        ),
      ),

这篇关于如何在Flutter中将文本垂直和水平居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆