1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 05:57:28 +01:00

Connect multiple kanji parts with search (#33)

This commit is contained in:
Oystein Kristoffer Tveit 2022-01-23 21:29:54 +01:00 committed by GitHub
parent 3d30a81205
commit a577af2667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 37 deletions

View File

@ -31,7 +31,7 @@ class KanjiResultBody extends StatelessWidget {
children: [ children: [
const Flexible( const Flexible(
fit: FlexFit.tight, fit: FlexFit.tight,
child: Center(child: SizedBox()), child: SizedBox(),
), ),
Flexible( Flexible(
fit: FlexFit.tight, fit: FlexFit.tight,

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart'; import 'package:unofficial_jisho_api/api.dart';
import '../../../bloc/theme/theme_bloc.dart'; import '../../../bloc/theme/theme_bloc.dart';
import '../../../routing/routes.dart';
import '../../../services/romaji_transliteration.dart'; import '../../../services/romaji_transliteration.dart';
import '../../../settings.dart'; import '../../../settings.dart';
@ -73,7 +74,14 @@ class _Example extends StatelessWidget {
child: IntrinsicHeight( child: IntrinsicHeight(
child: Row( child: Row(
children: [ children: [
_Kana(colors: kanaColors, example: yomiExample), InkWell(
onTap: () => Navigator.pushNamed(
context,
Routes.search,
arguments: yomiExample.example,
),
child: _Kana(colors: kanaColors, example: yomiExample),
),
_ExampleText(colors: menuColors, example: yomiExample) _ExampleText(colors: menuColors, example: yomiExample)
], ],
), ),

View File

@ -18,16 +18,15 @@ class Header extends StatelessWidget {
final colors = state.theme.kanjiResultColor; final colors = state.theme.kanjiResultColor;
return Container( return Container(
alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
color: colors.background, color: colors.background,
), ),
child: Center(
child: Text( child: Text(
kanji, kanji,
style: TextStyle(fontSize: 70.0, color: colors.foreground), style: TextStyle(fontSize: 70.0, color: colors.foreground),
), ),
),
); );
}, },
), ),

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho; import 'package:unofficial_jisho_api/api.dart' as jisho;
import '../../../bloc/theme/theme_bloc.dart'; import '../../../bloc/theme/theme_bloc.dart';
import '../../../routing/routes.dart';
class Radical extends StatelessWidget { class Radical extends StatelessWidget {
final jisho.Radical radical; final jisho.Radical radical;
@ -16,7 +17,9 @@ class Radical extends StatelessWidget {
builder: (context, state) { builder: (context, state) {
final colors = state.theme.kanjiResultColor; final colors = state.theme.kanjiResultColor;
return Container( return InkWell(
onTap: () => Navigator.pushNamed(context, Routes.kanjiSearchRadicals, arguments: radical.symbol),
child: Container(
padding: const EdgeInsets.all(15.0), padding: const EdgeInsets.all(15.0),
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
@ -29,6 +32,7 @@ class Radical extends StatelessWidget {
fontSize: 40.0, fontSize: 40.0,
), ),
), ),
),
); );
}, },
); );

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../bloc/theme/theme_bloc.dart'; import '../../../bloc/theme/theme_bloc.dart';
import '../../../routing/routes.dart';
import '../../../services/romaji_transliteration.dart'; import '../../../services/romaji_transliteration.dart';
import '../../../settings.dart'; import '../../../settings.dart';
@ -50,10 +51,14 @@ class YomiChips extends StatelessWidget {
bool get isExpandable => yomi.length > 6; bool get isExpandable => yomi.length > 6;
Widget yomiCard({ Widget yomiCard({
required BuildContext context,
required String yomi, required String yomi,
required ColorSet colors, required ColorSet colors,
}) => }) =>
Container( InkWell(
onTap: () =>
Navigator.pushNamed(context, Routes.search, arguments: yomi),
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 5), margin: const EdgeInsets.symmetric(horizontal: 5),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 10.0, vertical: 10.0,
@ -70,17 +75,25 @@ class YomiChips extends StatelessWidget {
color: colors.foreground, color: colors.foreground,
), ),
), ),
),
); );
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)
.map((y) => yomiCard(yomi: y, colors: type.getColors(context))) .map(
(y) => yomiCard(
context: context,
yomi: y,
colors: type.getColors(context),
),
)
.toList(); .toList();
final yomiCardsWithTitle = <Widget>[ final yomiCardsWithTitle = <Widget>[
if (type != YomiType.meaning) if (type != YomiType.meaning)
yomiCard( yomiCard(
context: context,
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,
@ -101,7 +114,11 @@ class YomiChips extends StatelessWidget {
else else
return ExpansionTile( return ExpansionTile(
title: Center( title: Center(
child: yomiCard(yomi: type.title, colors: type.getColors(context)), child: yomiCard(
context: context,
yomi: type.title,
colors: type.getColors(context),
),
), ),
children: [ children: [
const SizedBox(height: 20.0), const SizedBox(height: 20.0),

View File

@ -34,7 +34,8 @@ Route<Widget> generateRoute(RouteSettings settings) {
return MaterialPageRoute(builder: (_) => const KanjiGradeSearch()); return MaterialPageRoute(builder: (_) => const KanjiGradeSearch());
case Routes.kanjiSearchRadicals: case Routes.kanjiSearchRadicals:
return MaterialPageRoute(builder: (_) => const KanjiRadicalSearch()); final prechosenRadical = args as String?;
return MaterialPageRoute(builder: (_) => KanjiRadicalSearch(prechosenRadical: prechosenRadical));
// TODO: Add more specific error screens. // TODO: Add more specific error screens.
case Routes.errorNotFound: case Routes.errorNotFound:

View File

@ -6,7 +6,9 @@ import '../../../../routing/routes.dart';
import '../../../../services/jisho_api/radicals_search.dart'; import '../../../../services/jisho_api/radicals_search.dart';
class KanjiRadicalSearch extends StatefulWidget { class KanjiRadicalSearch extends StatefulWidget {
const KanjiRadicalSearch({Key? key}) : super(key: key); final String? prechosenRadical;
const KanjiRadicalSearch({Key? key, this.prechosenRadical}) : super(key: key);
@override @override
_KanjiRadicalSearchState createState() => _KanjiRadicalSearchState(); _KanjiRadicalSearchState createState() => _KanjiRadicalSearchState();
@ -25,6 +27,15 @@ class _KanjiRadicalSearchState extends State<KanjiRadicalSearch> {
for (final String r in radicals.values.expand((l) => l)) r: true for (final String r in radicals.values.expand((l) => l)) r: true
}; };
@override
void initState() {
if (widget.prechosenRadical != null &&
radicalToggles.containsKey(widget.prechosenRadical))
radicalToggles[widget.prechosenRadical!] = true;
updateSuggestions();
super.initState();
}
void resetRadicalToggles() => radicalToggles.forEach((k, _) { void resetRadicalToggles() => radicalToggles.forEach((k, _) {
radicalToggles[k] = false; radicalToggles[k] = false;
}); });