我使用SearchDelegate的Material来实现SearchAppBar,并使用this question的响应来更改搜索委托的提示文本默认值。
但是,我遇到的问题是无法在搜索字段中更改提示文本的字体样式,该提示样式如下图所示:
我已经有了要实现的样式,并且正在我的应用程序的另一种字体中使用此样式,但是我也想将此样式应用于此提示文本,以免与应用程序的样式指南冲突。
我用于更改搜索代表默认消息的代码:
class SearchRoomAppBar extends SearchDelegate {
SearchRoomAppBar() : super(
searchFieldLabel: "Search user",
keyboardType: TextInputType.text,
textInputAction: TextInputAction.search,
);
}
答案 0 :(得分:0)
您可以覆盖SearchDelegate appBarTheme 方法:
@override
ThemeData appBarTheme(BuildContext context) {
assert(context != null);
final ThemeData theme = Theme.of(context);
assert(theme != null);
return theme;
}
https://dartpad.dartlang.org/69724799fd6653ea4cf650a5a758c3d1
答案 1 :(得分:0)
SearchDelegate
应用栏文本的样式设置为ThemeData.textTheme.headline6
。
默认情况下,SearchDelegate
使用应用程序的ThemeData
,但是您可以覆盖ThemeData appBarTheme(BuildContext context)
方法以返回自定义版本。
@override
ThemeData appBarTheme(BuildContext context) {
// You can use Theme.of(context) directly too
var superThemeData = super.appBarTheme(context);
return superThemeData.copyWith(
textTheme: superThemeData.textTheme.copyWith(
headline6: /* Whatever style you want to apply to your text */,
),
);
}