getCommandValue method
Returns the latest value received for the specified item/key/field combination.
This method can only be used if the Subscription mode is COMMAND.
Subscriptions with two-level behavior
are also supported, hence the specified field
(see Subscription.setCommandSecondLevelFields and Subscription.setCommandSecondLevelFieldSchema)
can be either a first-level or a second-level one.
It is suggested to consume real-time data by implementing and adding a proper
SubscriptionListener rather than probing this method.
Note that internal data is cleared when the Subscription is unsubscribed from.
itemNameOrPosition
an item in the configured "Item List" or the 1-based position of an item within the configured "Item Group" or "Item List"keyValue
the value of a key received on the COMMAND subscription.fieldNameOrPosition
a item in the configured "Field List" or the 1-based position of a field within the configured "Field Schema" or "Field List"
Throws IllegalArgumentException if an invalid item name or field name is specified.
Throws IllegalStateException if the Subscription mode is not COMMAND.
Returns the current value for the specified field of the specified key within the specified item (possibly null), or null if the specified key has not been added yet (note that it might have been added and then deleted).
Implementation
Future<String?> getCommandValue(String itemNameOrPosition, String keyValue, 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,
'key': keyValue,
'field': fieldName,
};
return await _invokeMethod('getCommandValueByItemNameAndFieldName', arguments);
} else {
var arguments = <String, dynamic> {
'item': itemName,
'key': keyValue,
'field': fieldPos,
};
return await _invokeMethod('getCommandValueByItemNameAndFieldPos', arguments);
}
} else {
if (fieldPos == null) {
var arguments = <String, dynamic> {
'item': itemPos,
'key': keyValue,
'field': fieldName,
};
return await _invokeMethod('getCommandValueByItemPosAndFieldName', arguments);
} else {
var arguments = <String, dynamic> {
'item': itemPos,
'key': keyValue,
'field': fieldPos,
};
return await _invokeMethod('getCommandValueByItemPosAndFieldPos', arguments);
}
}
}