Skip to content

fix: add mounted guard before setState() in async SharedPreferences callback#44

Merged
matisiekpl merged 1 commit into
matisiekpl:mainfrom
chrisdebian:fix/43-mounted-guard-initstate
Jun 10, 2026
Merged

fix: add mounted guard before setState() in async SharedPreferences callback#44
matisiekpl merged 1 commit into
matisiekpl:mainfrom
chrisdebian:fix/43-mounted-guard-initstate

Conversation

@chrisdebian

Copy link
Copy Markdown
Contributor

Adds a mounted check before setState() in _AppState.initState() to prevent calling setState() on a disposed widget if the SharedPreferences.getInstance() future resolves after the widget is unmounted.

Change

One line added in lib/main.dart:

SharedPreferences.getInstance().then((prefs) {
  if (!mounted) return;   // added
  setState(() { ... });
});

Testing

Tested on Pixel 6, Android 16.

Fixes #43

…allback

Prevents setState() called after dispose() if the widget is unmounted
before SharedPreferences.getInstance() resolves.

Fixes matisiekpl#43
@netlify

netlify Bot commented Jun 2, 2026

Copy link
Copy Markdown

👷 Deploy request for aedmap pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0ec14a2

@matisiekpl matisiekpl merged commit 4e7530a into matisiekpl:main Jun 10, 2026
2 checks passed
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.

fix: add mounted guard before setState() in async SharedPreferences callback

2 participants