Changing colors for a subscription icon button when .resume and .pause are toggled. Why isn't this working?

0
      IconButton(
        icon: Icon(MdiIcons.moonWaxingCrescent),

          onPressed: () {
            expanded ? subscription.resume() : subscription.pause();


            setState(() {
              expanded
                  ? Color(0xffF2E03F)
                  : Color(0xffFFFFFF);
              expanded = !expanded;
            });
          }),

The above code won't change my color but does execute the function properly (toggles resume and pause). I tried changing this over from an animatedicon I have in use but it's a bit different with subscriptions I suppose. Here's the working animatedIcon that I don't need:

      IconButton(
          icon: AnimatedIcon(
            icon: AnimatedIcons.menu_arrow,
            progress: _animationController,
            semanticLabel: 'Pause',
          ),
          onPressed: () {
            expanded ? subscription.resume() : subscription.pause();
            setState(() {
              expanded
                  ? _animationController.forward()
                  : _animationController.reverse();
              expanded = !expanded;
            });
          }),

Any idea how to get the first button to change colors depending on .resume and .pause state?

flutter
dart
asked on Stack Overflow Aug 15, 2020 by tsy

1 Answer

0

Got it!

      IconButton(
        icon: Icon(MdiIcons.moonWaxingCrescent),
            color: (expanded) ? Color(0xffFF0000) : Color(0xff000000),
          onPressed: () {
            expanded ? subscription.resume() : subscription.pause();
            setState(() {
              expanded = !expanded;
            });
          }),
answered on Stack Overflow Aug 15, 2020 by tsy

User contributions licensed under CC BY-SA 3.0