Skip to content

setState not updating the Icon #53

@smbpunt

Description

@smbpunt

Describe the bug
I have a variable in my AppState, and I would like to change an icon depending on this variable, after a setState().
It seems the icon is changing only if I go to another page...

To Reproduce
Steps to reproduce the behavior:

  1. Have a variable in your AppState (here it's List<Message> newMessages)
  2. Have an Icon based on this variable :
    List<BottomBarWithSheetItem> lstItems = [
      BottomBarWithSheetItem(
          icon: container.state.newMessages?.isEmpty ? Icons.mail_outline : Icons.mark_email_unread_outlined,
          label: 'MESSAGES'),
      //...
    ];
    return SafeArea(
      child: BottomBarWithSheet(
        controller: _bottomBarController,
       // ...
        items: lstItems,
      )
  1. Have an action to update your variable, and setState()
  void checkNewMessages() async {
      //...
          this.setState(() {
            state.newMessages.add(msg);
          });
  }

Expected behavior
After calling checkNewMessages, the Icon should be mark_email_unread_outlined, but it says mail_outline.

Maybe it's not a bug, maybe It's my code the bug, but I've not find anything in your documentation regarding this...

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions