右对齐而不调整父级大小

时间:2018-09-03 00:41:43

标签: dart flutter

我试图在不调整父对象大小的情况下将其对齐。因此从技术上讲,框的大小应取决于文本对象,并且图标应向右对齐。

return new Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
      new Text("this is a test string"),
      new Align(
        alignment: Alignment.topRight,
        child: new Icon(Icons.speaker_notes),
      ),
    ]);

将路线设置为Alignment.topRight后,将以全屏宽度绘制框。我知道为什么会这样渲染,但也无法想到解决方案。有什么想法吗?

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情:

  @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(),
        body: Align(
          alignment: Alignment.topLeft,
          child: new Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                new Text("this is a test string"),
                new Icon(Icons.speaker_notes),
              ]),
        ),
      );
    }

结果

enter image description here