You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何在system_alert_window实现两端对齐(spaceBetween)?

实现system_alert_window弹窗同一行文本左右对齐

要实现同一行内一个文本左对齐、另一个右对齐的效果,你可以通过在EachRow中添加两个EachColumn组件,并分别设置它们的gravity属性来实现,具体修改如下:

SystemWindowBody body = SystemWindowBody(
  rows: [
    EachRow(
      columns: [
        // 左对齐文本列
        EachColumn(
          text: SystemWindowText(text: "Some body", fontSize: 12, textColor: Colors.black45),
          gravity: ContentGravity.LEFT,
        ),
        // 右对齐文本列
        EachColumn(
          text: SystemWindowText(text: "右对齐内容", fontSize: 12, textColor: Colors.black45),
          gravity: ContentGravity.RIGHT,
        ),
      ],
      gravity: ContentGravity.CENTER,
      weight: 1, // 让行占满弹窗可用宽度,确保对齐效果生效
    ),
  ],
  padding: SystemWindowPadding(left: 16, right: 16, bottom: 12, top: 12),
);

关键说明:

  • 给每个EachColumn单独设置gravity:第一个列用ContentGravity.LEFT实现左对齐,第二个列用ContentGravity.RIGHT实现右对齐
  • 为EachRow添加weight: 1,确保该行占据弹窗的全部水平宽度,这样左右对齐的效果才能完整呈现
  • 保持EachRow的gravity为ContentGravity.CENTER,让两个列在水平方向上合理分配空间,达到类似spaceBetween的布局效果

内容的提问来源于stack exchange,提问作者Anandh Krishnan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 11:57:53