Flutter MaterialApp Title

Flutter

本文:https://blog.csdn.net/CrazyApes/article/details/121748192

前言

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容