From 0da3959723a01406963bc002945e26d66d3e77cc Mon Sep 17 00:00:00 2001 From: Gold872 Date: Sat, 16 Dec 2023 19:18:37 -0500 Subject: [PATCH] Fixed widget properties not updating if multiple subscriptions are shared in a tab --- lib/services/nt4_client.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/services/nt4_client.dart b/lib/services/nt4_client.dart index fc15e06c..0bc06d54 100644 --- a/lib/services/nt4_client.dart +++ b/lib/services/nt4_client.dart @@ -60,7 +60,8 @@ class NT4Subscription { Object? currentValue; final List _listeners = []; - bool _newValueRequested = false; + // Multiple instances of this can be used at once, so it has to request the new value for all of the subscription streams + int _newValueRequestCount = 0; NT4Subscription({ required this.topic, @@ -77,10 +78,12 @@ class NT4Subscription { Object? lastYielded = currentValue; while (true) { - if (lastYielded != currentValue || yieldAll || _newValueRequested) { + if (lastYielded != currentValue || + yieldAll || + _newValueRequestCount > 0) { yield currentValue; lastYielded = currentValue; - _newValueRequested = false; + _newValueRequestCount--; } await Future.delayed( Duration(milliseconds: (options.periodicRateSeconds * 1000).round())); @@ -95,7 +98,7 @@ class NT4Subscription { } void requestNewValue() { - _newValueRequested = true; + _newValueRequestCount = useCount; } Map _toSubscribeJson() {