enter image description here

这是我的容器.我想将复制按钮向右移动.我该怎么办? 这是我的代码.

Container(
            child: Row(
              children: [
                const SizedBox(
                  width: 10,
                ),
                Flexible(
                  child: Text(
                      "",
                  ),
                ),
                  child: IconButton(
                    onPressed: setClipboard,
                    icon: const Icon(
                      Icons.copy,
                    ),
                  ),
                const SizedBox(
                  width: 15,
                ),
              ],
            ),
          ),

我跳过了容器的装饰.

推荐答案

您只需强制文本分配行的剩余空间:通过设置fit: FlexFit.tight,使灵活小部件等于Expanded小部件

Container(
        padding: EdgeInsets.symmetric(horizontal: 15),
        child: Row(children: [
          Flexible(
            fit: FlexFit.tight,
            child: Text(
              "",
            ),
          ),
          IconButton(
            onPressed: () {},
            icon: const Icon(
              Icons.copy,
            ),
          ),
        ]),
      )

注:SizedBox已被填充取代.

或者,您可以在文本和图标按钮之间放置间隔符:

  Text(
            "",
          ),
          Spacer(),
          IconButton(
            onPressed: () {},
            icon: const Icon(
              Icons.copy,
            ),
          ),

或将Row的mainAxisAlignment设置为spaceBetween.

 Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
          Text(
            "",
          ),
         
          IconButton(
            onPressed: () {},
            icon: const Icon(
              Icons.copy,
            ),
          ),
        ]),

希望对你有帮助.

Flutter相关问答推荐

如何更改ElevatedButton的 colored颜色 以按下它?

如何创建一个按钮来在Ffltter Webview中转到上一页?

Dexing时出错.将Flutter 升级到3.19.0后

更改BottomNavigationBar onTap?的大小

Flutter BLoC et workmanager:如何创建独特的仓库初始化模式?

如何在用Ffltter成功登录后重定向下一页?

如何从DART中的事件列表中获取即将到来的日期

如何使排内 children 的身高与其他排内 children 的身高相适应?

如何在Flutter 安全存储器中存储对象值?

在Flutter 中创建自定义形状

当我转到其他屏幕并按下后退按钮时,屏幕将不会刷新

当键盘隐藏表单时该怎么办?

点击后,将按钮的 colored颜色 禁用/更改一段时间

获取通过列表呈现的相同 TextEditingController 的值

我可以在列表图块下方添加其他小部件吗

什么最接近 Dart 的 List.asMap().forEach() 返回列表?

从子集合sem中获取参考学年&&课程名称的值

Pub get 尚未运行

如何将变量翻译成其他语言

try 为两个下拉值添加共享首选项,但在 Flutter 上显示错误断言失败:?