如何更改Flutter应用程序在手机屏幕上的显示名称?

13

如何更改在手机上显示的Flutter项目的应用程序名称? 我检查了pubspec.yaml文件

name: flutter_app
description: A new Flutter application.

修改了名称属性,但导入的包引用也会被更改,是否仅更改应用程序名称?

2个回答

39

Android

打开AndroidManifest.xml文件,按照以下步骤进行修改

<application
    android:label="App Name" ...> // Your app name here

iOS

打开info.plist文件,进行以下更改

<key>CFBundleName</key>
<string>App Name</string> // Your app name here

1
这些是本地方法来完成的。我想知道Flutter是否从单一点处理它? - Pankaj Bansal
@PankajBansal 你的意思是想要动态更改名称吗? - CopsOnRoad
@CopsOnRoad 不,我想知道是否有一个通用的地方可以为iOS和Android提供应用程序名称和图标,因为我知道它们在iOS(Plist)和Android(Manifest)上是不同的。 - Pankaj Bansal
2
@PankajBansal 很抱歉,目前没有其他方法,您需要在info.plistAndroidManifest.xml中进行操作。 - CopsOnRoad
对于iOS来说,仅更新CFBundleName的值是不够的。我还必须更新CFBundleDisplayName的值。我的应用程序Flutter版本为2.10.3。 - Scorpionk

4
要更改您的应用程序名称,您需要在Android和IOS上进行更改:
您可以使用rename软件包使其变得容易。
只需在Flutter项目根目录中运行此命令即可。
pub global run rename --appname "My application"

或者

编辑AndroidManifest.xml(Android)和info.plist(iOS)

对于Android,请仅在文件AndroidManifest.xml中的application标签中编辑android:label的值,该文件位于文件夹:android/app/src/main中。

代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Your Application Name"  //here
        android:icon="@mipmap/ic_launcher">
        <activity>
        <!--  -->
        </activity>
    </application>
</manifest>

截图:

Enter image description here

对于 iOS,只需在位于文件夹 ios/Runner 中的 Info.plist 文件中编辑 String 标签内的值。

代码:

<plist version="1.0">
<dict>
    <key>CFBundleName</key>
    <string>Your Application Name </string>  //here
</dict>
</plist>

屏幕截图:

Enter image description here

如果你遇到问题,请执行 flutter clean 命令并重新启动应用程序。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接