Flutter 中的动态应用程序标题
app title可以使用SystemChrome.setApplicationSwitcherDescription
:
@override
Widget build(BuildContext context) {
SystemChrome.setApplicationSwitcherDescription(ApplicationSwitcherDescription(
标签: 'Dynamic web app title',
原色: Theme.of(context).原色.value,
));
return Container(...);
}
SystemChrome
和import 'package:flutter/services.dart';
一起使用,你想在103 method中拨打setApplicationSwitcherDescription
.
Title
也是这样做的(参见source code),这是WidgetsApp
、MaterialApp
等使用的小部件.
因此,您也可以使用Title
小部件,而不是自己访问SystemChrome
:
@override
Widget build(Context context) {
return Title(
标签: 'Dynamic app title',
原色: Theme.of(context).原色,
child: ..,
);
}
标签
标签
参数非常简单:它精确地映射到MaterialApp
中的title
和String
.
原色
The 原色
will determine the color the system might use in the application switcher, e.g. the title bar color in recents on Android.
This is an int
instead of a Color
, which is why you need to call Color.value
to convert your primary color to an integer.
Interference with other Title
s
You might ask yourself if calling setApplicationSwitcherDescription
or inserting a Title
widget when the title
property on MaterialApp
is set can cause any problems.
The answer is: no because the widget that is the deepest down in the tree will set the title. Essentially, even if the whole app rebuilds, your setApplicationSwitcherDescription
will be called after that of MaterialApp
assuming you are calling it in a child and therefore you will override the MaterialApp
title.