【问题标题】:How to center text in container?如何在容器中居中文本?
【发布时间】:2020-03-09 09:59:22
【问题描述】:

我编写的代码将文本放在容器中第一行的中心,我需要它位于整个正方形(中线)的中心。

Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      textFormfield1('name', Controller),
      Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Text('Add at 3 images',
                textAlign: TextAlign.start,
                style: TextStyle(
                    //color: Colors.grey[400],
                    fontWeight: FontWeight.bold,
                    fontSize: 16))
          ]),
      Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Container(
          child: Text(text,        
          textAlign: TextAlign.center),
          width: 100,
          height: 100,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            border: Border.all(color: Colors.yellow)));
          )
),

发生了什么以及我需要什么的图片:https://imgur.com/a/FWdjPYX

【问题讨论】:

标签: flutter


【解决方案1】:

使用 Container 小部件的对齐属性,例如 - alignment: Alignment.center,

【讨论】:

    【解决方案2】:

    将您的Text 小部件包装在Center 小部件中。

    Center(
     child: Text('Your text')
    );
    

    【讨论】:

      【解决方案3】:

      您应该用Center 小部件包装您的Text

      Center(
       child: Text('Your text')
      );
      

      所以在你的上下文中

      Container(
       child: Center(
        child: Text('Your text')
       )
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-04
        • 1970-01-01
        • 2014-01-13
        • 2017-03-05
        • 2019-02-11
        • 2012-12-04
        相关资源
        最近更新 更多