I'm making an application by flutter.
I want to customize ExpansionTile Widget.
In normal, when expansion tile is expanded, its title's color turns to be blue.
Instead, I want to get it bold font.
return ExpansionTile(
textColor: Colors.black,
title: Text(_fencingClubDataList[index].Name),
expandedAlignment: Alignment.centerLeft,
expandedCrossAxisAlignment:
CrossAxisAlignment.start,
children: [
Table(
border: TableBorder.all(color: Colors.black),
defaultVerticalAlignment:
TableCellVerticalAlignment.top,
children: [
TableRow(children: [
Text("This is"),
Text("a sample."),
]),
],
),
],
);
I understand that you can change expanded tile's color by using textColor property.
Is there any way to change its text style like this?
Thanks,
CodePudding user response:
Try with this code.
bool isExpand = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ExpansionTile(
onExpansionChanged: (bool isExapnd) {
setState(() {
isExpand = isExapnd;
});
},
textColor: Colors.black,
title: Text(
"Title",
style: TextStyle(
fontWeight: isExpand ? FontWeight.bold : FontWeight.normal),
),
expandedAlignment: Alignment.centerLeft,
expandedCrossAxisAlignment: CrossAxisAlignment.start,
children: [
Table(
border: TableBorder.all(color: Colors.black),
defaultVerticalAlignment: TableCellVerticalAlignment.top,
children: [
TableRow(children: [
Text("This is"),
Text("a sample."),
]),
],
),
],
),
);
}
CodePudding user response:
bool _customTileExpanded = false;
ExpansionTile(
title: Text('ExpansionTile 2', style: TextStyle(fontWeight: _customTileExpanded ? FontWeight.bold : FontWeight.normal)),
subtitle: const Text('Custom expansion arrow icon'),
children: const <Widget>[
ListTile(title: Text('This is tile number 2')),
],
onExpansionChanged: (bool expanded) {
setState(() => _customTileExpanded = expanded);
},
)
now using this bool variable _customTileExpanded
, you can style as you want. You can find more information in here ExpansionTile