Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: setState() called after dispose() #1

Closed
tajjacob opened this issue Aug 29, 2020 · 2 comments
Closed

Unhandled Exception: setState() called after dispose() #1

tajjacob opened this issue Aug 29, 2020 · 2 comments
Assignees

Comments

@tajjacob
Copy link

Salam brother..
thanks for developing this package..
.
I have this error when running the example even though the pray time is generated.
'
Hope you can address this issue.

E/flutter (29148): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: setState() called after dispose(): _TodayKuliahMasjidWaktuSolatPageState#fe309(lifecycle state: defunct, not mounted) E/flutter (29148): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback. E/flutter (29148): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree. E/flutter (29148): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
image

image

@iamriajul
Copy link
Owner

iamriajul commented Aug 29, 2020

Waalaikumussalam brother,
can you try this: https://gist.github.com/iamriajul/d02c376c1617ec7579d9ac014f47d320

`@override
void initState() {
getLocationData().then((locationData) {
if (mounted) {
return;
}
if (locationData != null) {
setState(() {
prayerTimes = PrayerTimes(
Coordinates(locationData.latitude, locationData.longitude),
DateComponents.from(DateTime.now()),
CalculationMethod.karachi.getParameters());
});
} else {
setState(() {
locationError = "Couldn't Get Your Location!";
});
}
});

super.initState();
}
`

@iamriajul
Copy link
Owner

I have just pushed the changed code to the repository. now repository example shouldn't have Unhandled Exception: setState() called after dispose() Error.

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

No branches or pull requests

2 participants