簡體   English   中英

如何在 Flutter 中將 TextButton 的圖標右對齊?

[英]How to align TextButton's icon to right in Flutter?

使用此示例代碼,TextButton 小部件可以在左側呈現為帶有圖標。

TextButton.icon(
  onPressed: onPressed,
  icon: Icon(
    Icons.arrowOpen,
    color: companySelectionColor,
  ),
  label: text,
),

但是我想使用完全相同的小部件,但在右側呈現圖標。 有沒有辦法在右側呈現這個圖標?

以下是所需 output 的示例: 在此處輸入圖像描述

TextButton.icon(
      onPressed:null,
      icon: Text('2022-01-27'),
      label: Icon(Icons.arrow_drop_down_sharp),
    )
Directionality(
                        textDirection: TextDirection.rtl,
                        child: TextButton.icon(
                          onPressed: () {
                            Navigator.pushNamed(context, Routes.checkout);
                          },
                          icon: const Icon(IcoFontIcons.arrowRight),
                          label: const Text(
                            "Chekout",
                            style: TextStyle(color: Colors.blue),
                          ),
                        ),
                      )

您可以使用Directionality<\/code>小部件包裝小部件。 此小部件可以將給定的文本方向應用於子小部件。 使用文本按鈕可以執行以下操作:

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

您可以嘗試使用IconButton<\/code>並將 Text 小部件添加為子小部件。

IconButton(
   icon: Icon(Icons.arrowOpen),
   iconSize: 12,
   onPressed: () {},
),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM