![](/img/trans.png)
[英]How to add asset image in app bar as an action icon in Flutter application?
[英]How to implement app bar action text instead of action icon in Flutter?
我正在嘗試在顫振應用程序中實現 appbar。 我可以添加關閉應用程序的操作圖標。 我願意在關閉操作圖標旁邊顯示用戶名。 我嘗試在 appar 部分的 action 小部件數組中添加 new Text() 。 但無法對齊。 有沒有辦法直接添加動作文本?
代碼:
@override
Widget build(BuildContext context) {
//build a form widget using the form key we created above
return new Scaffold(
appBar: new AppBar(
title: new Text(StringRef.appName),
actions: <Widget>[
new Container(),
new Text(
userName,
textScaleFactor: 1.5,
style: new TextStyle(
fontSize: 12.0,
color: Colors.white,
),
),
new IconButton(
icon: new Icon(Icons.close),
tooltip: 'Closes application',
onPressed: () => exit(0),
),
],
),
}
將您的 Text 小部件包裹在 Center 小部件中
new Center(
new Text(
userName,
textScaleFactor: 1.5,
style: new TextStyle(
fontSize: 12.0,
color: Colors.white,
),
),
)
您還可以將Text
小部件包裹在Align
小部件內並進行alignment: Alignment.center
如下所示
Align(
alignment: Alignment.center,
child: Text(
"Save",
textScaleFactor: 1.5,
style: TextStyle(
fontSize: 12.0,
color: Colors.white,
),
),
)
你也可以通過使用TextButton
來實現這TextButton
TextButton(
onPressed: () {},
child: Text('Save', style: TextStyle(color: Colors.white),),
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.