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

Add grade based search

This commit is contained in:
Oystein Kristoffer Tveit 2022-01-17 14:43:10 +01:00
parent 32740dd7dd
commit e66e33b9ed
4 changed files with 759 additions and 12 deletions

631
lib/data/grades.dart Normal file
View File

@ -0,0 +1,631 @@
/// Jouyou kanji sorted primarily by grades and secondarliy by strokes.
const Map<int, Map<int, List<String>>> grades = {
1: {
1: [ '' ],
2: [
'', '', '',
'', '', '',
'', ''
],
3: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
''
],
4: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
'', ''
],
5: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
''
],
6: [
'', '', '',
'', '', '',
'', '', '',
'', '', ''
],
7: [
'', '', '',
'', '', '',
'', '', ''
],
8: [ '', '', '', '', '', '' ],
9: [ '', '' ],
10: [ '' ],
12: [ '' ]
},
2: {
2: [ '' ],
3: [ '', '', '', '', '' ],
4: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', ''
],
5: [
'', '', '',
'', '', '',
'', '', '',
'', '', ''
],
6: [
'', '', '', '',
'', '', '', '',
'西', '', '', '',
'', '', '', '',
'', '', '', ''
],
7: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', ''
],
8: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', ''
],
9: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', ''
],
10: [
'', '', '',
'', '', '',
'', '', '',
'', '', ''
],
11: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
''
],
12: [
'', '', '',
'', '', '',
'', '', '',
''
],
13: [
'', '',
'', '',
'', '',
''
],
14: [ '', '', '', '', '', '' ],
15: [ '' ],
16: [ '', '' ],
18: [ '', '' ]
},
3: {
2: [ '' ],
4: [ '', '', '', '' ],
5: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
''
],
6: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
'', ''
],
7: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
'', ''
],
8: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'使', '', '', '', '',
'', '', ''
],
9: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', ''
],
10: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', ''
],
11: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '宿', '', '',
'', '', ''
],
12: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', ''
],
13: [
'', '', '',
'', '', '',
'', '', '',
'', ''
],
14: [ '', '', '', '', '', '' ],
15: [ '', '調', '', '' ],
16: [ '', '', '', '' ],
18: [ '' ]
},
4: {
4: [ '', '', '', '', '' ],
5: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
'', ''
],
6: [
'', '', '',
'', '', '',
'', '', '',
'', '', ''
],
7: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', ''
],
8: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
''
],
9: [
'', '', '', '便',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', ''
],
10: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', ''
],
11: [
'', '', '', '',
'', '', '', '',
'', '', '鹿', '',
'', '', '', '',
'', '', ''
],
12: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', ''
],
13: [
'', '', '',
'', '', '',
'', '', '',
'', ''
],
14: [
'', '', '',
'', '', '',
'', '', '',
''
],
15: [
'', '', '',
'', '', '',
'', '', '',
''
],
16: [ '', '', '' ],
18: [ '', '', '' ],
19: [ '', '' ],
20: [ '', '' ]
},
5: {
3: [ '', '' ],
4: [ '', '', '' ],
5: [
'', '', '',
'', '', '',
'', '', '',
'', ''
],
6: [
'', '',
'', '',
'', '',
''
],
7: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', ''
],
8: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', ''
],
9: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
''
],
10: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', ''
],
11: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', ''
],
12: [
'貿', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', ''
],
13: [
'', '', '',
'', '', '',
'', '', '',
'', '', '',
'', ''
],
14: [
'', '', '綿', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', ''
],
15: [
'', '', '',
'', '', '',
'', ''
],
16: [ '', '', '', '', '' ],
17: [ '', '', '' ],
18: [ '', '', '' ],
19: [ '' ],
20: [ '' ]
},
6: {
3: [ '', '', '', '' ],
4: [ '', '', '', '' ],
5: [ '', '', '', '', '' ],
6: [
'', '', '',
'', '', '',
'', '', '',
''
],
7: [
'', '', '',
'', '', '',
'', '', '',
''
],
8: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '沿', ''
],
9: [
'', '', '', '',
'', '退', '', '',
'', '', '', '',
'姿', '', '', '',
'', '', '', '',
''
],
10: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', ''
],
11: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', ''
],
12: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', ''
],
13: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', ''
],
14: [
'', '', '',
'', '', '',
'', '', '',
'', '', ''
],
15: [
'', '', '',
'', '', '',
'', '', '',
''
],
16: [
'', '', '',
'', '', '',
'', ''
],
17: [ '', '', '', '' ],
18: [ '', '', '' ],
19: [ '', '' ]
},
7: {
1: [ '' ],
2: [ '', '' ],
3: [
'', '',
'', '',
'', '',
''
],
4: [
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', '',
'', '', '', ''
],
5: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '𠮟', '', '', '',
'', '', '', '', '',
'', '', ''
],
6: [
'', '', '', '', '', '',
'', '', '', '', '', '',
'', '', '', '', '', '',
'', '', '', '', '', '',
'', '', '', '', '', '',
'', '', '', '', '', '',
'', '', ''
],
7: [
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '尿', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '寿', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', ''
],
8: [
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
''
],
9: [
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', ''
],
10: [
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', ''
],
11: [
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', ''
],
12: [
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '婿', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '湿',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', ''
],
13: [
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '殿', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', ''
],
14: [
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', ''
],
15: [
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'稿', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', ''
],
16: [
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', '',
'', '', '', '', '', '', ''
],
17: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', ''
],
18: [
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', '', '', '', '',
'', ''
],
19: [
'', '', '', '',
'', '簿', '', '',
'', '', '', '',
'', '', '', '',
'', '', ''
],
20: [
'', '', '',
'', '', '',
'', ''
],
21: [ '', '', '', '', '', '' ],
22: [ '', '', '' ],
23: [ '' ],
29: [ '' ]
},
};

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'view/home.dart';
import 'view/screens/search/kanji_result_page.dart';
import 'view/screens/search/search_mechanisms/drawing.dart';
import 'view/screens/search/search_mechanisms/grade_list.dart';
import 'view/screens/search/search_mechanisms/radical_list.dart';
import 'view/screens/search/search_results_page.dart';
@ -28,6 +29,9 @@ Route<Widget> generateRoute(RouteSettings settings) {
case '/kanjiSearch/draw':
return MaterialPageRoute(builder: (_) => const KanjiDrawingSearch());
case '/kanjiSearch/grade':
return MaterialPageRoute(builder: (_) => const KanjiGradeSearch());
case '/kanjiSearch/radicals':
return MaterialPageRoute(builder: (_) => const KanjiRadicalSearch());

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
//TODO: Make buttons have an effect
import '../../../../bloc/theme/theme_bloc.dart';
class KanjiSearchOptionsBar extends StatelessWidget {
const KanjiSearchOptionsBar({Key? key}) : super(key: key);
@ -12,19 +12,16 @@ class KanjiSearchOptionsBar extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
_IconButton(
icon: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 18,
),
),
onPressed: () => Navigator.pushNamed(context, '/kanjiSearch/radicals'),
icon: const Icon(Icons.pie_chart),
onPressed: () =>
Navigator.pushNamed(context, '/kanjiSearch/radicals'),
),
const SizedBox(width: 10,),
_IconButton(
icon: const Icon(Icons.category),
onPressed: () {},
icon: const Icon(Icons.school),
onPressed: () => Navigator.pushNamed(context, '/kanjiSearch/grade'),
),
const SizedBox(width: 10,),
_IconButton(
icon: const Icon(Icons.mode),
onPressed: () => Navigator.pushNamed(context, '/kanjiSearch/draw'),
@ -47,6 +44,11 @@ class _IconButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return IconButton(onPressed: onPressed, icon: icon);
return IconButton(
onPressed: onPressed,
icon: icon,
iconSize: 30,
color: BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyDark.background,
);
}
}

View File

@ -0,0 +1,110 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../../../data/grades.dart';
import '../../../../models/themes/theme.dart';
class KanjiGradeSearch extends StatefulWidget {
const KanjiGradeSearch({Key? key}) : super(key: key);
@override
_KanjiGradeSearchState createState() => _KanjiGradeSearchState();
}
class _GridItem extends StatelessWidget {
final bool isNumber;
final String text;
const _GridItem({Key? key, required this.text, this.isNumber = false})
: super(key: key);
@override
Widget build(BuildContext context) {
final color = isNumber
? LightTheme.defaultMenuGreyDark
: LightTheme.defaultMenuGreyNormal;
final onTap = isNumber
? () => ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(text)),
)
: () =>
Navigator.popAndPushNamed(context, '/kanjiSearch', arguments: text);
return InkWell(
onTap: onTap,
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(5)),
color: color.background,
),
alignment: Alignment.center,
child: Text(
text,
style: TextStyle(
color: color.foreground,
fontSize: 25,
),
),
),
);
}
}
class _KanjiGradeSearchState extends State<KanjiGradeSearch> {
Future<Map<int, Map<int, List<Widget>>>> get gradeWidgets async => compute<
Map<int, Map<int, List<String>>>, Map<int, Map<int, List<Widget>>>>(
(gs) => gs.map(
(grade, sortedByStrokes) => MapEntry(
grade,
sortedByStrokes.map<int, List<Widget>>(
(strokeCount, kanji) => MapEntry(
strokeCount,
[_GridItem(text: strokeCount.toString(), isNumber: true)] +
kanji.map((k) => _GridItem(text: k)).toList(),
),
),
),
),
grades,
);
Future<Widget> get makeGrids async => SingleChildScrollView(
child: Column(
children: (await Future.wait(
grades.keys.map(
(grade) async => ExpansionTile(
title: Text(grade == 7 ? 'Junior Highschool' : 'Grade $grade'),
maintainState: true,
children: [
GridView.count(
crossAxisCount: 6,
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
padding: const EdgeInsets.all(10),
children: (await gradeWidgets)[grade]!
.values
.expand((l) => l)
.toList(),
)
],
),
),
))
.toList(),
),
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Choose by grade')),
body: FutureBuilder<Widget>(
future: makeGrids,
initialData: const Center(child: CircularProgressIndicator()),
builder: (context, snapshot) => snapshot.data!,
),
);
}
}