ExpansionTile Title color changes on expansion - flutter

ExpansionTile(
title: Text('test'),
children: [Text('test expanded')],
),
In this simple test, when I click on the title to expand the widget, the original title text turns from black to grey. I'm not sure if this is a Theme issue (I tried changing every grey color to something bright) or is something that I can manage through ExpansionTile (don't see it in the hover menu).
I did find that I could explicitly state the text color should be black and then it stays constant. However, in my real world use case for this tile I have several Text widgets and don't want to have to color each one.
Any ideas on how to address this in one shot?

It is an animated color between accentColor & subtitle1 color. So, you can override theme like this.
Theme(
data: ThemeData(
accentColor: Colors.black,
textTheme: TextTheme(
subtitle1: TextStyle(color: Colors.black),
),
),
child: ExpansionTile(
title: Text('test'),
children: [Text('test expanded')],
),
),

Related

Best practice to propagate theme through flutter screens

I've made a basic theme for my app and set it in the MaterialApp widget
ThemeData(
primaryColor: Colors.black,
backgroundColor: Colors.grey.shade50,
scaffoldBackgroundColor: Colors.grey.shade50,
buttonColor: Colors.purple,
);
but it seems the theme is not being updated on MaterialAppshome
home: LoginScreen()
. the button nor the background (supposed to be black and gray) aint updating...
What is the correct way of doing this?
As per the docs:
Using a Theme
Now that you’ve defined a theme, use it within the widgets’ build() methods by using the Theme.of(context) method.
The Theme.of(context) method looks up the widget tree and returns the nearest Theme in the tree. If you have a standalone Theme defined above your widget, that’s returned. If not, the app’s theme is returned.
In fact, the FloatingActionButton uses this technique to find the accentColor.
Container(
color: Theme.of(context).accentColor,
child: Text(
'Text with a background color',
style: Theme.of(context).textTheme.headline6,
),
),

Flutter Sliver AppBar leading color

This is a Sliver AppBar.
How can I change the color of the back arrow ?
BUT I don't want to set leading: Icon(Icons.arrow_back, color: Colors.red) since (I believe) that the Sliver AppBar has the nice property of adapting the lead icon depending on context.
wrap the SliverAppBar widget with Theme widget, and change primaryIconTheme color in ThemeData. Here's the code:
Theme(
data: ThemeData(
primaryIconTheme: IconThemeData(color: Colors.red)),
child: SliverAppBar(),
),

AppBar text color in Flutter

When I’m setting primarySwatch: Colors.blue, I’m getting white texts in AppBar.
However, when I’m switching to primarySwatch: Colors.cyan, texts are black.
I guess, Google does some kind of magic and automatically adjusts it.
How to globally edit theme to show always white texts in AppBar (for title and tabs).
You can use this code and see if that works
appBar: AppBar(
title: Text(
'History',
style: TextStyle(color: Color(0xffffffaa)),
),
),

Change highlight colour for textfield in flutter

Is there any way to change the colour of a Textfield's highlight in Flutter?
So when I highlight it does not look like this:
Thank you!
Solution 1. You can change the textSelectionColor in the theme of your app:
theme: ThemeData.dark().copyWith(
textSelectionColor: Colors.black
),
Solution 2. You can change the textSelectionColor only for a specific TextField by wrapping it with a Theme widget:
Theme(
data: ThemeData(
textSelectionColor: Colors.black,
),
child: TextField(
),
),

How do I change the check icon color in flutter filterChip

I need a way to change the check (✔) color to white. How do I achieve that
You can change the color of the checkmark by using checkMarkColor property
FilterChip(
label: Text('Pizza'),
shape: StadiumBorder(side: BorderSide()),
checkmarkColor: Colors.red,
backgroundColor: Colors.transparent,
),
Black or white checkmark
You can change the color to either black or white based on a light or dark theme. You can change the theme globally or wrap the specific widget within a Theme widget.
Theme(
data: ThemeData(
brightness: Brightness.dark
), // or shorthand => ThemeData.dark()
child: FilterChip(
label: Text('My chip'),
onSelected: (value) {
// ...
},
),
);
Other colors
There is currently no way to change the color of the checkmark in the FilterChip provided by the Material package to an arbitrary color. The way the checkmark is drawn can be found in the source code for the Chip classes here.
For future reference, this is the part of code that draws the checkmark:
void _paintCheck(Canvas canvas, Offset origin, double size) {
Color paintColor;
switch (theme.brightness) {
case Brightness.light:
paintColor = theme.showAvatar ? Colors.white : Colors.black.withAlpha(_kCheckmarkAlpha);
break;
case Brightness.dark:
paintColor = theme.showAvatar ? Colors.black : Colors.white.withAlpha(_kCheckmarkAlpha);
break;
}
...
So it is only able to show either as black or white right now. If you want it colored, you'll have to resort to a custom widget.
You could also chime in on the already opened issue on Flutters Github project.
You can simply wrap your FilterChip in a Theme widget, and set the desired ThemeData without changing your general app style.
Theme(
data: ThemeData.dark(), // White color. Select light for black.
child: FilterChip(
label: Text('Test'),
selected: _selected,
onSelected: (val) {
setState(() => _selected = val);
},
backgroundColor: Colors.blue,
selectedColor: Colors.pink,
labelStyle: TextStyle(
color: Colors.white,
),
),
),
You can work around this by using an Avatar and customising this to represent the tick mark, e.g.
FilterChip(
label: Text(
"label text",
style: TextStyle(color: Colors.red),
),
avatar: isSelected ? Icon(Icons.check, color: contrastColor(Colors.red)) : null,
// selected: isSelected,
},
)
The function contrastColor just looks at the supplied colour and chooses white or black depending upon its luminescence.
The animation effects when toggling ruin this slightly, so you may want to keep an 'empty' avatar rather than null if it looks bad.
Wrapping the FilterChip with a Theme sort of works but, for me at least, it rendered the background colours incorrectly (too dark) when flipping between light and dark themes.