android - 如何在appBar中添加一个图标? - flutter

标签 android flutter dart mobile

我想添加一个 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。结果如下: enter image description here


更新 如果你想添加 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/

相关文章:

android - Flutter-来自Firebase的readData()导致该方法在null上被调用

ios - 角 Dart : Route links in Safari on iOS 7 stop working

flutter - 如何在应用启动时初始化变量?

java - 用于序列化 List<String> 中的 List<User> 的自定义序列化程序

android - 如何格式化日期?

android - flutter :引发了另一个异常:类型 'Future<dynamic>' 不是类型 'String' 的子类型

sqlite - Firestore集合(带有子集合)到Flutter中的Sqflite元素

Android保存BLE设备以在应用关闭后重新连接

android 和 ios 应用订阅 checkin react 原生

android - Firebase 动态链接与 flutter : Deep link URL doesnt open app