Only listen for events on existing sites

This commit is contained in:
Ian VanSchooten 2024-10-29 11:18:50 -04:00
parent 1ecd008824
commit 700156cf64
1 changed files with 16 additions and 14 deletions

View File

@ -93,20 +93,22 @@ class Site {
this.rawConfig = rawConfig; this.rawConfig = rawConfig;
this.lastManagedUpdate = lastManagedUpdate; this.lastManagedUpdate = lastManagedUpdate;
_updates = EventChannel('net.defined.nebula/$id'); if (id != null) {
_updates.receiveBroadcastStream().listen((d) { _updates = EventChannel('net.defined.nebula/$id');
try { _updates.receiveBroadcastStream().listen((d) {
_updateFromJson(d); try {
_change.add(null); _updateFromJson(d);
} catch (err) { _change.add(null);
//TODO: handle the error } catch (err) {
print(err); //TODO: handle the error
} print(err);
}, onError: (err) { }
_updateFromJson(err.details); }, onError: (err) {
var error = err as PlatformException; _updateFromJson(err.details);
_change.addError(error.message ?? 'An unexpected error occurred'); var error = err as PlatformException;
}); _change.addError(error.message ?? 'An unexpected error occurred');
});
}
} }
factory Site.fromJson(Map<String, dynamic> json) { factory Site.fromJson(Map<String, dynamic> json) {