diff --git a/lib/entity_widgets/history_chart/entity_history.dart b/lib/entity_widgets/history_chart/entity_history.dart index 41c2ab6..272bbb3 100644 --- a/lib/entity_widgets/history_chart/entity_history.dart +++ b/lib/entity_widgets/history_chart/entity_history.dart @@ -32,6 +32,7 @@ class _EntityHistoryWidgetState extends State { List _history; bool _needToUpdateHistory; DateTime _historyLastUpdated; + bool _disposed = false; @override void initState() { @@ -47,16 +48,20 @@ class _EntityHistoryWidgetState extends State { if (_historyLastUpdated == null || now.difference(_historyLastUpdated).inSeconds > 30) { _historyLastUpdated = now; ha.getHistory(entityId).then((history){ - setState(() { - _history = history.isNotEmpty ? history[0] : []; - _needToUpdateHistory = false; - }); + if (!_disposed) { + setState(() { + _history = history.isNotEmpty ? history[0] : []; + _needToUpdateHistory = false; + }); + } }).catchError((e) { Logger.e("Error loading $entityId history: $e"); - setState(() { - _history = []; - _needToUpdateHistory = false; - }); + if (!_disposed) { + setState(() { + _history = []; + _needToUpdateHistory = false; + }); + } }); } } @@ -131,4 +136,10 @@ class _EntityHistoryWidgetState extends State { } + @override + void dispose() { + _disposed = true; + super.dispose(); + } + } \ No newline at end of file