繁体   English   中英

Flutter SerachDelegate 修改 Hint Text Color 和 TextField Cursor Color

[英]Flutter SerachDelegate modify Hint Text Color and TextField Cursor Color

我正在我的颤振应用程序中使用 SearchDelegate 实现搜索栏。

我已经覆盖了 ThemeData appBarTheme(BuildContext context) 函数来返回我的主 App ThemeData。

但是,这只会更改搜索视图,仅更改应用栏颜色。 它不使用主题中定义的光标或提示颜色。

感谢任何建议。

您是否在 Apple Simulator 上运行您的应用程序? 因为 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,
  );
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM