doesNamesContainString method

List doesNamesContainString(
  1. String? string,
  2. List<String> inputNames
)

checks whether name and family have been in inputNames or not. the first item of the list returned is the bool result and the second is the String result.

Implementation

List<dynamic> doesNamesContainString(
    String? string, List<String> inputNames) {
  bool b = false;
  String temp = '';
  string = string!.toLowerCase().trim();
  if (string.length < 2) return [false, ''];
  for (var s in inputNames) {
    String fn = '';
    List<String> fnList = s.split(" ");
    for (int i = fnList.length; i > 0; i--) {
      fn = fn + ' ' + fnList[i - 1];
    }
    fn = fn.trim();
    if (string.contains(s.toLowerCase()) || checkSimilarity(string, s)) {
      b = true;
      temp = s.toLowerCase();
    } else if (string.contains(fn.toLowerCase()) ||
        checkSimilarity(string, fn)) {
      b = true;
      temp = fn.toLowerCase();
    }
  }
  return [b, temp];
}