1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 21:47:29 +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,15 +18,14 @@ 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,17 +17,20 @@ class Radical extends StatelessWidget {
builder: (context, state) { builder: (context, state) {
final colors = state.theme.kanjiResultColor; final colors = state.theme.kanjiResultColor;
return Container( return InkWell(
padding: const EdgeInsets.all(15.0), onTap: () => Navigator.pushNamed(context, Routes.kanjiSearchRadicals, arguments: radical.symbol),
decoration: BoxDecoration( child: Container(
shape: BoxShape.circle, padding: const EdgeInsets.all(15.0),
color: colors.background, decoration: BoxDecoration(
), shape: BoxShape.circle,
child: Text( color: colors.background,
radical.symbol, ),
style: TextStyle( child: Text(
color: colors.foreground, radical.symbol,
fontSize: 40.0, style: TextStyle(
color: colors.foreground,
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,24 +51,29 @@ 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(
margin: const EdgeInsets.symmetric(horizontal: 5), onTap: () =>
padding: const EdgeInsets.symmetric( Navigator.pushNamed(context, Routes.search, arguments: yomi),
vertical: 10.0, child: Container(
horizontal: 10.0, margin: const EdgeInsets.symmetric(horizontal: 5),
), padding: const EdgeInsets.symmetric(
decoration: BoxDecoration( vertical: 10.0,
color: colors.background, horizontal: 10.0,
borderRadius: BorderRadius.circular(10.0), ),
), decoration: BoxDecoration(
child: Text( color: colors.background,
yomi, borderRadius: BorderRadius.circular(10.0),
style: TextStyle( ),
fontSize: 20.0, child: Text(
color: colors.foreground, yomi,
style: TextStyle(
fontSize: 20.0,
color: colors.foreground,
),
), ),
), ),
); );
@ -75,12 +81,19 @@ 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)
.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;
}); });