如何在appBar中添加一个图标? - 颤振
How to add an icon inside the appBar? - Flutter
我想在 应用标题 my app name
旁边添加一个 icon
(图标必须 右边).
这是应用栏:
appBar: AppBar(
title: Text(
'my app name',
style: TextStyle(
fontFamily: 'OpenSansBold',
fontSize: 26.0,
),
),
),
它不一定是可点击的图标,它只是应用程序的徽标。
试试这个:
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。
我想在 应用标题 my app name
旁边添加一个 icon
(图标必须 右边).
这是应用栏:
appBar: AppBar(
title: Text(
'my app name',
style: TextStyle(
fontFamily: 'OpenSansBold',
fontSize: 26.0,
),
),
),
它不一定是可点击的图标,它只是应用程序的徽标。
试试这个:
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。