Refactoring and cleaning
This commit is contained in:
parent
859b7753af
commit
17d6f862a2
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../models/themes/theme.dart';
|
||||
import '../../models/themes/theme.dart';
|
||||
|
||||
class SplashScreen extends StatelessWidget {
|
||||
const SplashScreen({Key? key}) : super(key: key);
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:signature/signature.dart';
|
||||
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../services/handwriting.dart';
|
||||
import '../../bloc/theme/theme_bloc.dart';
|
||||
import '../../services/handwriting.dart';
|
||||
|
||||
class DrawingBoard extends StatefulWidget {
|
||||
final Function(String)? onSuggestionChosen;
|
|
@ -1,49 +1,44 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../models/themes/theme.dart';
|
||||
import '../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class DateDivider extends StatelessWidget {
|
||||
final String? text;
|
||||
final DateTime? date;
|
||||
final EdgeInsets? margin;
|
||||
|
||||
const DateDivider({
|
||||
this.text,
|
||||
this.date,
|
||||
this.margin = const EdgeInsets.symmetric(vertical: 10),
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
}) : assert((text == null) ^ (date == null)),
|
||||
super(key: key);
|
||||
|
||||
String getHumanReadableDate(DateTime date) {
|
||||
const Map<int, String> monthTable = {
|
||||
1: 'Jan',
|
||||
2: 'Feb',
|
||||
3: 'Mar',
|
||||
4: 'Apr',
|
||||
5: 'May',
|
||||
6: 'Jun',
|
||||
7: 'Jul',
|
||||
8: 'Aug',
|
||||
9: 'Sep',
|
||||
10: 'Oct',
|
||||
11: 'Nov',
|
||||
12: 'Dec',
|
||||
};
|
||||
const List<String> monthTable = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
|
||||
final int day = date.day;
|
||||
final String month = monthTable[date.month]!;
|
||||
final String month = monthTable[date.month - 1];
|
||||
final int year = date.year;
|
||||
return '$day. $month $year';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Widget header = (text != null)
|
||||
? Text(text!)
|
||||
: (date != null)
|
||||
? Text(getHumanReadableDate(date!))
|
||||
: const SizedBox.shrink();
|
||||
final Widget header =
|
||||
(text != null) ? Text(text!) : Text(getHumanReadableDate(date!));
|
||||
|
||||
final ColorSet _menuColors =
|
||||
BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyNormal;
|
||||
|
@ -54,7 +49,6 @@ class DateDivider extends StatelessWidget {
|
|||
vertical: 5,
|
||||
horizontal: 10,
|
||||
),
|
||||
margin: margin,
|
||||
child: DefaultTextStyle.merge(
|
||||
child: header,
|
||||
style: TextStyle(color: _menuColors.foreground),
|
|
@ -0,0 +1,42 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class KanjiBox extends StatelessWidget {
|
||||
final String kanji;
|
||||
|
||||
const KanjiBox({
|
||||
Key? key,
|
||||
required this.kanji,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ColorSet menuColors =
|
||||
BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyLight;
|
||||
|
||||
return IntrinsicHeight(
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: menuColors.background,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: Center(
|
||||
child: FittedBox(
|
||||
child: Text(
|
||||
kanji,
|
||||
style: TextStyle(
|
||||
color: menuColors.foreground,
|
||||
fontSize: 25,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
|
||||
import '../../models/history/search.dart';
|
||||
|
||||
class SearchItem extends StatelessWidget {
|
||||
final DateTime time;
|
||||
final Widget search;
|
||||
final int objectKey;
|
||||
final void Function()? onDelete;
|
||||
final void Function()? onFavourite;
|
||||
final void Function()? onTap;
|
||||
|
||||
const SearchItem({
|
||||
required this.time,
|
||||
required this.search,
|
||||
required this.objectKey,
|
||||
this.onDelete,
|
||||
this.onFavourite,
|
||||
this.onTap,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
String getTime() {
|
||||
final hours = time.hour.toString().padLeft(2, '0');
|
||||
final mins = time.minute.toString().padLeft(2, '0');
|
||||
return '$hours:$mins';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Slidable(
|
||||
endActionPane: ActionPane(
|
||||
motion: const ScrollMotion(),
|
||||
children: [
|
||||
SlidableAction(
|
||||
label: 'Favourite',
|
||||
backgroundColor: Colors.yellow,
|
||||
icon: Icons.star,
|
||||
onPressed: (_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('TODO: implement favourites')),
|
||||
);
|
||||
onFavourite?.call();
|
||||
},
|
||||
),
|
||||
SlidableAction(
|
||||
label: 'Delete',
|
||||
backgroundColor: Colors.red,
|
||||
icon: Icons.delete,
|
||||
onPressed: (_) {
|
||||
final Database db = GetIt.instance.get<Database>();
|
||||
Search.store.record(objectKey).delete(db);
|
||||
onDelete?.call();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: ListTile(
|
||||
onTap: onTap,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text(getTime()),
|
||||
),
|
||||
search,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -24,34 +24,61 @@ class KanjiResultBody extends StatelessWidget {
|
|||
resultData = result.data!;
|
||||
}
|
||||
|
||||
Widget get headerRow => Container(
|
||||
margin: const EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 30.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
const Flexible(
|
||||
fit: FlexFit.tight,
|
||||
child: Center(child: SizedBox()),
|
||||
),
|
||||
Flexible(
|
||||
fit: FlexFit.tight,
|
||||
child: Center(child: Header(kanji: query)),
|
||||
),
|
||||
Flexible(
|
||||
fit: FlexFit.tight,
|
||||
child: Center(
|
||||
child: (resultData.radical != null)
|
||||
? Radical(radical: resultData.radical!)
|
||||
: const SizedBox(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget get rankingColumn => Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('JLPT: ', style: TextStyle(fontSize: 20.0)),
|
||||
JlptLevel(jlptLevel: resultData.jlptLevel ?? '⨉'),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Grade: ', style: TextStyle(fontSize: 20.0)),
|
||||
Grade(grade: resultData.taughtIn),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Rank: ', style: TextStyle(fontSize: 20.0)),
|
||||
Rank(rank: resultData.newspaperFrequencyRank),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 30.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
const Flexible(
|
||||
fit: FlexFit.tight,
|
||||
child: Center(child: SizedBox()),
|
||||
),
|
||||
Flexible(
|
||||
fit: FlexFit.tight,
|
||||
child: Center(child: Header(kanji: query)),
|
||||
),
|
||||
Flexible(
|
||||
fit: FlexFit.tight,
|
||||
child: Center(
|
||||
child: (resultData.radical != null)
|
||||
? Radical(radical: resultData.radical!)
|
||||
: const SizedBox(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
headerRow,
|
||||
YomiChips(yomi: resultData.meaning.split(', '), type: YomiType.meaning),
|
||||
(resultData.onyomi.isNotEmpty)
|
||||
? YomiChips(yomi: resultData.onyomi, type: YomiType.onyomi)
|
||||
|
@ -64,30 +91,7 @@ class KanjiResultBody extends StatelessWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
StrokeOrderGif(uri: resultData.strokeOrderGifUri),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('JLPT: ', style: TextStyle(fontSize: 20.0)),
|
||||
JlptLevel(jlptLevel: resultData.jlptLevel ?? '⨉'),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Grade: ', style: TextStyle(fontSize: 20.0)),
|
||||
Grade(grade: resultData.taughtIn ?? '⨉'),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Rank: ', style: TextStyle(fontSize: 20.0)),
|
||||
Rank(rank: resultData.newspaperFrequencyRank ?? -1),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
rankingColumn,
|
||||
],
|
||||
),
|
||||
),
|
|
@ -0,0 +1,153 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:unofficial_jisho_api/api.dart';
|
||||
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class Examples extends StatelessWidget {
|
||||
final List<YomiExample> onyomi;
|
||||
final List<YomiExample> kunyomi;
|
||||
|
||||
const Examples({
|
||||
required this.onyomi,
|
||||
required this.kunyomi,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const textStyle = TextStyle(fontSize: 20);
|
||||
|
||||
final yomiWidgets =
|
||||
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),
|
||||
)
|
||||
];
|
||||
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum _KanaType { kunyomi, onyomi }
|
||||
|
||||
class _Example extends StatelessWidget {
|
||||
final _KanaType kanaType;
|
||||
final YomiExample yomiExample;
|
||||
|
||||
const _Example(this.yomiExample, this.kanaType);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = BlocProvider.of<ThemeBloc>(context).state.theme;
|
||||
final menuColors = theme.menuGreyNormal;
|
||||
final kanaColors =
|
||||
kanaType == _KanaType.kunyomi ? theme.kunyomiColor : theme.onyomiColor;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
vertical: 5.0,
|
||||
horizontal: 10.0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: menuColors.background,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: IntrinsicHeight(
|
||||
child: Row(
|
||||
children: [
|
||||
_Kana(colors: kanaColors, example: yomiExample),
|
||||
_ExampleText(colors: menuColors, example: yomiExample)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Kana extends StatelessWidget {
|
||||
final ColorSet colors;
|
||||
final YomiExample example;
|
||||
|
||||
const _Kana({
|
||||
Key? key,
|
||||
required this.colors,
|
||||
required this.example,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.background,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(10.0),
|
||||
bottomLeft: Radius.circular(10.0),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
example.reading,
|
||||
style: TextStyle(
|
||||
color: colors.foreground,
|
||||
fontSize: 15.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5.0),
|
||||
Text(
|
||||
example.example,
|
||||
style: TextStyle(
|
||||
color: colors.foreground,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ExampleText extends StatelessWidget {
|
||||
final ColorSet colors;
|
||||
final YomiExample example;
|
||||
|
||||
const _ExampleText({
|
||||
Key? key,
|
||||
required this.colors,
|
||||
required this.example,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Wrap(
|
||||
children: [
|
||||
Text(
|
||||
example.meaning,
|
||||
style: TextStyle(
|
||||
color: colors.foreground,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class Grade extends StatelessWidget {
|
||||
final String? grade;
|
||||
final String ifNullChar;
|
||||
|
||||
const Grade({
|
||||
required this.grade,
|
||||
this.ifNullChar = '⨉',
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors =
|
||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.background,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Text(
|
||||
grade ?? ifNullChar,
|
||||
style: TextStyle(
|
||||
color: colors.foreground,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class Header extends StatelessWidget {
|
||||
final String kanji;
|
||||
|
@ -12,7 +12,7 @@ class Header extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _kanjiColors =
|
||||
final colors =
|
||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
|
||||
return AspectRatio(
|
||||
|
@ -20,12 +20,12 @@ class Header extends StatelessWidget {
|
|||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
color: _kanjiColors.background,
|
||||
color: colors.background,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
kanji,
|
||||
style: TextStyle(fontSize: 70.0, color: _kanjiColors.foreground),
|
||||
style: TextStyle(fontSize: 70.0, color: colors.foreground),
|
||||
),
|
||||
),
|
||||
),
|
|
@ -1,30 +1,32 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class JlptLevel extends StatelessWidget {
|
||||
final String jlptLevel;
|
||||
final String? jlptLevel;
|
||||
final String ifNullChar;
|
||||
|
||||
const JlptLevel({
|
||||
required this.jlptLevel,
|
||||
this.ifNullChar = '⨉',
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _kanjiColors =
|
||||
final colors =
|
||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _kanjiColors.background,
|
||||
color: colors.background,
|
||||
),
|
||||
child: Text(
|
||||
jlptLevel,
|
||||
jlptLevel ?? ifNullChar,
|
||||
style: TextStyle(
|
||||
color: _kanjiColors.foreground,
|
||||
color: colors.foreground,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
|
@ -1,28 +1,27 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:unofficial_jisho_api/api.dart' as jisho;
|
||||
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class Radical extends StatelessWidget {
|
||||
final jisho.Radical radical;
|
||||
|
||||
const Radical({required this.radical, Key? key,}) : super(key: key);
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _kanjiColors = BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
final colors = BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _kanjiColors.background,
|
||||
color: colors.background,
|
||||
),
|
||||
child: Text(
|
||||
radical.symbol,
|
||||
style: TextStyle(
|
||||
color: _kanjiColors.foreground,
|
||||
color: colors.foreground,
|
||||
fontSize: 40.0,
|
||||
),
|
||||
),
|
|
@ -0,0 +1,36 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class Rank extends StatelessWidget {
|
||||
final int? rank;
|
||||
final String ifNullChar;
|
||||
|
||||
const Rank({
|
||||
required this.rank,
|
||||
this.ifNullChar = '⨉',
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors =
|
||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
decoration: BoxDecoration(
|
||||
shape: (rank == null) ? BoxShape.circle : BoxShape.rectangle,
|
||||
borderRadius: (rank == null) ? null : BorderRadius.circular(10.0),
|
||||
color: colors.background,
|
||||
),
|
||||
child: Text(
|
||||
rank != null ? '${rank.toString()} / 2500' : ifNullChar,
|
||||
style: TextStyle(
|
||||
color: colors.foreground,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class StrokeOrderGif extends StatelessWidget {
|
||||
final String uri;
|
||||
|
@ -10,13 +10,13 @@ class StrokeOrderGif extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _kanjiColors = BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
final colors = BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 20.0),
|
||||
padding: const EdgeInsets.all(5.0),
|
||||
decoration: BoxDecoration(
|
||||
color: _kanjiColors.background,
|
||||
color: colors.background,
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
),
|
||||
child: ClipRRect(
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
enum YomiType {
|
||||
onyomi,
|
||||
|
@ -47,18 +47,17 @@ class YomiChips extends StatelessWidget {
|
|||
bool get isExpandable => yomi.length > 6;
|
||||
|
||||
Widget yomiCard({
|
||||
required BuildContext context,
|
||||
required String yomi,
|
||||
required ColorSet colors,
|
||||
}) =>
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 5),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10.0,
|
||||
horizontal: 10.0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: type.getColors(context).background,
|
||||
color: colors.background,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: Text(
|
||||
|
@ -72,41 +71,38 @@ class YomiChips extends StatelessWidget {
|
|||
|
||||
Widget yomiWrapper(BuildContext context) {
|
||||
final yomiCards = yomi
|
||||
.map(
|
||||
(y) => yomiCard(
|
||||
context: context,
|
||||
yomi: y,
|
||||
colors: type.getColors(context),
|
||||
),
|
||||
)
|
||||
.map((y) => yomiCard(yomi: y, colors: type.getColors(context)))
|
||||
.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;
|
||||
|
||||
final wrap = Wrap(
|
||||
runSpacing: 10.0,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: yomiCardsWithTitle,
|
||||
);
|
||||
|
||||
if (!isExpandable)
|
||||
return Wrap(
|
||||
runSpacing: 10.0,
|
||||
children: yomiCards,
|
||||
);
|
||||
return wrap;
|
||||
else
|
||||
return ExpansionTile(
|
||||
// initiallyExpanded: false,
|
||||
title: Center(
|
||||
child: yomiCard(
|
||||
context: context,
|
||||
yomi: type.title,
|
||||
colors: type.getColors(context),
|
||||
),
|
||||
child: yomiCard(yomi: type.title, colors: type.getColors(context)),
|
||||
),
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 20.0,
|
||||
),
|
||||
Wrap(
|
||||
runSpacing: 10.0,
|
||||
children: yomiCards,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 25.0,
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
wrap,
|
||||
const SizedBox(height: 25.0),
|
||||
],
|
||||
);
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:animated_size_and_fade/animated_size_and_fade.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../services/kanji_suggestions.dart';
|
||||
import '../../services/kanji_suggestions.dart';
|
||||
import 'kanji_search_body/kanji_grid.dart';
|
||||
import 'kanji_search_body/kanji_search_bar.dart';
|
||||
import 'kanji_search_body/kanji_search_options_bar.dart';
|
||||
|
@ -59,7 +59,7 @@ class _KanjiSearchBodyState extends State<KanjiSearchBody>
|
|||
}
|
||||
return true;
|
||||
},
|
||||
child: GestureDetector(
|
||||
child: InkWell(
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(),
|
||||
|
@ -89,6 +89,7 @@ class _KanjiSearchBodyState extends State<KanjiSearchBody>
|
|||
}),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
AnimatedSizeAndFade(
|
||||
fadeDuration: const Duration(milliseconds: 200),
|
||||
sizeDuration: const Duration(milliseconds: 300),
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../routing/routes.dart';
|
||||
|
||||
class KanjiGrid extends StatelessWidget {
|
||||
final List<String> suggestions;
|
||||
|
@ -33,7 +34,7 @@ class _GridItem extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, '/kanjiSearch', arguments: kanji);
|
||||
Navigator.pushNamed(context, Routes.kanjiSearch, arguments: kanji);
|
||||
},
|
||||
child: BlocBuilder<ThemeBloc, ThemeState>(
|
||||
builder: (context, state) {
|
|
@ -21,20 +21,18 @@ class KanjiSearchBarState extends State<KanjiSearchBar> {
|
|||
super.initState();
|
||||
}
|
||||
|
||||
void runOnChanged() {
|
||||
if (widget.onChanged != null) widget.onChanged!(textController.text);
|
||||
}
|
||||
void onChanged() => widget.onChanged?.call(textController.text);
|
||||
|
||||
void clearText() {
|
||||
textController.text = '';
|
||||
runOnChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
Future<void> pasteText() async {
|
||||
final ClipboardData? clipboardData = await Clipboard.getData('text/plain');
|
||||
if (clipboardData != null && clipboardData.text != null) {
|
||||
textController.text = clipboardData.text!;
|
||||
runOnChanged();
|
||||
onChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,15 +50,11 @@ class KanjiSearchBarState extends State<KanjiSearchBar> {
|
|||
|
||||
return TextField(
|
||||
controller: textController,
|
||||
onChanged: (text) {
|
||||
if (widget.onChanged != null) widget.onChanged!(text);
|
||||
},
|
||||
onChanged: (text) => onChanged(),
|
||||
onSubmitted: (_) => {},
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
hintText: 'Search',
|
||||
// fillColor: Colors.white,
|
||||
// filled: true,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../routing/routes.dart';
|
||||
|
||||
class KanjiSearchOptionsBar extends StatelessWidget {
|
||||
const KanjiSearchOptionsBar({Key? key}) : super(key: key);
|
||||
|
@ -14,17 +15,17 @@ class KanjiSearchOptionsBar extends StatelessWidget {
|
|||
_IconButton(
|
||||
icon: const Icon(Icons.pie_chart),
|
||||
onPressed: () =>
|
||||
Navigator.pushNamed(context, '/kanjiSearch/radicals'),
|
||||
Navigator.pushNamed(context, Routes.kanjiSearchRadicals),
|
||||
),
|
||||
const SizedBox(width: 10,),
|
||||
const SizedBox(width: 10),
|
||||
_IconButton(
|
||||
icon: const Icon(Icons.school),
|
||||
onPressed: () => Navigator.pushNamed(context, '/kanjiSearch/grade'),
|
||||
onPressed: () => Navigator.pushNamed(context, Routes.kanjiSearchGrade),
|
||||
),
|
||||
const SizedBox(width: 10,),
|
||||
const SizedBox(width: 10),
|
||||
_IconButton(
|
||||
icon: const Icon(Icons.mode),
|
||||
onPressed: () => Navigator.pushNamed(context, '/kanjiSearch/draw'),
|
||||
onPressed: () => Navigator.pushNamed(context, Routes.kanjiSearchDraw),
|
||||
),
|
||||
],
|
||||
),
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../models/themes/theme.dart';
|
||||
import '../../models/themes/theme.dart';
|
||||
|
||||
class LanguageSelector extends StatefulWidget {
|
||||
const LanguageSelector({Key? key}) : super(key: key);
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../routing/routes.dart';
|
||||
import 'language_selector.dart';
|
||||
|
||||
class SearchBar extends StatelessWidget {
|
||||
|
@ -13,7 +14,7 @@ class SearchBar extends StatelessWidget {
|
|||
children: [
|
||||
TextField(
|
||||
onSubmitted: (text) =>
|
||||
Navigator.pushNamed(context, '/search', arguments: text),
|
||||
Navigator.pushNamed(context, Routes.search, arguments: text),
|
||||
controller: TextEditingController(),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Search',
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:unofficial_jisho_api/api.dart';
|
||||
|
||||
import '../../../../../bloc/theme/theme_bloc.dart';
|
||||
import '../../../../bloc/theme/theme_bloc.dart';
|
||||
|
||||
class OtherForms extends StatelessWidget {
|
||||
final List<JishoJapaneseWord> forms;
|
|
@ -9,7 +9,7 @@ import 'package:sembast/sembast_io.dart';
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'bloc/theme/theme_bloc.dart';
|
||||
import 'router.dart';
|
||||
import 'routing/router.dart';
|
||||
|
||||
Future<void> setupDatabase() async {
|
||||
final Directory appDocDir = await getApplicationDocumentsDirectory();
|
||||
|
|
|
@ -3,6 +3,9 @@ import 'package:sembast/sembast.dart';
|
|||
import './kanji_query.dart';
|
||||
import './word_query.dart';
|
||||
|
||||
export 'package:get_it/get_it.dart';
|
||||
export 'package:sembast/sembast.dart';
|
||||
|
||||
class Search {
|
||||
final DateTime timestamp;
|
||||
final WordQuery? wordQuery;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import './word_result.dart';
|
||||
|
||||
class WordQuery {
|
||||
final String query;
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
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';
|
||||
|
||||
Route<Widget> generateRoute(RouteSettings settings) {
|
||||
final args = settings.arguments;
|
||||
|
||||
switch (settings.name) {
|
||||
case '/':
|
||||
return MaterialPageRoute(builder: (_) => const Home());
|
||||
|
||||
case '/search':
|
||||
final searchTerm = args! as String;
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => SearchResultsPage(searchTerm: searchTerm),
|
||||
);
|
||||
|
||||
case '/kanjiSearch':
|
||||
final searchTerm = args! as String;
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => KanjiResultPage(kanjiSearchTerm: searchTerm),
|
||||
);
|
||||
|
||||
case '/kanjiSearch/draw':
|
||||
return MaterialPageRoute(builder: (_) => const KanjiDrawingSearch());
|
||||
|
||||
case '/kanjiSearch/grade':
|
||||
return MaterialPageRoute(builder: (_) => const KanjiGradeSearch());
|
||||
|
||||
case '/kanjiSearch/radicals':
|
||||
return MaterialPageRoute(builder: (_) => const KanjiRadicalSearch());
|
||||
|
||||
default:
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => const Text('ERROR: this route does not exist'),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../screens/home.dart';
|
||||
import '../screens/search/kanji_result_page.dart';
|
||||
import '../screens/search/search_mechanisms/drawing.dart';
|
||||
import '../screens/search/search_mechanisms/grade_list.dart';
|
||||
import '../screens/search/search_mechanisms/radical_list.dart';
|
||||
import '../screens/search/search_results_page.dart';
|
||||
import 'routes.dart';
|
||||
|
||||
Route<Widget> generateRoute(RouteSettings settings) {
|
||||
final args = settings.arguments;
|
||||
|
||||
switch (settings.name) {
|
||||
case Routes.root:
|
||||
return MaterialPageRoute(builder: (_) => const Home());
|
||||
|
||||
case Routes.search:
|
||||
final searchTerm = args! as String;
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => SearchResultsPage(searchTerm: searchTerm),
|
||||
);
|
||||
|
||||
case Routes.kanjiSearch:
|
||||
final searchTerm = args! as String;
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => KanjiResultPage(kanjiSearchTerm: searchTerm),
|
||||
);
|
||||
|
||||
case Routes.kanjiSearchDraw:
|
||||
return MaterialPageRoute(builder: (_) => const KanjiDrawingSearch());
|
||||
|
||||
case Routes.kanjiSearchGrade:
|
||||
return MaterialPageRoute(builder: (_) => const KanjiGradeSearch());
|
||||
|
||||
case Routes.kanjiSearchRadicals:
|
||||
return MaterialPageRoute(builder: (_) => const KanjiRadicalSearch());
|
||||
|
||||
// TODO: Add more specific error screens.
|
||||
case Routes.errorNotFound:
|
||||
case Routes.errorNetwork:
|
||||
case Routes.errorOther:
|
||||
default:
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => Scaffold(
|
||||
appBar:
|
||||
AppBar(title: const Text('Error'), backgroundColor: Colors.red),
|
||||
body: Center(child: ErrorWidget('Some kind of error occured')),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
class Routes {
|
||||
static const String root = '/';
|
||||
static const String search = '/search';
|
||||
static const String kanjiSearch = '/kanjiSearch';
|
||||
static const String kanjiSearchDraw = '/kanjiSearch/draw';
|
||||
static const String kanjiSearchGrade = '/kanjiSearch/grade';
|
||||
static const String kanjiSearchRadicals = '/kanjiSearch/radicals';
|
||||
static const String errorNotFound = '/error/404';
|
||||
static const String errorNetwork = '/error/network';
|
||||
static const String errorOther = '/error/other';
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../components/drawing_board/drawing_board.dart';
|
||||
|
||||
class DebugView extends StatelessWidget {
|
||||
const DebugView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
DrawingBoard(
|
||||
allowHiragana: true,
|
||||
allowKatakana: true,
|
||||
allowOther: true,
|
||||
onSuggestionChosen: (s) => ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Chose: $s'),
|
||||
duration: const Duration(milliseconds: 600),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../components/common/loading.dart';
|
||||
import '../components/common/opaque_box.dart';
|
||||
import '../components/history/date_divider.dart';
|
||||
import '../components/history/kanji_box.dart';
|
||||
import '../components/history/search_item.dart';
|
||||
import '../models/history/search.dart';
|
||||
import '../routing/routes.dart';
|
||||
|
||||
class HistoryView extends StatelessWidget {
|
||||
const HistoryView({Key? key}) : super(key: key);
|
||||
|
||||
Database get _db => GetIt.instance.get<Database>();
|
||||
|
||||
Stream<Map<int, Search>> get searchStream => Search.store
|
||||
.query(finder: Finder(sortOrders: [SortOrder('timestamp', false)]))
|
||||
.onSnapshots(_db)
|
||||
.map(
|
||||
(snapshot) => Map.fromEntries(
|
||||
snapshot.where((snap) => snap.value != null).map(
|
||||
(snap) => MapEntry(
|
||||
snap.key,
|
||||
Search.fromJson(snap.value! as Map<String, Object?>),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder<Map<int, Search>>(
|
||||
stream: searchStream,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) return const LoadingScreen();
|
||||
|
||||
final Map<int, Search> data = snapshot.data!;
|
||||
if (data.isEmpty)
|
||||
return const Center(
|
||||
child: Text('The history is empty.\nTry searching for something!'),
|
||||
);
|
||||
|
||||
return OpaqueBox(
|
||||
child: ListView.separated(
|
||||
itemCount: data.length + 1,
|
||||
itemBuilder: historyEntryWithData(data),
|
||||
separatorBuilder:
|
||||
historyEntrySeparatorWithData(data.values.toList()),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget Function(BuildContext, int) historyEntryWithData(
|
||||
Map<int, Search> data,
|
||||
) =>
|
||||
(context, index) {
|
||||
if (index == 0) return const SizedBox.shrink();
|
||||
|
||||
final Search search = data.values.toList()[index - 1];
|
||||
final int objectKey = data.keys.toList()[index - 1];
|
||||
|
||||
late final Widget child;
|
||||
late final void Function() onTap;
|
||||
|
||||
if (search.isKanji) {
|
||||
child = KanjiBox(kanji: search.kanjiQuery!.kanji);
|
||||
onTap = () => Navigator.pushNamed(
|
||||
context,
|
||||
Routes.kanjiSearch,
|
||||
arguments: search.kanjiQuery!.kanji,
|
||||
);
|
||||
} else {
|
||||
child = Text(search.wordQuery!.query);
|
||||
onTap = () => Navigator.pushNamed(
|
||||
context,
|
||||
Routes.search,
|
||||
arguments: search.wordQuery!.query,
|
||||
);
|
||||
}
|
||||
|
||||
return SearchItem(
|
||||
time: search.timestamp,
|
||||
search: child,
|
||||
objectKey: objectKey,
|
||||
onTap: onTap,
|
||||
onDelete: () => build(context),
|
||||
);
|
||||
};
|
||||
|
||||
DateTime roundToDay(DateTime date) =>
|
||||
DateTime(date.year, date.month, date.day);
|
||||
|
||||
bool dateChangedFromLastSearch(Search prevSearch, DateTime searchDate) {
|
||||
final DateTime prevSearchDate = roundToDay(prevSearch.timestamp);
|
||||
return prevSearchDate != searchDate;
|
||||
}
|
||||
|
||||
DateTime get today => roundToDay(DateTime.now());
|
||||
DateTime get yesterday =>
|
||||
roundToDay(DateTime.now().subtract(const Duration(days: 1)));
|
||||
|
||||
Widget Function(BuildContext, int) historyEntrySeparatorWithData(
|
||||
List<Search> data,
|
||||
) =>
|
||||
(context, index) {
|
||||
final Search search = data[index];
|
||||
final DateTime searchDate = roundToDay(search.timestamp);
|
||||
|
||||
if (index == 0 ||
|
||||
dateChangedFromLastSearch(data[index - 1], searchDate)) {
|
||||
if (searchDate == today)
|
||||
return const DateDivider(text: 'Today');
|
||||
else if (searchDate == yesterday)
|
||||
return const DateDivider(text: 'Yesterday');
|
||||
else
|
||||
return DateDivider(date: searchDate);
|
||||
}
|
||||
|
||||
return const Divider(height: 0);
|
||||
};
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mdi/mdi.dart';
|
||||
|
||||
import '../bloc/theme/theme_bloc.dart';
|
||||
import 'screens/history.dart';
|
||||
import 'screens/search/kanji_view.dart';
|
||||
import 'screens/search/search_view.dart';
|
||||
import 'screens/settings.dart';
|
||||
import 'debug.dart';
|
||||
import 'history.dart';
|
||||
import 'search/kanji_view.dart';
|
||||
import 'search/search_view.dart';
|
||||
import 'settings.dart';
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
const Home({Key? key}) : super(key: key);
|
||||
|
@ -68,7 +70,7 @@ class _HomeState extends State<Home> {
|
|||
),
|
||||
const _Page(
|
||||
content: KanjiView(),
|
||||
titleBar: Text('Kanji'),
|
||||
titleBar: Text('Kanji Search'),
|
||||
item: BottomNavigationBarItem(
|
||||
label: 'Kanji',
|
||||
icon: Icon(Mdi.ideogramCjk, size: 30),
|
||||
|
@ -98,6 +100,16 @@ class _HomeState extends State<Home> {
|
|||
icon: Icon(Icons.settings),
|
||||
),
|
||||
),
|
||||
if (kDebugMode) ...[
|
||||
const _Page(
|
||||
content: DebugView(),
|
||||
titleBar: Text('Debug Page'),
|
||||
item: BottomNavigationBarItem(
|
||||
label: 'Debug',
|
||||
icon: Icon(Icons.biotech),
|
||||
),
|
||||
)
|
||||
],
|
||||
];
|
||||
}
|
||||
|