[英]How to align the icon left and text middle in a Raised button in flutter?
[英]Button with icon and text position left
我使用 flutter 做帶有圖標的RaisedButton
以及我想要將 position 更改為左側的圖標和文本。 怎么做? 這是我的按鈕代碼。
我想像圖片中那樣做:
Card(
child: SizedBox(
width: double.infinity,
height: 60,
child: RaisedButton.icon(
icon: Icon(Icons.home,
size: 40, color: Theme.of(context).primaryColor),
color: Colors.white,
textColor: Theme.of(context).primaryColor,
label: const Text('Electrical and Wiring',
style: TextStyle(
fontWeight: FontWeight.normal, fontSize: 15)),
onPressed: () => {},
),
),
),
在 Raised Button 小部件中,您可以將Row()
或Column()
作為child
,因此可以像這樣輕松完成,
RaisedButton(
child: Row(
children: <Widget>[
Icon(Icons.call),
Text('Your Text'),
],
),
onPressed: (){
//Actions
}),
您可以使用RaisedButton.icon()
小部件來實現這一點。
您可以從文檔中獲得更多信息。
這是給你的一個最小的例子..
RaisedButton.icon(onPressed: null, icon: null, label: null);
嘗試這個
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {},
child: Card(
child: SizedBox(
width: double.infinity,
height: 60,
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Icon(Icons.home,
size: 40, color: Theme.of(context).primaryColor),
),
Text('Electrical and Wiring',
style: TextStyle(
fontWeight: FontWeight.normal, fontSize: 15)),
],
)),
),
),
您可以做什么,您可以使用帶有TextButton.icon()
的 flutter 中的方向性小部件。 這是代碼。
Directionality(
textDirection: TextDirection.rtl,
child: TextButton.icon(
onPressed: null,
icon: Icon(
CupertinoIcons.ellipsis_circle_fill,
color: Colors.green,
),
label: Text(
"Business Name",
style: Theme.of(context).textTheme.subtitle1,
),
),
),
這是視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.