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

Organize files better

This commit is contained in:
Oystein Kristoffer Tveit 2021-07-17 12:19:03 +02:00
parent b8f69bfaaf
commit 1aebc38954
30 changed files with 169 additions and 90 deletions

View File

@ -12,7 +12,7 @@ export './kanji_state.dart';
class KanjiBloc extends Bloc<KanjiEvent, KanjiState> { class KanjiBloc extends Bloc<KanjiEvent, KanjiState> {
KanjiBloc() : super(KanjiSearchInitial()); KanjiBloc() : super(KanjiSearch(KanjiSearchType.Initial));
@override @override
Stream<KanjiState> mapEventToState(KanjiEvent event) Stream<KanjiState> mapEventToState(KanjiEvent event)
@ -31,10 +31,10 @@ class KanjiBloc extends Bloc<KanjiEvent, KanjiState> {
} else if (event is GetKanjiSuggestions) { } else if (event is GetKanjiSuggestions) {
final suggestions = kanjiSuggestions(event.searchString); final suggestions = kanjiSuggestions(event.searchString);
yield KanjiSearchInput(suggestions); yield KanjiSearchKeyboard(KanjiSearchType.Keyboard, suggestions);
} else if (event is ReturnToInitialState) { } else if (event is ReturnToInitialState) {
yield KanjiSearchInitial(); yield KanjiSearch(KanjiSearchType.Initial);
} }
} }
} }

View File

@ -4,13 +4,22 @@ abstract class KanjiState {
const KanjiState(); const KanjiState();
} }
class KanjiSearchInitial extends KanjiState { enum KanjiSearchType {
const KanjiSearchInitial(); Initial,
Keyboard,
Drawing,
Radical,
Grade
} }
class KanjiSearchInput extends KanjiState { class KanjiSearch extends KanjiState {
final KanjiSearchType type;
const KanjiSearch(this.type);
}
class KanjiSearchKeyboard extends KanjiSearch {
final List<String> kanjiSuggestions; final List<String> kanjiSuggestions;
const KanjiSearchInput(this.kanjiSuggestions); const KanjiSearchKeyboard(KanjiSearchType type, this.kanjiSuggestions) : super(type);
} }
class KanjiSearchLoading extends KanjiState { class KanjiSearchLoading extends KanjiState {

View File

@ -3,9 +3,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mdi/mdi.dart'; import 'package:mdi/mdi.dart';
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart'; import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
import 'package:jisho_study_tool/view/screens/kanji_search.dart'; import 'package:jisho_study_tool/view/screens/kanji/view.dart';
import 'package:jisho_study_tool/view/screens/history.dart'; import 'package:jisho_study_tool/view/screens/history.dart';
import 'package:jisho_study_tool/view/screens/search.dart'; import 'package:jisho_study_tool/view/screens/search/view.dart';
import 'bloc/search/search_bloc.dart'; import 'bloc/search/search_bloc.dart';
@ -69,16 +69,18 @@ final List<BottomNavigationBarItem> navBar = [
icon: Icon(Icons.search), icon: Icon(Icons.search),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
label: 'Kanji', label: 'Kanji',
icon: Icon(Mdi.ideogramCjk, size: 30,) icon: Icon(
), Mdi.ideogramCjk,
size: 30,
)),
BottomNavigationBarItem( BottomNavigationBarItem(
label: 'History', label: 'History',
icon: Icon(Icons.bookmark), icon: Icon(Icons.history),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
label: 'Memorize', label: 'Memorize',
icon: Icon(Icons.local_offer), icon: Icon(Icons.bookmark),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
label: 'Settings', label: 'Settings',

View File

@ -1,32 +1,32 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart'; import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
class KanjiSuggestions extends StatelessWidget { class KanjiGrid extends StatelessWidget {
final List<String> suggestions; final List<String> suggestions;
const KanjiSuggestions(this.suggestions); const KanjiGrid(this.suggestions);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
color: Colors.grey[300],
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
vertical: 20.0, vertical: 20.0,
horizontal: 40.0, horizontal: 40.0,
), ),
child: GridView.count( child: GridView.count(
crossAxisCount: 3, crossAxisCount: 3,
mainAxisSpacing: 20.0, mainAxisSpacing: 10.0,
crossAxisSpacing: 40.0, crossAxisSpacing: 10.0,
children: suggestions.map((kanji) => _Suggestion(kanji)).toList(), children: suggestions.map((kanji) => _GridItem(kanji)).toList(),
), ),
); );
} }
} }
class _Suggestion extends StatelessWidget { class _GridItem extends StatelessWidget {
final String kanji; final String kanji;
const _Suggestion(this.kanji); const _GridItem(this.kanji);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -36,19 +36,19 @@ class _Suggestion extends StatelessWidget {
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.grey, color: Colors.grey[300],
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(20.0),
), ),
child: Container( child: Container(
margin: EdgeInsets.all(10.0), margin: EdgeInsets.all(10.0),
child: FittedBox( child: FittedBox(
child: Text( child: Text(
kanji, kanji,
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.black),
), ),
), ),
), ),
), ),
); );
} }
} }

View File

@ -69,12 +69,13 @@ class _KanjiSearchBarState extends State<KanjiSearchBar> {
onSubmitted: (text) => onSubmitted: (text) =>
BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)), BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
decoration: new InputDecoration( decoration: new InputDecoration(
prefixIcon: Icon(Icons.search), prefixIcon: Icon(Icons.search),
hintText: 'Search for kanji', hintText: 'Search',
fillColor: Colors.white, fillColor: Colors.white,
filled: true, filled: true,
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(100.0), borderRadius: BorderRadius.circular(10.0),
), ),
contentPadding: EdgeInsets.symmetric(vertical: 10.0), contentPadding: EdgeInsets.symmetric(vertical: 10.0),
isDense: false, isDense: false,

View File

@ -1,11 +0,0 @@
import 'package:flutter/material.dart';
class KanjiGrid extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 3,
);
}
}

View File

@ -11,8 +11,11 @@ class SearchBar extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
TextField( TextField(
onSubmitted: (text) => BlocProvider.of<SearchBloc>(context) onSubmitted: (text) {
.add(GetSearchResults(text)),
BlocProvider.of<SearchBloc>(context)
.add(GetSearchResults(text));
},
controller: TextEditingController(), controller: TextEditingController(),
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Search', labelText: 'Search',

View File

@ -9,15 +9,18 @@ class OtherForms extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
child: Column( child: Column(
children: [ children:
Text( this.otherForms.isNotEmpty
'Other Forms', ? [
style: TextStyle(fontWeight: FontWeight.bold), Text(
), 'Other Forms',
Row( style: TextStyle(fontWeight: FontWeight.bold),
children: otherForms.map((form) => _KanaBox(form)).toList(), ),
), Row(
], children: otherForms.map((form) => _KanaBox(form)).toList(),
),
]
: [],
), ),
); );
} }

View File

@ -8,7 +8,7 @@ class Senses extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<Widget> senseWidgets = final List<Widget> senseWidgets =
senses.map((sense) => _Sense(sense)).toList(); senses.asMap().entries.map((e) => _Sense(e.key, e.value)).toList();
return Container( return Container(
child: Column( child: Column(
@ -18,23 +18,42 @@ class Senses extends StatelessWidget {
} }
class _Sense extends StatelessWidget { class _Sense extends StatelessWidget {
final int index;
final JishoWordSense sense; final JishoWordSense sense;
const _Sense(this.sense);
const _Sense(this.index, this.sense);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
child: Column( child: Column(
children: [ children: [
Text( Row(
sense.parts_of_speech.join(', '), children: [
style: TextStyle(fontWeight: FontWeight.bold), Text(
textAlign: TextAlign.left, (index + 1).toString() + '. ',
style: TextStyle(color: Colors.grey),
),
Text(
sense.parts_of_speech.join(', '),
style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.left,
),
],
),
Container(
child: Row(
children:[
Column(
children:
sense.english_definitions.map((def) => Text(def)).toList(),
crossAxisAlignment: CrossAxisAlignment.start,
),
]
),
padding: EdgeInsets.symmetric(horizontal: 20),
margin: EdgeInsets.fromLTRB(0, 5, 0, 15),
), ),
Column(
children:
sense.english_definitions.map((def) => Text(def)).toList(),
)
], ],
), ),
); );

View File

@ -44,6 +44,9 @@ class SearchResultCard extends StatelessWidget {
children: [ children: [
Senses(result.senses), Senses(result.senses),
OtherForms(otherForms), OtherForms(otherForms),
// Text(result.toJson().toString()),
// Text(result.attribution.toJson().toString()),
// Text(result.japanese.map((e) => e.toJson().toString()).toList().toString()),
], ],
), ),
padding: EdgeInsets.symmetric(horizontal: 30), padding: EdgeInsets.symmetric(horizontal: 30),

View File

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_search_bar.dart';
class InitScreen extends StatelessWidget {
const InitScreen({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
padding: EdgeInsets.symmetric(horizontal: 20),
child: KanjiSearchBar(),
);
}
}

View File

@ -1,17 +1,18 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho; import 'package:unofficial_jisho_api/api.dart' as jisho;
import 'parts/grade.dart'; import 'package:jisho_study_tool/view/components/kanji/result/grade.dart';
import 'parts/header.dart'; import 'package:jisho_study_tool/view/components/kanji/result/header.dart';
import 'parts/jlpt_level.dart'; import 'package:jisho_study_tool/view/components/kanji/result/jlpt_level.dart';
import 'parts/meaning.dart'; import 'package:jisho_study_tool/view/components/kanji/result/meaning.dart';
import 'parts/radical.dart'; import 'package:jisho_study_tool/view/components/kanji/result/radical.dart';
import 'parts/rank.dart'; import 'package:jisho_study_tool/view/components/kanji/result/rank.dart';
import 'parts/stroke_order_gif.dart'; import 'package:jisho_study_tool/view/components/kanji/result/stroke_order_gif.dart';
import 'parts/onyomi.dart'; import 'package:jisho_study_tool/view/components/kanji/result/onyomi.dart';
import 'parts/kunyomi.dart'; import 'package:jisho_study_tool/view/components/kanji/result/kunyomi.dart';
import 'parts/examples.dart'; import 'package:jisho_study_tool/view/components/kanji/result/examples.dart';
class KanjiResultCard extends StatelessWidget { class KanjiResultCard extends StatelessWidget {
final jisho.KanjiResult result; final jisho.KanjiResult result;
@ -88,4 +89,4 @@ class KanjiResultCard extends StatelessWidget {
} }
KanjiResultCard(this.result); KanjiResultCard(this.result);
} }

View File

@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_grid.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_search_bar.dart';
class SearchGrid extends StatelessWidget {
final List<String> suggestions;
const SearchGrid(this.suggestions);
@override
Widget build(BuildContext context) {
return
Column(
children: [
SizedBox(height: 10),
KanjiSearchBar(),
SizedBox(height: 10),
Expanded(
child: KanjiGrid(suggestions)
)
],
);
}
}

View File

@ -0,0 +1 @@
const List<List<String>> radicals = [[]];

View File

@ -1,18 +1,22 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart'; import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_search_bar.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_search_result_page/kanji_search_result_page.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_search_suggestion_list/kanji_search_suggestion_list.dart';
import 'package:jisho_study_tool/view/screens/loading.dart'; import 'package:jisho_study_tool/view/screens/loading.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_grid.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_search_bar.dart';
import 'init.dart';
import 'result.dart';
import 'search/grid.dart';
class KanjiView extends StatelessWidget { class KanjiView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocListener<KanjiBloc, KanjiState>( return BlocListener<KanjiBloc, KanjiState>(
listener: (context, state) { listener: (context, state) {
if (state is KanjiSearchInitial) { if (state is KanjiSearch && state.type == KanjiSearchType.Initial) {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
} else if (state is KanjiSearchLoading) { } else if (state is KanjiSearchLoading) {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
@ -20,8 +24,10 @@ class KanjiView extends StatelessWidget {
}, },
child: BlocBuilder<KanjiBloc, KanjiState>( child: BlocBuilder<KanjiBloc, KanjiState>(
builder: (context, state) { builder: (context, state) {
if (state is KanjiSearchInitial) return Container(); if (state is KanjiSearch) {
else if (state is KanjiSearchInput) return KanjiSuggestions(state.kanjiSuggestions); if (state.type == KanjiSearchType.Initial) return InitScreen();
else if (state is KanjiSearchKeyboard) return SearchGrid(state.kanjiSuggestions);
}
else if (state is KanjiSearchLoading) return LoadingScreen(); else if (state is KanjiSearchLoading) return LoadingScreen();
else if (state is KanjiSearchFinished) else if (state is KanjiSearchFinished)
return WillPopScope( return WillPopScope(
@ -49,19 +55,19 @@ class KanjiViewBar extends StatelessWidget {
onPressed: () => onPressed: () =>
BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState()), BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState()),
), ),
Expanded( // Expanded(
child: Container( // child: Container(
child: KanjiSearchBar(), // child: KanjiSearchBar(),
), // ),
), // ),
IconButton( // IconButton(
icon: Icon(Icons.star_border), // icon: Icon(Icons.star_border),
onPressed: null, // onPressed: null,
), // ),
IconButton( // IconButton(
icon: Icon(Icons.add), // icon: Icon(Icons.add),
onPressed: null, // onPressed: null,
), // ),
], ],
), ),
); );

View File

View File