getValue method
Returns the latest value received for the specified item/field pair.
It is suggested to consume real-time data by implementing and adding
a proper SubscriptionListener rather than probing this method.
In case of COMMAND Subscriptions, the value returned by this
method may be misleading, as in COMMAND mode all the keys received, being
part of the same item, will overwrite each other; for COMMAND Subscriptions,
use getCommandValue instead.
Note that internal data is cleared when the Subscription is
unsubscribed from.
Lifecycle This method can be called at any time; if called to retrieve a value that has not been received yet, then it will return null.
Throws IllegalArgumentException if an invalid item name or field name is specified.
itemNameOrPosition
an item in the configured "Item List" or the 1-based position of an item within the configured "Item Group" or "Item List"fieldNameOrPosition
a item in the configured "Field List" or the 1-based position of a field within the configured "Field Schema" or "Field List"
Returns the current value for the specified field of the specified item (possibly null), or null if no value has been received yet.
Implementation
Future<String?> getValue(String itemNameOrPosition, String fieldNameOrPosition) async {
if (!_remoteActive) {
return null;
}
var itemPos = int.tryParse(itemNameOrPosition, radix: 10);
var fieldPos = int.tryParse(fieldNameOrPosition, radix: 10);
var itemName = itemNameOrPosition;
var fieldName = fieldNameOrPosition;
if (itemPos == null) {
if (fieldPos == null) {
var arguments = <String, dynamic> {
'item': itemName,
'field': fieldName,
};
return await _invokeMethod('getValueByItemNameAndFieldName', arguments);
} else {
var arguments = <String, dynamic> {
'item': itemName,
'field': fieldPos,
};
return await _invokeMethod('getValueByItemNameAndFieldPos', arguments);
}
} else {
if (fieldPos == null) {
var arguments = <String, dynamic> {
'item': itemPos,
'field': fieldName,
};
return await _invokeMethod('getValueByItemPosAndFieldName', arguments);
} else {
var arguments = <String, dynamic> {
'item': itemPos,
'field': fieldPos,
};
return await _invokeMethod('getValueByItemPosAndFieldPos', arguments);
}
}
}