comigor/fuzzy

Results randomly change?

Opened this issue · 0 comments

Super strange behaviour, Meagher street should stay but it disappears when the street is added

Kapture.2024-02-09.at.21.50.08.mp4
  void updateSearched(String searchTerm) {
    _searched.clear();
    if (searchTerm.isEmpty) {
      setState(() {
        _searched = List.from(_clinics);
      });
    }
    if (searchTerm.isNotEmpty) {
      for (var clinic in _clinics) {

        String clinicName = clinic['clinic']['name'].toLowerCase();
        String clinicAddress = clinic['clinic']['address'].toLowerCase();
        String clinicSpeciality = clinic['clinic']['speciality'].toLowerCase();
        String clinicSuburb = clinic['clinic']['suburb'].toLowerCase();
        Fuzzy fuzzy = Fuzzy([clinicName, clinicAddress, clinicSpeciality, clinicSuburb]);

        List<Result<dynamic>> results = fuzzy.search(searchTerm.toLowerCase());

        if (results.isNotEmpty) {
          List<dynamic> matchedStrings = results.map((result) => result.item).toList();
          print(matchedStrings);
          print(searchTerm);

          if (matchedStrings.length > 0) {
            _searched.add(clinic);
            break;
          }
        }
  }