【问题标题】:Is this really how I have to position something on the right in Flutter?这真的是我必须在 Flutter 中将某些东西放在右侧的方式吗?
【发布时间】:2020-02-15 08:20:33
【问题描述】:

ColumncrossAxisAlignment: CrossAxisAlignment.start 内部,我想定位一个孩子向右浮动。

这是我的解决方案:

Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: <Widget>[
    [...]
    Container(
      height: 20.0,
      child: Row(
        children: <Widget>[
          Expanded(
            child: Stack(
              children: <Widget>[
                Positioned(
                  right: 10.0,
                  child: Text(
                    "Price - " + _event.price,
                     style: Styles.constratingTextStyle,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    ),
  ],
),

有没有更简洁的方法来做到这一点?这感觉很重。

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    Flutter - Align Widget

    您也可以使用Containeralignment 属性

    【讨论】:

      【解决方案2】:
       SizedBox.expand(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                Text("hello")
              ],
            ),
          )
      

      使用 crossAxisAlignment.end 并通过将列包裹在
      中扩展列子项的宽度 “SizedBox.expand”小部件

      【讨论】:

      • 感谢您的回答。我选择了另一个建议的解决方案,因为它节省了创建新列的时间。我的父列需要.startcrossAxisAligment。如果我要在右侧放置多个东西,这可能是我的首选。谢谢!
      • @louisdeb ,最欢迎的朋友......快乐的编码...... :)
      猜你喜欢
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 2016-11-14
      • 2021-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多