Flutter — как изменить название приложения и лаунчера на разных платформах

Опубликовано: 7 Января, 2023

Иногда вы замечаете, что нам приходится менять заголовок приложения в приложениях для Android и iOS, а также заголовок для флаттер-веб во время или после загрузки. Итак, в этой статье мы рассмотрим все места, где нам нужно изменить название приложения на разных платформах.

1. Название приложения для Android

Измените имя метки Android в

Путь к файлу : android/app/src/main/AndroidManifest.xml

Dart




<application
  android:label="Your android app title"
  android:name="${applicationName}"
  android:icon="@mipmap/ic_launcher">

2. Когда приложение работает в фоновом режиме и еще не убито

  • На Android: используется в недавних приложениях
  • На iOS: используется в переключателе приложений
  • Он используется на вкладках браузера, которые соответствуют свойству title веб-приложения.

Путь к файлу: lib/main.dart

Dart




class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "App Title",
      theme: ThemeData(
        scaffoldBackgroundColor: Color(0xFFDEE9F9),
        textTheme: TextTheme(
          headline3: TextStyle(
            color: Colors.black,
            fontSize: 20,
            fontWeight: FontWeight.w600,
          ),
        ),
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You"ll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn"t reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      initialRoute: home,
      routes: {
        checkBox: (context) => const GradientCheckBox(),
        home: (context) => const Home(),
      },
    );
  }
}

3. Название приложения для iOS

Путь к файлу: ios>Runner/info.plist

<key>CFBundleName</key>
<string>Your iOS App Title</string>

Dart




<key>CFBundleDisplayName</key>
<string>Your iOS App Title</string>

4. Заголовок появляется при загрузке веб-приложения (Flutter web).

Путь к файлу: web/index.html

Dart




<meta name="apple-mobile-web-app-title" content="your web app title">
<title>your web app title</title>

Вы также можете изменить эти два описания в веб-флаттере, чтобы улучшить SEO.

Путь к файлу: web/index.html

Dart




<meta name="description" content="Your App Description">

Путь к файлу: pubspec.yaml

Dart




name: Your App Title
description: Your App Description
  
publish_to: "none" 
  
version: 1.0.0+1
  
environment:
  sdk: ">=2.16.2 <3.0.0"