问题描述
我正在研究可以与 flutter_typeahed 包一起使用的搜索。
我找到了一个名为 trie
的包,但它没有 null 安全,所以我想把它包括在内,并为该项目以及我自己的项目做出贡献。
由于整个 trie
文件很大,我提供了一个指向 pastebin 的链接。
这是我编写的 Search
类:
class Search {
final Map<String,RecipeModel> _map = Map.fromIterable(
Store.instance.getAllRecipes(),key: (recipe) => RecipeModel().recipeName!);
late final Trie trie;
Search() {
// This will be O[n]
trie = Trie.list(_map.keys.toList());
}
late RecipeModel recipe;
RecipeModel returnRecipe(String? suggestion) {
if (suggestion == null) return recipe;
// This will be O(1) instead of O(n) [better]
final RecipeModel? found = _map[suggestion];
return found ?? recipe;
}
List<String> returnSuggestions(String prefix) {
//will return O[W*L] ad-hoc search was O[n^2]
return trie.getAllWordsWithPrefix(prefix);
}
}
但我收到以下错误:
Cannot fit requested classes in a single dex file (# methods: 66909 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
The shrinker may have Failed to optimize the Java bytecode.
To disable the shrinker,pass the `--no-shrink` flag to this command.
注意:RecipeModel 只是一个包含 recipeName、authorId 等的模型。Store.instance.getAllRecipes(),
返回一个配方列表
解决方法
我必须启用 multidex。我必须更改以下内容:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.food_app"
minSdkVersion 17
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true // add this line
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.1' // add this one
}