我想添加一个 icon
在 标题 my app name
的应用程序(图标必须是 在右边)。
这是应用栏:
appBar: AppBar(
title: Text(
'my app name',
style: TextStyle(
fontFamily: 'OpenSansBold',
fontSize: 26.0,
),
),
),
它不一定是可点击的图标,它只是应用程序的 Logo 。
最佳答案
试试这个:
appBar: AppBar(
title: Row(
mainAxisAlignment:MainAxisAlignment.center,
children:[
Text(
'my app name',
style: TextStyle(
fontFamily: 'OpenSansBold',
fontSize: 26.0,
),
),
Icon(
Icons.audiotrack,
color: Colors.green,
size: 30.0,
),
]
)
),
此外,您可以更改 mainAxisAlignment
以对齐这些项目或更改它们的顺序以在文本的开头或结尾显示 icon
。结果如下:
更新
如果你想添加 image
而不是 icon
,试试这个:
appBar: AppBar(
title: Row(
mainAxisAlignment:MainAxisAlignment.center,
children:[
Text(
'my app name',
style: TextStyle(
fontFamily: 'OpenSansBold',
fontSize: 26.0,
),
),
Image(image: AssetImage('your directory'));
]
)
),
请注意,首先,您应该将图像添加到 pubspec.yaml
文件的 asset
部分,如下所示:
flutter:
assets:
- Your directory
有关详细信息,请参阅 this .
关于android - 如何在appBar中添加一个图标? - flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69170286/