Flutter SerachDelegate修改提示文本颜色和TextField光标颜色 [英] Flutter SerachDelegate modify Hint Text Color and TextField Cursor Color

查看:844
本文介绍了Flutter SerachDelegate修改提示文本颜色和TextField光标颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Flutter应用中使用SearchDelegate实现搜索栏。

I'm implementing the search bar using SearchDelegate in my flutter app.

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

I've overridden the ThemeData appBarTheme(BuildContext context) function to return my main App ThemeData.

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

However, this only changes the Search views, App Bar Color only. It does not use the Cursor or Hint color defined in the theme.

欣赏所有建议。

推荐答案

您是否在Apple Simulator上运行您的应用程序?因为cursorColor似乎与平台有关。 TextField类的文档指出,cursorColor字段

Are you running your app on the Apple Simulator? Because cursorColor seems to be platform dependent. The documentation for the TextField class states that the cursorColor field


默认为[ThemeData.cursorColor]或[CupertinoTheme.primaryColor],具体取决于[ThemeData .platform]。

Defaults to [ThemeData.cursorColor] or [CupertinoTheme.primaryColor] depending on [ThemeData.platform].

我必须创建一个CupertinoThemeData并将其传递给main.dart文件中应用程序的ThemeData,例如

I had to create a CupertinoThemeData and pass it to the ThemeData of my app in the main.dart file, like this:

@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,
  );
}

这篇关于Flutter SerachDelegate修改提示文本颜色和TextField光标颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆