checkClassifierSettings function
Validates settings as Google's runtime would.
Implementation
void checkClassifierSettings(ClassifierSettings settings) {
final ClassifierSettings(
:maxResults,
:scoreThreshold,
:displayNamesLocale,
:categoryAllowlist,
:categoryDenylist,
) = settings;
// MediaPipe treats a negative count as "no limit"; zero would return
// nothing, which is a mistake rather than a useful configuration.
if (maxResults == 0 || maxResults < -0x80000000 || maxResults > 0x7fffffff) {
throw ArgumentError.value(
maxResults,
'maxResults',
'Must be negative for no limit, or a positive count',
);
}
if (!scoreThreshold.isFinite) {
throw ArgumentError.value(
scoreThreshold,
'scoreThreshold',
'Must be finite',
);
}
if (categoryAllowlist.isNotEmpty && categoryDenylist.isNotEmpty) {
throw ArgumentError(
'Supply at most one of categoryAllowlist and categoryDenylist.',
);
}
if (displayNamesLocale case final locale?) {
checkLabel(locale, 'displayNamesLocale');
}
for (final name in [...categoryAllowlist, ...categoryDenylist]) {
checkLabel(name, 'category');
}
}