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() +
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: <Widget>[
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,

View File

@ -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 = <Widget>[
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,

View File

@ -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<KanjiGradeSearch> {
sortedByStrokes.map<int, List<Widget>>(
(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(),
],
),
),
),

View File

@ -91,8 +91,7 @@ class _KanjiRadicalSearchState extends State<KanjiRadicalSearch> {
);
}
List<Widget> get radicalGridElements =>
<Widget>[
List<Widget> get radicalGridElements => <Widget>[
IconButton(
onPressed: () => setState(() {
suggestions.clear();
@ -103,22 +102,25 @@ class _KanjiRadicalSearchState extends State<KanjiRadicalSearch> {
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;

View File

@ -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<jisho.JishoAPIResult> fetchJishoResults(searchTerm) async {
return jisho.searchForPhrase(searchTerm);
}
Future<jisho.JishoAPIResult> fetchJishoResults(searchTerm) =>
jisho.searchForPhrase(searchTerm);