【发布时间】:2019-10-10 04:13:10
【问题描述】:
我正在 Flutter 应用中使用 SearchDelegate 实现搜索栏。
我已覆盖 ThemeData appBarTheme(BuildContext context) 函数以返回我的主应用 ThemeData。
但是,这只会更改搜索视图,仅更改应用栏颜色。它不使用主题中定义的光标或提示颜色。
感谢任何建议。
【问题讨论】:
标签: search flutter cursor hint
我正在 Flutter 应用中使用 SearchDelegate 实现搜索栏。
我已覆盖 ThemeData appBarTheme(BuildContext context) 函数以返回我的主应用 ThemeData。
但是,这只会更改搜索视图,仅更改应用栏颜色。它不使用主题中定义的光标或提示颜色。
感谢任何建议。
【问题讨论】:
标签: search flutter cursor hint
您是否在 Apple 模拟器上运行您的应用程序?因为 cursorColor 似乎是平台相关的。 TextField 类的文档指出 cursorColor 字段
根据 [ThemeData.platform] 默认为 [ThemeData.cursorColor] 或 [CupertinoTheme.primaryColor]。
我必须创建一个 CupertinoThemeData 并将其传递给 main.dart 文件中我的应用程序的 ThemeData,如下所示:
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: appBarCursorColorTheme(context),
home: MyHomePage(); // MySearchDelegate contained inside MyHomePage()
);
}
ThemeData appBarCursorColorTheme(BuildContext context) {
final ThemeData theme = Theme.of(context);
CupertinoThemeData ctd =
CupertinoThemeData.raw(null, Colors.white, null, null, null, null);
return theme.copyWith(
cupertinoOverrideTheme: ctd,
);
}
【讨论】: