getCountForLists method

int getCountForLists(
  1. BuildContext context,
  2. int loop
)

Implementation

int getCountForLists(BuildContext context, int loop) {
  assert(variableID != null, 'Variable ID is null');
  final variable = context
      .getVariableById(
          variableID: variableID!, cubitID: cubitID!, stateID: stateID!)
      .variable as JsonVar?;
  if (variable == null) {
    return 1;
  }
  if (type == VariableTypes.json) {
    final elements =
        JsonPath('\$.$jsonPath').readValues(variable.data).toList();
    if (elements.isEmpty) {
      return context.forPlay ? 0 : 1;
    }
    if (elements.length > 1) {
      return elements.length;
    }
    if (elements.first is List || elements.first is Iterable) {
      return (elements.first as List).length;
    }
    if (elements.first is num) {
      return (elements.first as num).toInt();
    }
    return 1;
  }
  throw Exception('Unknown variable type, type: $type');
}