replace full text match with fuzzy match + sort according to best match
This commit is contained in:
parent
896337bf2f
commit
65f71eef1a
|
@ -3,6 +3,7 @@ import 'dart:async';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:fuzzy/fuzzy.dart';
|
||||||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
@ -91,10 +92,15 @@ class CommunitiesTab extends HookWidget {
|
||||||
);
|
);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
filterCommunities(List<CommunityFollowerView> comm) =>
|
filterCommunities(List<CommunityFollowerView> comm) {
|
||||||
comm.where((e) => e.communityName
|
var matches = Fuzzy(
|
||||||
.toLowerCase()
|
comm.map((e) => e.communityName).toList(),
|
||||||
.contains(filterController.text.toLowerCase()));
|
options: FuzzyOptions(threshold: 0.5),
|
||||||
|
).search(filterController.text).map((e) => e.item);
|
||||||
|
|
||||||
|
return matches
|
||||||
|
.map((match) => comm.firstWhere((e) => e.communityName == match));
|
||||||
|
}
|
||||||
|
|
||||||
toggleCollapse(int i) => isCollapsed.value =
|
toggleCollapse(int i) => isCollapsed.value =
|
||||||
isCollapsed.value.mapWithIndex((e, j) => j == i ? !e : e).toList();
|
isCollapsed.value.mapWithIndex((e, j) => j == i ? !e : e).toList();
|
||||||
|
|
14
pubspec.lock
14
pubspec.lock
|
@ -268,6 +268,13 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
fuzzy:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: fuzzy
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.3"
|
||||||
glob:
|
glob:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -338,6 +345,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.1"
|
version: "3.0.1"
|
||||||
|
latinize:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: latinize
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.0.2"
|
||||||
lemmy_api_client:
|
lemmy_api_client:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -29,6 +29,7 @@ dependencies:
|
||||||
cached_network_image: ^2.2.0+1
|
cached_network_image: ^2.2.0+1
|
||||||
timeago: ^2.0.27
|
timeago: ^2.0.27
|
||||||
lemmy_api_client: ^0.4.0
|
lemmy_api_client: ^0.4.0
|
||||||
|
fuzzy: <1.0.0
|
||||||
|
|
||||||
mobx: ^1.2.1
|
mobx: ^1.2.1
|
||||||
flutter_mobx: ^1.1.0
|
flutter_mobx: ^1.1.0
|
||||||
|
|
Loading…
Reference in New Issue