Reputation: 234
I need to change the color of the trailing keyboard_down_arrow
in ExpansionTile
. I have tried wrapping it in Theme widget and setting accent, primary and IconTheme also, but nothing seems to work.
Theme(
data: Theme.of(context).copyWith(
dividerColor: Colors.transparent,
accentColor: Colors.black,
),
child: ExpansionTile(
//
title: Text("Some Text"
),
childrenPadding: EdgeInsets.symmetric(horizontal: 15),
children: [
],
),
),
Upvotes: 9
Views: 24345
Reputation: 11
ExpansionTileTheme(
data: const ExpansionTileThemeData(iconColor: Colors.black), // set color here
child: ExpansionTile(
subtitle: subtitle,
tilePadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
childrenPadding: const EdgeInsets.all(16),
shape: const Border(),
title: title,
children: children,
),
);
Upvotes: 1
Reputation: 594
ExpansionTile
has a properties:
iconColor: Colors.black,
collapsedIconColor: Colors.orange,
It changes the color of the trailing icon depending on if the tile is expanded or not.
Upvotes: 6
Reputation: 114
If you need more dynamic/general solution;
ExpansionTileThemeData expansionTileTheme(ColorScheme colors) {
return ExpansionTileThemeData(iconColor: Colors.white);
}
use this theme data in your theme.dart file that you use for theme light & dark like this
ThemeData light([Color? targetColor]) {
final colorScheme = colors(Brightness.light, targetColor);
return ThemeData.light().copyWith(
// unselectedWidgetColor: colorScheme.onPrimary,
expansionTileTheme: expansionTileTheme(colorScheme),);
}
in main.dart
MaterialApp.router(
theme: theme.light(Color),
);
This will affect your whole project, so you won't need to implement this color in every expansion tile that you will use.
Upvotes: 0
Reputation: 169
I have latest solution with both open/close state:
Theme(
data: Theme.of(context).copyWith(
unselectedWidgetColor: Colors.white, // here for close state
colorScheme: ColorScheme.light(
primary: Colors.white,
), // here for open state in replacement of deprecated accentColor
dividerColor: Colors.transparent, // if you want to remove the border
),
child: ExpansionTile(
...
),
),...
Upvotes: 16
Reputation: 234
I found the solution to the above problem.
set unselectedWidgetColor
property to the color you want in Theme class in flutter.
Upvotes: 5
Reputation: 2157
To change the trailing icon Color you can use the fallowing parameter in Expansion Tile
trailing: Icon(
Icons.keyboard_arrow_down,
color: Colors.green,
),
Example:
ExpansionTile(
//
title: Text("Some Text"),
trailing: Icon(
Icons.keyboard_arrow_down,
color: Colors.green,
),
),
And for theme Color use color: Theme.of(context).primaryColor,
Upvotes: 6