iamriajul / adhan-dart

Adhan for Dart / Muslim Prayer Times Library. Now retrieving Prayer time in Dart easier than ever.
https://pub.dev/packages/adhan
MIT License
86 stars 41 forks source link

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

Closed tajjacob closed 4 years ago

tajjacob commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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