1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 13:37:29 +01:00

Small refactoring

This commit is contained in:
Oystein Kristoffer Tveit 2022-01-23 03:18:05 +01:00
parent b4a6b52e89
commit 7e8442881a
5 changed files with 60 additions and 52 deletions

View File

@ -23,22 +23,23 @@ class Examples extends StatelessWidget {
onyomi.map((onEx) => _Example(onEx, _KanaType.onyomi)).toList() + onyomi.map((onEx) => _Example(onEx, _KanaType.onyomi)).toList() +
kunyomi.map((kunEx) => _Example(kunEx, _KanaType.kunyomi)).toList(); kunyomi.map((kunEx) => _Example(kunEx, _KanaType.kunyomi)).toList();
const noExamplesWidget = [ const noExamplesWidget = Padding(
Padding( padding: EdgeInsets.symmetric(vertical: 10),
padding: EdgeInsets.symmetric(vertical: 10), child: Text('No Examples', style: textStyle),
child: Text('No Examples', style: textStyle), );
)
];
return Column( return Column(
children: <Widget>[ children: <Widget>[
Container( Container(
margin: const EdgeInsets.symmetric(horizontal: 10), margin: const EdgeInsets.symmetric(horizontal: 10),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: const Text('Examples:', style: textStyle), child: const Text('Examples:', style: textStyle),
) ),
] + if (onyomi.isEmpty && kunyomi.isEmpty)
(onyomi.isEmpty && kunyomi.isEmpty ? noExamplesWidget : yomiWidgets), noExamplesWidget
else
...yomiWidgets
],
); );
} }
} }
@ -89,7 +90,6 @@ class _Kana extends StatelessWidget {
required this.example, required this.example,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -105,7 +105,9 @@ class _Kana extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Text(
romajiEnabled ? transliterateKanaToLatin(example.reading) : example.reading, romajiEnabled
? transliterateKanaToLatin(example.reading)
: example.reading,
style: TextStyle( style: TextStyle(
color: colors.foreground, color: colors.foreground,
fontSize: 15.0, fontSize: 15.0,

View File

@ -70,7 +70,7 @@ class YomiChips extends StatelessWidget {
), ),
), ),
); );
Widget yomiWrapper(BuildContext context) { Widget yomiWrapper(BuildContext context) {
final yomiCards = yomi final yomiCards = yomi
.map((y) => romajiEnabled ? transliterateKanaToLatin(y) : y) .map((y) => romajiEnabled ? transliterateKanaToLatin(y) : y)
@ -78,16 +78,16 @@ class YomiChips extends StatelessWidget {
.toList(); .toList();
final yomiCardsWithTitle = <Widget>[ final yomiCardsWithTitle = <Widget>[
if (type != YomiType.meaning) if (type != YomiType.meaning)
yomiCard( yomiCard(
yomi: type == YomiType.kunyomi ? 'Kun:' : 'On:', yomi: type == YomiType.kunyomi ? 'Kun:' : 'On:',
colors: ColorSet( colors: ColorSet(
foreground: type.getColors(context).background, foreground: type.getColors(context).background,
background: const Color(0x000000ff), background: Colors.transparent,
), ),
), ),
] + ...yomiCards
yomiCards; ];
final wrap = Wrap( final wrap = Wrap(
runSpacing: 10.0, runSpacing: 10.0,

View File

@ -29,8 +29,11 @@ class _GridItem extends StatelessWidget {
? () => ScaffoldMessenger.of(context).showSnackBar( ? () => ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(text)), SnackBar(content: Text(text)),
) )
: () => : () => Navigator.popAndPushNamed(
Navigator.popAndPushNamed(context, Routes.kanjiSearch, arguments: text); context,
Routes.kanjiSearch,
arguments: text,
);
return InkWell( return InkWell(
onTap: onTap, onTap: onTap,
@ -61,8 +64,10 @@ class _KanjiGradeSearchState extends State<KanjiGradeSearch> {
sortedByStrokes.map<int, List<Widget>>( sortedByStrokes.map<int, List<Widget>>(
(strokeCount, kanji) => MapEntry( (strokeCount, kanji) => MapEntry(
strokeCount, 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(),
],
), ),
), ),
), ),

View File

@ -91,8 +91,7 @@ class _KanjiRadicalSearchState extends State<KanjiRadicalSearch> {
); );
} }
List<Widget> get radicalGridElements => List<Widget> get radicalGridElements => <Widget>[
<Widget>[
IconButton( IconButton(
onPressed: () => setState(() { onPressed: () => setState(() {
suggestions.clear(); suggestions.clear();
@ -103,22 +102,25 @@ class _KanjiRadicalSearchState extends State<KanjiRadicalSearch> {
color: AppTheme.jishoGreen.background, color: AppTheme.jishoGreen.background,
iconSize: fontSize * 1.3, iconSize: fontSize * 1.3,
), ),
] + ...radicals
radicals .map(
.map( (key, value) => MapEntry(
(key, value) => MapEntry( key,
key, value
value .where((r) => allowedToggles[r]!)
.where((r) => allowedToggles[r]!) .map((r) => radicalGridElement(r))
.map((r) => radicalGridElement(r)) .toList()
.toList() ..insert(
..insert(0, radicalGridElement(key.toString(), isNumber: true)), 0,
), radicalGridElement(key.toString(), isNumber: true),
) ),
.values ),
.where((element) => element.length != 1) )
.expand((l) => l) .values
.toList(); .where((element) => element.length != 1)
.expand((l) => l)
.toList()
];
Widget kanjiGridElement(String kanji) { Widget kanjiGridElement(String kanji) {
const color = LightTheme.defaultMenuGreyNormal; const color = LightTheme.defaultMenuGreyNormal;

View File

@ -1,6 +1,5 @@
import 'package:unofficial_jisho_api/api.dart' as jisho; 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<jisho.JishoAPIResult> fetchJishoResults(searchTerm) async { Future<jisho.JishoAPIResult> fetchJishoResults(searchTerm) =>
return jisho.searchForPhrase(searchTerm); jisho.searchForPhrase(searchTerm);
}