part of 'data_entry.dart'; class KanjiEntry extends DataEntry { final String kanji; final List kana; KanjiEntry.fromJson(Map json) : kanji = json['kanji'] as String, kana = [ for (final j in json['kana'] as List) WordConstruct.fromJson(j) ]; @override String toString() { return '$kanji - ${kana.join('、')}'; } } class WordConstruct { final List pieces; WordConstruct({required this.pieces}); WordConstruct.fromJson(dynamic json) : pieces = (json is String) ? [WordPiece(word: json, isActive: true)] : [for (final j in json as List) WordPiece.fromJson(j)]; @override String toString() { return pieces.map((p) => p.isActive ? p.word : '(${p.word})').join(''); } } class WordPiece { final String? kana; final String? romaji; final String word; final bool isActive; const WordPiece({ required this.word, this.kana, this.romaji, this.isActive = false, }); WordPiece.fromJson(Map json) : kana = json['kana'] as String?, romaji = json['romaji'] as String?, word = json['text'] as String, isActive = json['active'] as bool? ?? false; }