Skip to content

Fix setState() called after dispose in MacosPulldownButton - #581

Closed
Abbas1Hussein wants to merge 7 commits into
macosui:devfrom
Abbas1Hussein:dev
Closed

Fix setState() called after dispose in MacosPulldownButton#581
Abbas1Hussein wants to merge 7 commits into
macosui:devfrom
Abbas1Hussein:dev

Conversation

@Abbas1Hussein

Copy link
Copy Markdown
Contributor

Fix: avoid calling setState after dispose in MacosPulldownButton

When I used MacosPulldownButton, this error appeared during tests:

setState() called after dispose(): _MacosPulldownButtonState (lifecycle state: defunct, not mounted)

It happened because setState was called inside the navigator.push(...).then(...) callback after the widget was already disposed.

I fixed it by adding a mounted check before calling setState:

navigator.push(_pulldownRoute!).then<void>((_) {
  if (!mounted) return;
  setState(() => _pullDownButtonState = PulldownButtonState.enabled);
  _removeMacosPulldownRoute();
});

@GroovinChip

Copy link
Copy Markdown
Collaborator

Hey @Abbas1Hussein, thanks for the PR. This is currently blocked by #580. In the meantime:

  • Could you please increment the package version number & update the changelog?
  • If you could add a test that covers this change, I'd really appreciate it, so that we can ensure this problem doesn't crop up again

@Abbas1Hussein

Copy link
Copy Markdown
Contributor Author

Updated the PR as requested:

  • Bumped the version to 2.0.4.
  • Updated the CHANGELOG.md.
  • Added a test that reproduces the issue and verifies the fix (no more setState after dispose errors).

All tests are passing successfully.

Thanks for the feedback!

@GroovinChip

Copy link
Copy Markdown
Collaborator

Looks like you deleted the changelog, can you please undo that?

@Abbas1Hussein

Copy link
Copy Markdown
Contributor Author

I removed the file while cleaning up my branch, I’ve restored the CHANGELOG.md file.

Please let me know if anything else is needed.

@GroovinChip

Copy link
Copy Markdown
Collaborator

I removed the file while cleaning up my branch, I’ve restored the CHANGELOG.md file.

Please let me know if anything else is needed.

It looks like the file was not restored completely - if you look at the diff on this PR, you will see several recent entries are showing as removed. Please add those back in. Thanks!

@Abbas1Hussein Abbas1Hussein closed this by deleting the head repository Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants