getValue method

dynamic getValue(
  1. BuildContext context, {
  2. int loop = 0,
})

Implementation

dynamic getValue(BuildContext context, {int loop = 0}) {
  final variable = context
      .getVariableById(
          variableID: variableID!, cubitID: cubitID!, stateID: stateID!)
      .variable as JsonVar;
  if (type == VariableTypes.json) {
    try {
      if (jsonPath.isEmpty) {
        if (variable.data is List) {
          return getListValueModified(
            variable.data,
            context,
            loop,
          );
        }
        return variable.data;
      }

      final elements =
          JsonPath('\$.$jsonPath').readValues(variable.data).toList();

      if (listFormatOptions.options.isEmpty) {
        return getValueModified(
          elements[overridedLoop ?? loop],
          context,
          loop,
        );
      } else {
        var value = getListValueModified(
          elements.map((e) => e).toList(),
          context,
          loop,
        );
        if (value is List) {
          return value;
        }
        if (formatOptions.options.isEmpty) {
          return value;
        }
        return getValueModified(
          value,
          context,
          loop,
        );
      }
    } catch (e) {
      Logger.printError('JsonGetAttribute.getValue, error: $e');
      return '{${jsonPath.split('.').last}}';
    }
  }
  throw Exception('Unknown variable type');
}