hasTargetMissingValues function
- WidgetRef ref
Checks if the target variable has any missing values.
Returns true if the target has missing values, false otherwise. Also returns false if no target is set or if the target doesn't exist in metadata.
Implementation
bool hasTargetMissingValues(WidgetRef ref) {
// Get the target variable name.
final target = getTarget(ref);
// If there's no target set, return false.
if (target == 'NULL' || target.isEmpty) {
return false;
}
// Get the metadata for all variables.
final metaData = ref.read(metaDataProvider);
// Check if the target exists in metadata and has missing values.
if (metaData.containsKey(target) &&
metaData[target]!.containsKey('missing') &&
metaData[target]!['missing'] != null) {
// Check if the missing value is greater than 0
// The missing value is stored as a list with a single value.
final missingCount = metaData[target]!['missing'][0];
return missingCount > 0;
}
return false;
}