1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 05:57:28 +01:00

Fix small bugs, formatting and file structure

This commit is contained in:
Oystein Kristoffer Tveit 2021-08-03 22:13:50 +02:00
parent ff6f6ef868
commit d3f76f0b22
22 changed files with 77 additions and 66 deletions

View File

@ -43,6 +43,7 @@ class KanjiSearchOptionsBar extends StatelessWidget {
class _IconButton extends StatelessWidget { class _IconButton extends StatelessWidget {
final Widget icon; final Widget icon;
final void Function()? onPressed; final void Function()? onPressed;
const _IconButton({ const _IconButton({
required this.icon, required this.icon,
required this.onPressed, required this.onPressed,

View File

@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
class Grade extends StatelessWidget { class Grade extends StatelessWidget {
final String grade; final String grade;
const Grade(this.grade);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -20,6 +22,4 @@ class Grade extends StatelessWidget {
), ),
); );
} }
Grade(this.grade);
} }

View File

@ -3,20 +3,24 @@ import 'package:flutter/material.dart';
class Header extends StatelessWidget { class Header extends StatelessWidget {
final String kanji; final String kanji;
const Header(this.kanji);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return AspectRatio(
decoration: BoxDecoration( aspectRatio: 1,
borderRadius: BorderRadius.circular(10.0), color: Colors.blue), child: Container(
child: Padding( decoration: BoxDecoration(
padding: const EdgeInsets.all(10.0), borderRadius: BorderRadius.circular(10.0),
child: Text( color: Colors.blue,
kanji, ),
style: TextStyle(fontSize: 80.0, color: Colors.white), child: Center(
child: Text(
kanji,
style: TextStyle(fontSize: 70.0, color: Colors.white),
),
), ),
), ),
); );
} }
Header(this.kanji);
} }

View File

@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
class JlptLevel extends StatelessWidget { class JlptLevel extends StatelessWidget {
final String jlptLevel; final String jlptLevel;
const JlptLevel(this.jlptLevel);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -21,6 +23,4 @@ class JlptLevel extends StatelessWidget {
), ),
); );
} }
JlptLevel(this.jlptLevel);
} }

View File

@ -5,6 +5,13 @@ class Meaning extends StatelessWidget {
late final List<_MeaningCard> meaningCards; late final List<_MeaningCard> meaningCards;
late final bool expandable; late final bool expandable;
Meaning(meaning) {
this.meanings = meaning.split(', ');
this.meaningCards =
meanings.map((m) => _MeaningCard(m)).toList();
this.expandable = (this.meanings.length > 6);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -42,18 +49,13 @@ class Meaning extends StatelessWidget {
); );
} }
} }
Meaning(meaning) {
this.meanings = meaning.split(', ');
this.meaningCards =
meanings.map((m) => _MeaningCard(m)).toList();
this.expandable = (this.meanings.length > 6);
}
} }
class _MeaningCard extends StatelessWidget { class _MeaningCard extends StatelessWidget {
final String meaning; final String meaning;
const _MeaningCard(this.meaning);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -75,6 +77,4 @@ class _MeaningCard extends StatelessWidget {
), ),
); );
} }
_MeaningCard(this.meaning);
} }

View File

@ -51,6 +51,7 @@ class Onyomi extends StatelessWidget {
class _OnyomiCard extends StatelessWidget { class _OnyomiCard extends StatelessWidget {
final String onyomi; final String onyomi;
const _OnyomiCard(this.onyomi); const _OnyomiCard(this.onyomi);
@override @override

View File

@ -4,6 +4,8 @@ import 'package:unofficial_jisho_api/api.dart' as jisho;
class Radical extends StatelessWidget { class Radical extends StatelessWidget {
final jisho.Radical radical; final jisho.Radical radical;
const Radical(this.radical);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -21,6 +23,4 @@ class Radical extends StatelessWidget {
), ),
); );
} }
Radical(this.radical);
} }

View File

@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
class Rank extends StatelessWidget { class Rank extends StatelessWidget {
final int rank; final int rank;
const Rank(this.rank);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -21,6 +23,4 @@ class Rank extends StatelessWidget {
), ),
); );
} }
Rank(this.rank);
} }

View File

@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
class StrokeOrderGif extends StatelessWidget { class StrokeOrderGif extends StatelessWidget {
final String uri; final String uri;
const StrokeOrderGif(this.uri);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -18,6 +20,4 @@ class StrokeOrderGif extends StatelessWidget {
), ),
); );
} }
StrokeOrderGif(this.uri);
} }

View File

@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class LanguageSelector extends StatefulWidget { class LanguageSelector extends StatefulWidget {
const LanguageSelector();
@override @override
_LanguageSelectorState createState() => new _LanguageSelectorState(); _LanguageSelectorState createState() => new _LanguageSelectorState();
} }
@ -44,7 +46,7 @@ class _LanguageSelectorState extends State<LanguageSelector> {
isSelected: isSelected, isSelected: isSelected,
children: <Widget> [ children: <Widget> [
_LanguageOption("Auto"), _LanguageOption("Auto"),
_LanguageOption("Japanese"), _LanguageOption("日本語"),
_LanguageOption("English") _LanguageOption("English")
], ],
selectedColor: Colors.blue, selectedColor: Colors.blue,
@ -64,7 +66,7 @@ class _LanguageSelectorState extends State<LanguageSelector> {
class _LanguageOption extends StatelessWidget { class _LanguageOption extends StatelessWidget {
final String language; final String language;
_LanguageOption(this.language); const _LanguageOption(this.language);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -1,9 +1,12 @@
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/search/search_bloc.dart'; import 'package:jisho_study_tool/bloc/search/search_bloc.dart';
import 'package:jisho_study_tool/view/components/search/LanguageSelector.dart'; import 'package:jisho_study_tool/view/components/search/language_selector.dart';
class SearchBar extends StatelessWidget { class SearchBar extends StatelessWidget {
const SearchBar();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(

View File

@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:jisho_study_tool/view/components/search/search_result_page/parts/badge.dart'; import 'package:jisho_study_tool/view/components/search/search_result_page/parts/badge.dart';
class CommonBadge extends StatelessWidget { class CommonBadge extends StatelessWidget {
bool isCommon; final bool isCommon;
CommonBadge(this.isCommon); const CommonBadge(this.isCommon);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -3,6 +3,7 @@ import 'package:unofficial_jisho_api/api.dart';
class JapaneseHeader extends StatelessWidget { class JapaneseHeader extends StatelessWidget {
final JishoJapaneseWord word; final JishoJapaneseWord word;
const JapaneseHeader(this.word); const JapaneseHeader(this.word);
@override @override

View File

@ -3,7 +3,8 @@ import 'package:unofficial_jisho_api/api.dart';
class OtherForms extends StatelessWidget { class OtherForms extends StatelessWidget {
final List<JishoJapaneseWord> otherForms; final List<JishoJapaneseWord> otherForms;
OtherForms(this.otherForms);
const OtherForms(this.otherForms);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -28,6 +29,7 @@ class OtherForms extends StatelessWidget {
class _KanaBox extends StatelessWidget { class _KanaBox extends StatelessWidget {
final JishoJapaneseWord word; final JishoJapaneseWord word;
const _KanaBox(this.word); const _KanaBox(this.word);
@override @override

View File

@ -3,6 +3,7 @@ import 'package:unofficial_jisho_api/parser.dart';
class Senses extends StatelessWidget { class Senses extends StatelessWidget {
final List<JishoWordSense> senses; final List<JishoWordSense> senses;
const Senses(this.senses); const Senses(this.senses);
@override @override

View File

@ -31,7 +31,7 @@ class SearchResultCard extends StatelessWidget {
children: [ children: [
WKBadge(result.tags.firstWhere((tag) => tag.contains("wanikani"), orElse: () => '')), WKBadge(result.tags.firstWhere((tag) => tag.contains("wanikani"), orElse: () => '')),
JLPTBadge(result.jlpt.isNotEmpty ? result.jlpt[0] : ''), JLPTBadge(result.jlpt.isNotEmpty ? result.jlpt[0] : ''),
CommonBadge(result.isCommon!) CommonBadge(result.isCommon ?? false)
], ],
) )
], ],

View File

@ -1,6 +1,4 @@
import 'package:flutter/material.dart'; 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_grid.dart';
import 'package:jisho_study_tool/view/components/kanji/kanji_search_bar.dart'; import 'package:jisho_study_tool/view/components/kanji/kanji_search_bar.dart';

View File

@ -8,32 +8,30 @@ import 'package:jisho_study_tool/view/components/search/search_result_page/searc
class SearchView extends StatelessWidget { class SearchView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocListener<SearchBloc, SearchState>( return BlocConsumer<SearchBloc, SearchState>(
listener: (context, state) {}, listener: (context, state) {},
child: BlocBuilder<SearchBloc, SearchState>( builder: (context, state) {
builder: (context, state) { if (state is SearchInitial)
if (state is SearchInitial) return _InitialView();
return _InitialView(); else if (state is SearchLoading)
else if (state is SearchLoading) return LoadingScreen();
return LoadingScreen(); else if (state is SearchFinished) {
else if (state is SearchFinished) { return WillPopScope(
return WillPopScope( child: ListView(
child: ListView( children: state.results
children: state.results .map((result) => SearchResultCard(result))
.map((result) => SearchResultCard(result)) .toList(),
.toList(), ),
), onWillPop: () async {
onWillPop: () async { BlocProvider.of<SearchBloc>(context).add(ReturnToInitialState());
BlocProvider.of<SearchBloc>(context) print('Popped');
.add(ReturnToInitialState()); return false;
print('Popped'); },
return false; );
}, }
); throw 'No such event found';
} },
throw 'No such event found'; );
},
));
} }
} }