prepareTagsYomichanFormat function
- PrepareDictionaryParams params
Top-level function for use in compute. See DictionaryFormat for details.
Implementation
Future<List<DictionaryTag>> prepareTagsYomichanFormat(
PrepareDictionaryParams params) async {
List<DictionaryTag> tags = [];
final List<FileSystemEntity> entities = params.workingDirectory.listSync();
final Iterable<File> files = entities.whereType<File>();
for (File file in files) {
String filename = path.basename(file.path);
if (!filename.startsWith('tag_bank')) {
continue;
}
String json = file.readAsStringSync();
List<dynamic> items = jsonDecode(json);
for (List<dynamic> item in items) {
String name = item[0] as String;
String category = item[1] as String;
int sortingOrder = item[2] as int;
String notes = item[3] as String;
double popularity = (item[4] as num).toDouble();
DictionaryTag tag = DictionaryTag(
dictionaryId: params.dictionary.id,
name: name,
category: category,
sortingOrder: sortingOrder,
notes: notes,
popularity: popularity,
);
tags.add(tag);
}
if (tags.isNotEmpty) {
params.send(t.import_found_tag(count: tags.length));
}
}
return tags;
}