Resolves #168 Fix error when entity view closed before history loaded
This commit is contained in:
@ -32,6 +32,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
List _history;
|
List _history;
|
||||||
bool _needToUpdateHistory;
|
bool _needToUpdateHistory;
|
||||||
DateTime _historyLastUpdated;
|
DateTime _historyLastUpdated;
|
||||||
|
bool _disposed = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -47,16 +48,20 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
if (_historyLastUpdated == null || now.difference(_historyLastUpdated).inSeconds > 30) {
|
if (_historyLastUpdated == null || now.difference(_historyLastUpdated).inSeconds > 30) {
|
||||||
_historyLastUpdated = now;
|
_historyLastUpdated = now;
|
||||||
ha.getHistory(entityId).then((history){
|
ha.getHistory(entityId).then((history){
|
||||||
|
if (!_disposed) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_history = history.isNotEmpty ? history[0] : [];
|
_history = history.isNotEmpty ? history[0] : [];
|
||||||
_needToUpdateHistory = false;
|
_needToUpdateHistory = false;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
Logger.e("Error loading $entityId history: $e");
|
Logger.e("Error loading $entityId history: $e");
|
||||||
|
if (!_disposed) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_history = [];
|
_history = [];
|
||||||
_needToUpdateHistory = false;
|
_needToUpdateHistory = false;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,4 +136,10 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_disposed = true;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user