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

View File

@ -4,13 +4,22 @@ abstract class KanjiState {
const KanjiState();
}
class KanjiSearchInitial extends KanjiState {
const KanjiSearchInitial();
enum KanjiSearchType {
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;
const KanjiSearchInput(this.kanjiSuggestions);
const KanjiSearchKeyboard(KanjiSearchType type, this.kanjiSuggestions) : super(type);
}
class KanjiSearchLoading extends KanjiState {

View File

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

View File

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

View File

@ -69,12 +69,13 @@ class _KanjiSearchBarState extends State<KanjiSearchBar> {
onSubmitted: (text) =>
BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
decoration: new InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'Search for kanji',
hintText: 'Search',
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(100.0),
borderRadius: BorderRadius.circular(10.0),
),
contentPadding: EdgeInsets.symmetric(vertical: 10.0),
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(
children: [
TextField(
onSubmitted: (text) => BlocProvider.of<SearchBloc>(context)
.add(GetSearchResults(text)),
onSubmitted: (text) {
BlocProvider.of<SearchBloc>(context)
.add(GetSearchResults(text));
},
controller: TextEditingController(),
decoration: InputDecoration(
labelText: 'Search',

View File

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

View File

@ -8,7 +8,7 @@ class Senses extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<Widget> senseWidgets =
senses.map((sense) => _Sense(sense)).toList();
senses.asMap().entries.map((e) => _Sense(e.key, e.value)).toList();
return Container(
child: Column(
@ -18,23 +18,42 @@ class Senses extends StatelessWidget {
}
class _Sense extends StatelessWidget {
final int index;
final JishoWordSense sense;
const _Sense(this.sense);
const _Sense(this.index, this.sense);
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
Text(
sense.parts_of_speech.join(', '),
style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.left,
Row(
children: [
Text(
(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: [
Senses(result.senses),
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),

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:unofficial_jisho_api/api.dart' as jisho;
import 'parts/grade.dart';
import 'parts/header.dart';
import 'parts/jlpt_level.dart';
import 'parts/meaning.dart';
import 'parts/radical.dart';
import 'parts/rank.dart';
import 'parts/stroke_order_gif.dart';
import 'parts/onyomi.dart';
import 'parts/kunyomi.dart';
import 'parts/examples.dart';
import 'package:jisho_study_tool/view/components/kanji/result/grade.dart';
import 'package:jisho_study_tool/view/components/kanji/result/header.dart';
import 'package:jisho_study_tool/view/components/kanji/result/jlpt_level.dart';
import 'package:jisho_study_tool/view/components/kanji/result/meaning.dart';
import 'package:jisho_study_tool/view/components/kanji/result/radical.dart';
import 'package:jisho_study_tool/view/components/kanji/result/rank.dart';
import 'package:jisho_study_tool/view/components/kanji/result/stroke_order_gif.dart';
import 'package:jisho_study_tool/view/components/kanji/result/onyomi.dart';
import 'package:jisho_study_tool/view/components/kanji/result/kunyomi.dart';
import 'package:jisho_study_tool/view/components/kanji/result/examples.dart';
class KanjiResultCard extends StatelessWidget {
final jisho.KanjiResult result;
@ -88,4 +89,4 @@ class KanjiResultCard extends StatelessWidget {
}
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_bloc/flutter_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/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 {
@override
Widget build(BuildContext context) {
return BlocListener<KanjiBloc, KanjiState>(
listener: (context, state) {
if (state is KanjiSearchInitial) {
if (state is KanjiSearch && state.type == KanjiSearchType.Initial) {
FocusScope.of(context).unfocus();
} else if (state is KanjiSearchLoading) {
FocusScope.of(context).unfocus();
@ -20,8 +24,10 @@ class KanjiView extends StatelessWidget {
},
child: BlocBuilder<KanjiBloc, KanjiState>(
builder: (context, state) {
if (state is KanjiSearchInitial) return Container();
else if (state is KanjiSearchInput) return KanjiSuggestions(state.kanjiSuggestions);
if (state is KanjiSearch) {
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 KanjiSearchFinished)
return WillPopScope(
@ -49,19 +55,19 @@ class KanjiViewBar extends StatelessWidget {
onPressed: () =>
BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState()),
),
Expanded(
child: Container(
child: KanjiSearchBar(),
),
),
IconButton(
icon: Icon(Icons.star_border),
onPressed: null,
),
IconButton(
icon: Icon(Icons.add),
onPressed: null,
),
// Expanded(
// child: Container(
// child: KanjiSearchBar(),
// ),
// ),
// IconButton(
// icon: Icon(Icons.star_border),
// onPressed: null,
// ),
// IconButton(
// icon: Icon(Icons.add),
// onPressed: null,
// ),
],
),
);

View File

View File