Home > front end >  unable to change color of container in expansion Tile flutter
unable to change color of container in expansion Tile flutter

Time:08-07

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:

enter image description here

  • Related