如何在 Flutter 中将 TextButton 的图标右对齐?

Erk*_*urt 2 flutter

使用此示例代码,TextButton 小部件可以在左侧呈现图标。

TextButton.icon(
  onPressed: onPressed,
  icon: Icon(
    Icons.arrowOpen,
    color: companySelectionColor,
  ),
  label: text,
),
Run Code Online (Sandbox Code Playgroud)

不过,我想使用完全相同的小部件,但在右侧呈现图标。有什么办法可以让这个图标显示在右侧吗?

以下是所需输出的示例: 在此输入图像描述

Erk*_*urt 6

您可以用 widget 包裹Directionalitywidget。该小部件可以将给定的文本方向应用于子小部件。使用文本按钮可以执行以下操作:

Directionality(
  textDirection: TextDirection.rtl,
  child: TextButton.icon(
    onPressed: onPressed,
    icon: Icon(
      Icons.arrowOpen,
       color: companySelectionColor,
    ),
    label: text,
  ),
);
Run Code Online (Sandbox Code Playgroud)

编辑:您还需要使用 TextDirection.ltr 来换行文本。再想一想,这有很多。只需通过使用文本和图标实现行/墨水池来创建自定义文本按钮