feedback method

  1. @override
Feedback? feedback({
  1. required bool isSoleMatch,
})
override

Should return the warning and suggestions regarding this match.

Implementation

@override
Feedback? feedback({required bool isSoleMatch}) {
  final String? warning;
  switch (dictionary) {
    case Dictionary.diceware:
    case Dictionary.commonWords:
      warning = null;
      break;
    case Dictionary.passwords:
      if (isSoleMatch && this is! L33tMatch && this is! ReverseMatch) {
        if (rank <= 10) {
          warning = Translation.warnings.topTen;
        } else if (rank <= 100) {
          warning = Translation.warnings.topHundred;
        } else {
          warning = Translation.warnings.common;
        }
      } else if (guesses <= 1e4) {
        warning = Translation.warnings.similarToCommon;
      } else {
        warning = null;
      }
      break;
    case Dictionary.names:
      warning = isSoleMatch
          ? Translation.warnings.namesByThemselves
          : Translation.warnings.commonNames;
      break;
    case Dictionary.wikipedia:
      warning = isSoleMatch ? Translation.warnings.wordByItself : null;
      break;
    case Dictionary.userInputs:
      warning = Translation.warnings.userInputs;
      break;
  }
  final List<String> suggestions;
  if (_startUpper.hasMatch(token)) {
    suggestions = <String>[Translation.suggestions.capitalization];
  } else if (_allUpperInverted.hasMatch(token) &&
      token.toLowerCase() != token) {
    suggestions = <String>[Translation.suggestions.allUppercase];
  } else {
    suggestions = const <String>[];
  }
  return Feedback(warning: warning, suggestions: suggestions);
}