targetMissingNumbeCount function

String targetMissingNumbeCount(
  1. WidgetRef ref
)

Retrieves the count of missing values for the target variable.

Returns the number of missing values as a string. Returns "0" if no target is set, the target is not found in metadata, or the missing value information is not available.

Implementation

String targetMissingNumbeCount(WidgetRef ref) {
  // Get the target variable name.

  final target = getTarget(ref);

  // If there's no target set, return "0".

  if (target == 'NULL' || target.isEmpty) {
    return '0';
  }

  // Get the metadata for all variables.

  final metaData = ref.read(metaDataProvider);

  // Check if the target exists in metadata and has missing values information.

  if (metaData.containsKey(target) &&
      metaData[target]!.containsKey('missing') &&
      metaData[target]!['missing'] != null &&
      metaData[target]!['missing'].isNotEmpty) {
    // The missing value is stored as a list with a single numeric value.

    final missingCount = metaData[target]!['missing'][0];

    return missingCount.toString();
  }

  return '0';
}