I am creating an expansion tile in flutter web that I have wrapped around a container. The default is green color. I want to do is so that if the widget is expanded, the color changes to blue. I tried using setState but it still does not work.
Color change = Colors.green;
Container(
width: width*0.19,
decoration: BoxDecoration(
color: change,
//
borderRadius: BorderRadius.only(
topRight: Radius.circular(40.0),
bottomRight: Radius.circular(40.0),
),
),
child: ExpansionTile(
title: Text('ExpansionTile 2'),
subtitle: const Text('Custom expansion arrow icon'),
children: const <Widget>[
ListTile(title: Text('This is tile number 2')),
],
onExpansionChanged: (expanded) {
setState(() {
if (expanded) {
change = Colors.blue;
} else {
change = Colors.green;
}
});
},
),
),
These are a few links I referred:
How to change title's text style of ExpansionTile in flutter?
Change color of Title text in ExpansionTile widget when it is expanded
Make sure that you have added state variable outside the build method in class.
class TestScreen extends StatefulWidget {
@override
_TestScreenState createState() => _TestScreenState();
}
class _TestScreenState extends State<TestScreen> {
Color change;
@override
Widget build(BuildContext context) {
//Your ContainerWidget()
}
}