Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change state after onClick to show items

I would want to expand/show this column when I click on an IconButton which I set isExpanded = true. But nothing happens when I tap on the IconButton. Here’s my code:

IconButton(
      onPressed: () {
          if (isExpanded) isExpanded = false;
          isExpanded = true;                     // i tried wrapping in setState and wont work too
      },
      icon: const Icon(Icons.more_horiz)
)
...["general-chat", "gm", "gn", "self-introduction"].map((channel) => isExpanded ? ListTile(
        leading: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                     const Icon(Icons.chat_bubble_rounded, size: 21),
                ],
               ),
               horizontalTitleGap: 0,
               title: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                             Text(channel),
                              ],
                        ),
                        onTap: () {},
                            ): Row(
                            children: [
                              SizedBox(width: 1),
                             ],
))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

try this:
use operator not ! to your value

IconButton(
   onPressed: () {
      setState(() { 
          isExpanded = !isExpanded;    // notice there "!" before isexpadned
      });                 
   },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading