0

I am wanting an action to happen when a specific icon is pressed. I am currently trying to do it by getting the icon data information and using an if statement:

child: new CircleButton(
  onTap: () {
    if(IconData==Icons.control_point){
      print("hello");
    }
  },
  iconData: _iconsDaily[index]
),

And I am declaring my icons:

@override
  Widget build(BuildContext context) {
    List<IconData> _iconsDaily = [
      Icons.shopping_cart,
      Icons.cake_rounded,
      Icons.card_giftcard,
      Icons.control_point,
    ];

However IconData==Icons.control_point are unrelated types and so I am unsure how to compare these. Any help would be appreciated thanks.

1
  • 2
    _iconsDaily[index] == Icons.control_point Commented Jan 5, 2021 at 14:43

1 Answer 1

3

If you're trying to check the iconData that belongs to the CircleButton, you should do it like this

child: new CircleButton(
  onTap: () {
    if( _iconsDaily[index] == Icons.control_point){
      print("hello");
    }
  },
  iconData: _iconsDaily[index]
)
Sign up to request clarification or add additional context in comments.

2 Comments

Amazing, I thought I had tried that but apparently not so thank you very much - it works perfectly!
@ajnabz IconData is a type of variable, you cannot compare it to a value of a variable. You can only compare a value to the variable's value. Also take note that the new keyword is not needed anymore. You can remove it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.