added vocabulary audio reading
This commit is contained in:
@@ -96,19 +96,27 @@ class VocabSrsItem {
|
||||
}) : lastAsked = lastAsked ?? DateTime.now();
|
||||
}
|
||||
|
||||
class PronunciationAudio {
|
||||
final String url;
|
||||
final String gender;
|
||||
|
||||
PronunciationAudio({required this.url, required this.gender});
|
||||
}
|
||||
|
||||
class VocabularyItem {
|
||||
final int id;
|
||||
final String characters;
|
||||
final List<String> meanings;
|
||||
final List<String> readings;
|
||||
final List<PronunciationAudio> pronunciationAudios;
|
||||
final Map<String, VocabSrsItem> srsItems = {};
|
||||
|
||||
VocabularyItem({
|
||||
required this.id,
|
||||
required this.characters,
|
||||
required this.meanings,
|
||||
required this.readings,
|
||||
});
|
||||
VocabularyItem(
|
||||
{required this.id,
|
||||
required this.characters,
|
||||
required this.meanings,
|
||||
required this.readings,
|
||||
required this.pronunciationAudios});
|
||||
|
||||
factory VocabularyItem.fromSubject(Map<String, dynamic> subj) {
|
||||
final int id = subj['id'] as int;
|
||||
@@ -116,6 +124,7 @@ class VocabularyItem {
|
||||
final String characters = (data['characters'] ?? '') as String;
|
||||
final List<String> meanings = <String>[];
|
||||
final List<String> readings = <String>[];
|
||||
final List<PronunciationAudio> pronunciationAudios = <PronunciationAudio>[];
|
||||
|
||||
if (data['meanings'] != null) {
|
||||
for (final m in data['meanings'] as List) {
|
||||
@@ -129,11 +138,26 @@ class VocabularyItem {
|
||||
}
|
||||
}
|
||||
|
||||
if (data['pronunciation_audios'] != null) {
|
||||
for (final audio in data['pronunciation_audios'] as List) {
|
||||
final url = audio['url'] as String?;
|
||||
final metadata = audio['metadata'] as Map<String, dynamic>?;
|
||||
final gender = metadata?['gender'] as String?;
|
||||
|
||||
if (url != null && gender != null) {
|
||||
pronunciationAudios.add(PronunciationAudio(
|
||||
url: url,
|
||||
gender: gender,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VocabularyItem(
|
||||
id: id,
|
||||
characters: characters,
|
||||
meanings: meanings,
|
||||
readings: readings,
|
||||
);
|
||||
id: id,
|
||||
characters: characters,
|
||||
meanings: meanings,
|
||||
readings: readings,
|
||||
pronunciationAudios: pronunciationAudios);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user