[英]How to align TextButton's icon to right in Flutter?
With this sample code TextButton widget can be rendered with icon on the left side.使用此示例代码,TextButton 小部件可以在左侧呈现为带有图标。
TextButton.icon(
onPressed: onPressed,
icon: Icon(
Icons.arrowOpen,
color: companySelectionColor,
),
label: text,
),
However I want to use exact same widget but render the icon on the right side.但是我想使用完全相同的小部件,但在右侧呈现图标。 Is there any way to render this icon on the right side?有没有办法在右侧呈现这个图标?
I think as per documentation here<\/a> and as per my knowledge Icon is not right side position but you use using Directionality()<\/strong> widget its solved Just you use ElevetedBtton.icon<\/strong> instead of TextButton.icon<\/strong> and its working correctly and you use Directionality()<\/strong> widget refer below code hope its help to you.我认为根据此处<\/a>的文档和我的知识,图标不是右侧位置,但您使用Directionality()<\/strong>小部件已解决只需您使用ElevetedBtton.icon<\/strong>而不是TextButton.icon<\/strong>并且它工作正常并且您使用Directionality()<\/strong>小部件参考下面的代码希望对您有所帮助。
<\/blockquote>Directionality( textDirection: TextDirection.rtl, child: ElevatedButton.icon( onPressed: () {}, icon: Icon( Icons.add, color: Colors.white, ), label: Text( "Pressed", style: TextStyle(color: Colors.white), ), ), ),<\/code><\/pre>
Use TextButton.icon使用 TextButton.icon
<\/blockquote>TextButton.icon( onPressed: () {}, label: Text('Pressed'), icon: Icon( Icons.add, color: Colors.red, ), ),<\/code><\/pre>
Use TextButton.icon using Directionality()<\/strong> widget通过Directionality()<\/strong>小部件使用 TextButton.icon
<\/blockquote>Directionality( textDirection: TextDirection.rtl, child: TextButton.icon( onPressed: null, icon: Icon( Icons.add, color: Colors.red, ), label: Text( 'Pressed', style: TextStyle( letterSpacing: .5, fontSize: 22, fontWeight: FontWeight.bold, color: Colors.blue, ), ), ), ),<\/code><\/pre>
Your screen using ElevetedBtton.icon Widget like ->您的屏幕使用 ElevetedBtton.icon 小部件,例如 -> <\/a>
Your screen using TextButton.icon Widget like ->您的屏幕使用 TextButton.icon 小部件,例如 -> <\/a>
Your screen using TextButton.icon Widget using Directionality() like ->您的屏幕使用 TextButton.icon 使用 Directionality() 的小部件,例如 -> <\/a>
"
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),
),
),
)
You can wrap the widget with Directionality<\/code> widget.
您可以使用
Directionality<\/code>小部件包装小部件。
This widget can apply the given text direction to child widgets.此小部件可以将给定的文本方向应用于子小部件。 With text button one can do following:使用文本按钮可以执行以下操作:
Directionality(
textDirection: TextDirection.rtl,
child: TextButton.icon(
onPressed: onPressed,
icon: Icon(
Icons.arrowOpen,
color: companySelectionColor,
),
label: text,
),
);
You can try using IconButton<\/code> and add Text widget as a child alternatively.
您可以尝试使用
IconButton<\/code>并将 Text 小部件添加为子小部件。
IconButton(
icon: Icon(Icons.arrowOpen),
iconSize: 12,
onPressed: () {},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.