如何在Flutter的Row小部件中,在我的文本和图标之间放置一个空格?

huangapple go评论58阅读模式
英文:

How i can place a space between my text and a icon on Row widget in flutter

问题

需要做类似这样的事情,但我不知道我可以做什么。
当我尝试使用Align移动时,图标不会移动:

我尝试过这样:

Widget AreaProfil(){
  return Column(
      children: [
        Container(
            margin: const EdgeInsets.only(left: 10.0),
            padding: const EdgeInsets.only(top: 10.0, ),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(20),
            ),
            child: Card(
              child: Container(
                child: Row(
                children:  [
                  const Text(
                    "Mon Profil",
                    style: TextStyle(
                       fontSize: 20,
                       fontWeight: FontWeight.bold,
                    ),
                  ),
                  Align(
                    alignment: Alignment.centerRight,
                    child: Row(
                      children: const [
                        Icon(Icons.edit),
                     ],
                    ),
                  ),
                 ]
                )
               ),
        )
     )
  ]
  );
}

这个结果不起作用,所有图标都停留在左边。

英文:

I need to do something like this but I don't know what I can do.
When I try to move with Align, the icon doesn't move:

如何在Flutter的Row小部件中,在我的文本和图标之间放置一个空格?

I tried this:

Widget AreaProfil(){
  return Column(
      children: [
        Container(
            margin: const EdgeInsets.only(left: 10.0),
            padding: const EdgeInsets.only(top: 10.0, ),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(20),
            ),
            child: Card(
              child: Container(
                child: Row(
                children:  [
                  const Text(
                    "Mon Profil",
                    style: TextStyle(
                       fontSize: 20,
                       fontWeight: FontWeight.bold,
                    ),
                  ),
                  Align(
                    alignment: Alignment.centerRight,
                    child: Row(
                      children: const [
                        Icon(Icons.edit),
                     ],
                    ),
                  ),
                 ]
                )
               ),
        )
     )
  ]
  );
}

The result of this don't work and all the Icon rest on the left.

答案1

得分: 1

如果您想在多个小部件之间创建间隔,而MainAxisAlignment.spaceBetween不够用,您也可以使用SpacerExpanded来创建这样的间隔。

Widget AreaProfil(){
  return Column(
    children: [
      Container(
        margin: const EdgeInsets.only(left: 10.0),
        padding: const EdgeInsets.only(top: 10.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
        ),
        child: Card(
          child: Row(
            children:  [
              const Text(
                "Mon Profil",
                style: TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Spacer(),
              Icon(Icons.edit),
              Icon(Icons.edit),
            ],
          ),
        ),
      ),
    ],
  );
}

以上是您提供的代码的翻译部分。

英文:

If you want to have a gap between several widgets and MainAxisAlignment.spaceBetween is not enough for you, you can also use Spacer or Expanded to create such a gap.

Widget AreaProfil(){
 return Column(
  children: [
    Container(
        margin: const EdgeInsets.only(left: 10.0),
        padding: const EdgeInsets.only(top: 10.0, ),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
        ),
        child: Card(
          child: Row(
            children:  [
              const Text(
                "Mon Profil",
                style: TextStyle(
                   fontSize: 20,
                   fontWeight: FontWeight.bold,
                ),
              ),
              Spacer(),
              Icon(Icons.edit),
              Icon(Icons.edit),
              ),
             ],
           ),
    )
    )
  ]
);
}

答案2

得分: 0

  • 需要为父级组件指定宽度
  • 这是一个示例
Widget AreaProfil(BuildContext context) {
  var width = MediaQuery.of(context).size.width;
  return Column(children: [
    Container(
        width: width,
        margin: const EdgeInsets.only(left: 10.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
        ),
        child: Padding(
          padding: const EdgeInsets.only(
            top: 10.0,
          ),
          child: Card(
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                const Text(
                  "Mon Profil",
                  style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Row(
                  children: [
                    Align(
                      alignment: Alignment.centerRight,
                      child: Row(
                        children: const [
                          Icon(Icons.edit),
                        ],
                      ),
                    ),
                    Align(
                      alignment: Alignment.centerRight,
                      child: Row(
                        children: const [
                          Icon(Icons.edit),
                        ],
                      ),
                    )
                  ],
                )
              ])),
        ))
  ]);
}
英文:
  • Need to specify width for parent group
  • this is example
Widget AreaProfil(BuildContext context) {
  var width = MediaQuery.of(context).size.width;
  return Column(children: [
    Container(
        width: width,
        margin: const EdgeInsets.only(left: 10.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
        ),
        child: Padding(
          padding: const EdgeInsets.only(
            top: 10.0,
          ),
          child: Card(
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                const Text(
                  "Mon Profil",
                  style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Row(
                  children: [
                    Align(
                      alignment: Alignment.centerRight,
                      child: Row(
                        children: const [
                          Icon(Icons.edit),
                        ],
                      ),
                    ),
                    Align(
                      alignment: Alignment.centerRight,
                      child: Row(
                        children: const [
                          Icon(Icons.edit),
                        ],
                      ),
                    )
                  ],
                )
              ])),
        ))
  ]);
}

huangapple
  • 本文由 发表于 2023年1月8日 22:53:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048730.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定