search - Flutter SerachDelegate 修改 Hint Text Color 和 TextField Cursor Color
问题描述
我正在我的颤振应用程序中使用 SearchDelegate 实现搜索栏。
我已经覆盖了 ThemeData appBarTheme(BuildContext context) 函数以返回我的主 App ThemeData。
但是,这只会更改搜索视图,仅更改应用栏颜色。它不使用主题中定义的光标或提示颜色。
感谢任何建议。
解决方案
您是否在 Apple 模拟器上运行您的应用程序?因为 cursorColor 似乎是平台相关的。TextField 类的文档指出 cursorColor 字段
默认为 [ThemeData.cursorColor] 或 [CupertinoTheme.primaryColor],具体取决于 [ThemeData.platform]。
我必须创建一个 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,
);
}
推荐阅读
- visual-studio-code - 向上/向下滚动页面不移动光标
- angular - Angular:将注入的数据传递给子组件
- vuejs2 - 在 nuxtjs 的中间件中访问命名空间的 getter 函数
- android - React Native:如何从 app.js 导航
- r - 如何使用 formatstyle() 更改颜色基准条件?
- c# - SerialDataReceivedEventHandler 没有被触发
- windows - 从 powershell 卸载设备
- eclipse - DBeaver 内容辅助颜色
- python - 从应用于初始数据帧的多个条件构建数据帧:这种情况适用于 pandas 而不是 pyspark?
- sql - sql作业停止重复