首页 > 解决方案 > 如何在列中对齐 TextFields,例如 Text()?

问题描述

我正在尝试绘制一个对话框/弹出窗口,当用户点击谷歌地图中的标记时会显示。

问题是文本字段在对话框中没有对齐。你可以在下面的图片中看到它:

所以,我想知道如何对齐文本,以便每个新文本都从垂直的一行开始。

看看时间,和一天的领先

这是我的代码:

child: Material(
    color: Colors.transparent,
    child: ScaleTransition(
      scale: scaleAnimation,
      child: Container(
        decoration: ShapeDecoration(
            color: Colors.blueGrey[900],
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(15.0))),
        child: Padding(
          padding: const EdgeInsets.fromLTRB(40, 20, 40, 15),
          child: Container(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Container(
                  child: Text(
                    'Stackoverflow Restaurant',
                    style: new TextStyle(
                        fontSize: 20.0,
                        color: textColorPopup,
                        fontWeight: FontWeight.bold),
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
                  child: Text(
                    'Open hours',
                    style: new TextStyle(
                        fontSize: fontSizeWeekDays, color: textColorPopup),
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text(
                        'MON',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                      SizedBox(
                        width: 30.0,
                      ),
                      Text(
                        '15.00 - 03.00',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text(
                        'TUE',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                      SizedBox(
                        width: 30.0,
                      ),
                      Text(
                        '15.00 - 03.00',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text(
                        'WEN',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                      SizedBox(
                        width: 30.0,
                      ),
                      Text(
                        '15.00 - 03.00',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text(
                        'THU',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                      SizedBox(
                        width: 30.0,
                      ),
                      Text(
                        '15.00 - 03.00',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text(
                        'FRI',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                      SizedBox(
                        width: 30.0,
                      ),
                      Text(
                        '15.00 - 03.00',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text(
                        'SAT',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                      SizedBox(
                        width: 30.0,
                      ),
                      Text(
                        '15.00 - 03.00',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(0, 5, 0, 30),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text(
                        'SUN',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                      SizedBox(
                        width: 30.0,
                      ),
                      Text(
                        '15.00 - 03.00',
                        style: new TextStyle(
                            fontSize: fontSizeOpenHours,
                            color: textColorPopup),
                      ),
                    ],
                  ),
                ),
                RaisedButton(
                  padding: EdgeInsets.fromLTRB(60, 0, 60, 0),
                  color: Colors.white,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(20.0),
                  ),
                  onPressed: _dismissAlertDialog,
                  child: Text(
                    'CLOSE',
                    style: TextStyle(
                        fontSize: 18,
                        color: Colors.black,
                        fontStyle: FontStyle.normal),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  ),

标签: flutterdart

解决方案


在每一行上使用 mainAxisAlignment: MainAxisAlignment.spaceBetween ,Days 将左对齐,Times 将右对齐。


推荐阅读