如何在Flutter中将小部件与动态居中小部件的右侧对齐?

我在中心有一个具有动态宽度的文本小部件。但是,我想在此文本窗口小部件的右侧添加一个窗口小部件。

由于此中心文本小环具有动态宽度,因此无法使用绝对定位小部件,例如“对齐”或“位置小部件”。我正在寻找类似于Android中的RelativeLayout的东西。

如何在Flutter中将小部件与动态居中小部件的右侧对齐?

  Widget body() {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
          Text('Center text'),flatButton(
            child: Text('next'),onpressed: () {},),],);
  }

使用@Igors方法,我可以以一个中心小部件结尾,每个小部件上的按钮均等分布。我的目标是该按钮位于右侧。

  Widget body() {
    return Container(
      child: Row(
        children: <Widget>[
          Expanded(
            child: flatButton(
              child: Text('next'),Container(color: Colors.red,child: Text('test')),Expanded(
            child: flatButton(
              child: Text('next'),);
  }

编辑:通过在居中小部件1的每一侧上使用“调整大小的框”来解决。

beixiaonuan 回答:如何在Flutter中将小部件与动态居中小部件的右侧对齐?

Row(
  children: <Widget>[
    Expanded(
      child: Container(
        color: Colors.green
      ),),Container(
      color: Colors.red,child: Text('test')
    ),Expanded(
      child: Container(
        color: Colors.blue
      ),],)
,

使用小部件行,并将文本小部件添加到容器小部件中。

并为容器增加边距

本文链接:https://www.f2er.com/3154773.html

大家都在问