From 7e8442881ab9030a6bb89f053f02e8976c762e3f Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 23 Jan 2022 03:18:05 +0100 Subject: [PATCH] Small refactoring --- .../kanji/kanji_result_body/examples.dart | 32 ++++++++-------- .../kanji/kanji_result_body/yomi_chips.dart | 22 +++++------ .../search/search_mechanisms/grade_list.dart | 13 +++++-- .../search_mechanisms/radical_list.dart | 38 ++++++++++--------- lib/services/jisho_api/jisho_search.dart | 7 ++-- 5 files changed, 60 insertions(+), 52 deletions(-) diff --git a/lib/components/kanji/kanji_result_body/examples.dart b/lib/components/kanji/kanji_result_body/examples.dart index b9934a8..8e79cc0 100644 --- a/lib/components/kanji/kanji_result_body/examples.dart +++ b/lib/components/kanji/kanji_result_body/examples.dart @@ -23,22 +23,23 @@ class Examples extends StatelessWidget { onyomi.map((onEx) => _Example(onEx, _KanaType.onyomi)).toList() + kunyomi.map((kunEx) => _Example(kunEx, _KanaType.kunyomi)).toList(); - const noExamplesWidget = [ - Padding( - padding: EdgeInsets.symmetric(vertical: 10), - child: Text('No Examples', style: textStyle), - ) - ]; + const noExamplesWidget = Padding( + padding: EdgeInsets.symmetric(vertical: 10), + child: Text('No Examples', style: textStyle), + ); return Column( children: [ - Container( - margin: const EdgeInsets.symmetric(horizontal: 10), - alignment: Alignment.centerLeft, - child: const Text('Examples:', style: textStyle), - ) - ] + - (onyomi.isEmpty && kunyomi.isEmpty ? noExamplesWidget : yomiWidgets), + Container( + margin: const EdgeInsets.symmetric(horizontal: 10), + alignment: Alignment.centerLeft, + child: const Text('Examples:', style: textStyle), + ), + if (onyomi.isEmpty && kunyomi.isEmpty) + noExamplesWidget + else + ...yomiWidgets + ], ); } } @@ -89,7 +90,6 @@ class _Kana extends StatelessWidget { required this.example, }) : super(key: key); - @override Widget build(BuildContext context) { return Container( @@ -105,7 +105,9 @@ class _Kana extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - romajiEnabled ? transliterateKanaToLatin(example.reading) : example.reading, + romajiEnabled + ? transliterateKanaToLatin(example.reading) + : example.reading, style: TextStyle( color: colors.foreground, fontSize: 15.0, diff --git a/lib/components/kanji/kanji_result_body/yomi_chips.dart b/lib/components/kanji/kanji_result_body/yomi_chips.dart index c36ebda..941f0af 100644 --- a/lib/components/kanji/kanji_result_body/yomi_chips.dart +++ b/lib/components/kanji/kanji_result_body/yomi_chips.dart @@ -70,7 +70,7 @@ class YomiChips extends StatelessWidget { ), ), ); - + Widget yomiWrapper(BuildContext context) { final yomiCards = yomi .map((y) => romajiEnabled ? transliterateKanaToLatin(y) : y) @@ -78,16 +78,16 @@ class YomiChips extends StatelessWidget { .toList(); final yomiCardsWithTitle = [ - if (type != YomiType.meaning) - yomiCard( - yomi: type == YomiType.kunyomi ? 'Kun:' : 'On:', - colors: ColorSet( - foreground: type.getColors(context).background, - background: const Color(0x000000ff), - ), - ), - ] + - yomiCards; + if (type != YomiType.meaning) + yomiCard( + yomi: type == YomiType.kunyomi ? 'Kun:' : 'On:', + colors: ColorSet( + foreground: type.getColors(context).background, + background: Colors.transparent, + ), + ), + ...yomiCards + ]; final wrap = Wrap( runSpacing: 10.0, diff --git a/lib/screens/search/search_mechanisms/grade_list.dart b/lib/screens/search/search_mechanisms/grade_list.dart index 7404520..78154be 100644 --- a/lib/screens/search/search_mechanisms/grade_list.dart +++ b/lib/screens/search/search_mechanisms/grade_list.dart @@ -29,8 +29,11 @@ class _GridItem extends StatelessWidget { ? () => ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(text)), ) - : () => - Navigator.popAndPushNamed(context, Routes.kanjiSearch, arguments: text); + : () => Navigator.popAndPushNamed( + context, + Routes.kanjiSearch, + arguments: text, + ); return InkWell( onTap: onTap, @@ -61,8 +64,10 @@ class _KanjiGradeSearchState extends State { sortedByStrokes.map>( (strokeCount, kanji) => MapEntry( strokeCount, - [_GridItem(text: strokeCount.toString(), isNumber: true)] + - kanji.map((k) => _GridItem(text: k)).toList(), + [ + _GridItem(text: strokeCount.toString(), isNumber: true), + ...kanji.map((k) => _GridItem(text: k)).toList(), + ], ), ), ), diff --git a/lib/screens/search/search_mechanisms/radical_list.dart b/lib/screens/search/search_mechanisms/radical_list.dart index 87171ae..a8d08a5 100644 --- a/lib/screens/search/search_mechanisms/radical_list.dart +++ b/lib/screens/search/search_mechanisms/radical_list.dart @@ -91,8 +91,7 @@ class _KanjiRadicalSearchState extends State { ); } - List get radicalGridElements => - [ + List get radicalGridElements => [ IconButton( onPressed: () => setState(() { suggestions.clear(); @@ -103,22 +102,25 @@ class _KanjiRadicalSearchState extends State { color: AppTheme.jishoGreen.background, iconSize: fontSize * 1.3, ), - ] + - radicals - .map( - (key, value) => MapEntry( - key, - value - .where((r) => allowedToggles[r]!) - .map((r) => radicalGridElement(r)) - .toList() - ..insert(0, radicalGridElement(key.toString(), isNumber: true)), - ), - ) - .values - .where((element) => element.length != 1) - .expand((l) => l) - .toList(); + ...radicals + .map( + (key, value) => MapEntry( + key, + value + .where((r) => allowedToggles[r]!) + .map((r) => radicalGridElement(r)) + .toList() + ..insert( + 0, + radicalGridElement(key.toString(), isNumber: true), + ), + ), + ) + .values + .where((element) => element.length != 1) + .expand((l) => l) + .toList() + ]; Widget kanjiGridElement(String kanji) { const color = LightTheme.defaultMenuGreyNormal; diff --git a/lib/services/jisho_api/jisho_search.dart b/lib/services/jisho_api/jisho_search.dart index 3459bda..3df4c01 100644 --- a/lib/services/jisho_api/jisho_search.dart +++ b/lib/services/jisho_api/jisho_search.dart @@ -1,6 +1,5 @@ import 'package:unofficial_jisho_api/api.dart' as jisho; -export 'package:unofficial_jisho_api/api.dart' show JishoAPIResult; +export 'package:unofficial_jisho_api/api.dart' show JishoAPIResult; -Future fetchJishoResults(searchTerm) async { - return jisho.searchForPhrase(searchTerm); -} +Future fetchJishoResults(searchTerm) => + jisho.searchForPhrase(searchTerm);