-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SearchDelegate should respect InputDecoration theme override #19734
Comments
The style of the search text field in the _SearchPageState needs to be updated as well. The code I'm referring to is on line 420 of search.dart. title: new TextField(
controller: queryTextController,
focusNode: widget.delegate._focusNode,
style: theme.textTheme.title,
onSubmitted: (String _) {
widget.delegate.showResults(context);
},
decoration: new InputDecoration(
border: InputBorder.none,
hintText: MaterialLocalizations.of(context).searchFieldLabel,
),
), I have the following code to override the app bar style. @override
ThemeData appBarTheme(BuildContext context) {
final ThemeData theme = Theme.of(context);
return theme.copyWith(
primaryColor: theme.primaryColor,
primaryIconTheme: theme.primaryIconTheme,
primaryColorBrightness: theme.primaryColorBrightness,
primaryTextTheme: theme.primaryTextTheme,
);
} Which makes it look like this I'm able to update the text field with this code in my overridden method:
Which makes it look like this However, the 'Search' hint text is still grey as shown I'm unsure how to fix that part. |
@DFreds I do understand the problem you describe in your second post. We need to provide a way to customize the hint text. However, I don't understand your issue in the fist post. Overriding |
It isn't so much an issue as it is unexpected behavior of the search widget. I'm struggling to understand why it would default to Colors.white and Colors.grey for the primary color and primary icon theme instead of inheriting something from the theme like (almost all?) other widgets with color. I think having the override for the theme of it is great for unique customization, but I assumed that it would match the rest of my application by default when I added it. My example pointed out dark mode. As it stands, I have to do basically zero work if I want a dark mode in my app. Obviously I can customize it, but widgets such as cards, text, icons, etc. all change to match the dark theme. The search widget does not. Does that clear it up? |
That makes sense. Thanks for the clarification. |
I did not solve it. I ended up using the default styling for now |
Same issue, we need a way to customize hint color |
Please merge @guojiex changes to stable. |
Same problem, Is there any development? |
There is another way to fix this, change the line 433 in search.dart, by adding a theme wrapper for the text_field: title: Theme(
data: theme,
child: TextField(
controller: queryTextController,
focusNode: widget.delegate._focusNode,
style: theme.textTheme.title,
textInputAction: TextInputAction.search,
onSubmitted: (String _) {
widget.delegate.showResults(context);
},
decoration: InputDecoration(
border: InputBorder.none,
hintText: searchFieldLabel,
),
),
), Maybe we should add a theme wrapper for the whole Scaffold in the search.dart, line 426, but I think that will be a breaking change. |
when fix for hint color? |
Closing this as #30388 was just merged and built successfully. SearchDelegate will now respect the I still think that a more comprehensive solution to this theme problem would be nice, as discussed above, but this fixes the problem for now. |
As of temporary fix for dark theme I changed line 398 in search.dart |
The suggestions here work. except for the cursor color. is there a workaround for this? |
@chitgoks I don't see a way to set the cursor color in SearchDelegate. Can you open a separate issue for that? It would be a pretty straightforward PR if anyone is interested in opening one. |
It looks like we can't override InputDecoration as shown in the source code:
|
This issue is quite old at this point and is too generic IMO. I am refocusing it to be primarily about InputDecoration theme which remains an issue also raised by several internal teams. Marking as p3 for now. |
I have found the solution !!!
|
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Internal: b/165582972
Currently, the search bar contained in SearchDelegate uses the following code to set the colors of the app:
This requires a specific override of
appBarTheme
for each SearchDelegate or else it looks horrible for dark themes (even the defaultThemeData.dark()
). Frankly, I don't see why it needs to explicitly specify Colors.white or Colors.grey. It should inherit something from the currently applied theme just like the regular app bar.I attached two images (light and dark) to prove my point.
The text was updated successfully, but these errors were encountered: