From 700156cf642b512831366892f79d22c7a0035476 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 29 Oct 2024 11:18:50 -0400 Subject: [PATCH] Only listen for events on existing sites --- lib/models/Site.dart | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/models/Site.dart b/lib/models/Site.dart index 46ee231..05efa36 100644 --- a/lib/models/Site.dart +++ b/lib/models/Site.dart @@ -93,20 +93,22 @@ class Site { this.rawConfig = rawConfig; this.lastManagedUpdate = lastManagedUpdate; - _updates = EventChannel('net.defined.nebula/$id'); - _updates.receiveBroadcastStream().listen((d) { - try { - _updateFromJson(d); - _change.add(null); - } catch (err) { - //TODO: handle the error - print(err); - } - }, onError: (err) { - _updateFromJson(err.details); - var error = err as PlatformException; - _change.addError(error.message ?? 'An unexpected error occurred'); - }); + if (id != null) { + _updates = EventChannel('net.defined.nebula/$id'); + _updates.receiveBroadcastStream().listen((d) { + try { + _updateFromJson(d); + _change.add(null); + } catch (err) { + //TODO: handle the error + print(err); + } + }, onError: (err) { + _updateFromJson(err.details); + var error = err as PlatformException; + _change.addError(error.message ?? 'An unexpected error occurred'); + }); + } } factory Site.fromJson(Map json) {