Flutter MaterialApp Title

Flutter

前言

MaterialApp 有一个Title属性,一开始以为是ActionBar的title,后来发现不是。查看源码的时候,注释解释说在Android端是多任务状态下的title。

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: 'MaterialApp Title',
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

如下图:

MIUI 多任务.png

源码

  • Android
    在Android上,标题出现在任务管理器的应用程序快照上方,当用户按下“最近的应用程序”按钮时会显示。

  • iOS
    在iOS上,此值设置无效。应用程序使用的还是 Info.plist 中的 CbundleDisplayName,或者 CFBundleName

  • Web
    在web上,它用作页面标题,显示在浏览器的打开选项卡列表中。

  # material/app.dart

  /// {@macro flutter.widgets.widgetsApp.title}
  ///
  /// This value is passed unmodified to [WidgetsApp.title].
  final String title;

===================================================================

  # widgets/app.dart

  /// {@template flutter.widgets.widgetsApp.title}
  /// A one-line description used by the device to identify the app for the user.
  ///
  /// On Android the titles appear above the task manager's app snapshots which are
  /// displayed when the user presses the "recent apps" button. On iOS this
  /// value cannot be used. `CFBundleDisplayName` from the app's `Info.plist` is
  /// referred to instead whenever present, `CFBundleName` otherwise.
  /// On the web it is used as the page title, which shows up in the browser's list of open tabs.
  ///
  /// To provide a localized title instead, use [onGenerateTitle].
  /// {@endtemplate}
  final String title;


#参考
https://api.flutter.dev/flutter/material/MaterialApp/title.html

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>