将 ElevatedButton.icon 的图标放置在右侧

Kav*_*she 5 dart flutter flutter-layout

我有一个带有图标的提升按钮,该图标使用 放置在文本左侧ElevatedButton.icon。我真正想要的是将图标放置在文本的右侧。我该如何做我的代码:

    ElevatedButton.icon(
        onPressed: onPressed,
        icon:Icon(icon,
          color: color != null ? color : null,
          size: getIconSize(),
        ),
        label: Text(label),
        style: buttonStyle);
Run Code Online (Sandbox Code Playgroud)

外观如何:

在此输入图像描述

我想要的是 :

下一页->

s.a*_*m.i 26

使用 Directionality小部件。做出方向rtl

Directionality(
      textDirection: TextDirection.rtl,
      child: ElevatedButton.icon(
        onPressed: () {},
        icon: Icon(
          Icons.arrow_back,
        ),
        label: Text("Test"),
     //.........
      ))
Run Code Online (Sandbox Code Playgroud)

现在,您只需添加您的风格

在此输入图像描述


cro*_*x5f 6

您可以只使用常规ElevatedButton构造函数并传入 Row 作为其子项,并带有图标和文本:

 ElevatedButton(
        onPressed: onPressed,
        style: buttonStyle,
        child: Row(mainAxisSize:MainAxisSize.min,
children:
[Text(label),
SizedBox.square(dimension: 4),
Icon(icon,color: color != null ? color : null,size: getIconSize()),
]),)
Run Code Online (Sandbox Code Playgroud)

结果示例