processDynamicArgs method
Processes any dynamic argument values from args. This will return a
metadata object with the results as well as a collection of dynamic
variable names that were encounted.
Implementation
DynamicParamsResult processDynamicArgs(
dynamic args, {
Set<String>? dynamicKeys,
}) {
dynamicKeys ??= <String>{};
dynamic result;
if (args is String) {
var parsed = JsonWidgetRegexHelper.parse(args);
if (parsed?.isNotEmpty == true) {
String? functionKey;
List<dynamic>? functionArgs;
for (var item in parsed!) {
if (item.isFunction == true) {
dynamicKeys.add('__FUNCTION__');
functionKey = item.key;
functionArgs = [];
} else if (item.isVariable == true) {
if (item.isStatic != true) {
dynamicKeys.add(item.key!);
}
var value = getValue(item.key);
functionArgs?.add(value);
result = value;
} else {
functionArgs?.add(item.key);
result = item.key;
}
}
if (functionKey?.isNotEmpty == true) {
result = execute(functionKey, functionArgs);
}
} else {
result = args;
}
} else if (args is Iterable) {
result = [];
for (var value in args) {
result.add(processDynamicArgs(
value,
dynamicKeys: dynamicKeys,
).values);
}
} else if (args is Map) {
result = {};
if (args['type'] != null &&
(args['child'] != null ||
args['children'] != null ||
args['args'] != null)) {
// The entry has a "type" and one of: "child", "children", "args". This
// means the item is most likely a JsonWidgetData class, so we should
// not process the args yet. We should wait until the actual
// JsonWidgetData gets built.
result = args;
} else {
args.forEach((key, value) {
result[key] = processDynamicArgs(
value,
dynamicKeys: dynamicKeys,
).values;
});
}
} else {
result = args;
}
return DynamicParamsResult(
dynamicKeys: dynamicKeys,
values: result,
);
}