Reputation: 165
I'm implementing the search bar using SearchDelegate in my flutter app.
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.
Appreciate any suggestions.
Upvotes: 2
Views: 1133
Reputation: 1123
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
Defaults to [ThemeData.cursorColor] or [CupertinoTheme.primaryColor] depending on [ThemeData.platform].
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,
);
}
Upvotes: 0