From d3f76f0b22c3842dabce16ca4c1be324eebe5da8 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 3 Aug 2021 22:13:50 +0200 Subject: [PATCH] Fix small bugs, formatting and file structure --- lib/bloc/history/{bloc => }/history_bloc.dart | 0 .../history/{bloc => }/history_event.dart | 0 .../history/{bloc => }/history_state.dart | 0 .../kanji/kanji_search_options_bar.dart | 1 + lib/view/components/kanji/result/grade.dart | 4 +- lib/view/components/kanji/result/header.dart | 26 ++++++---- .../components/kanji/result/jlpt_level.dart | 4 +- lib/view/components/kanji/result/meaning.dart | 18 +++---- lib/view/components/kanji/result/onyomi.dart | 1 + lib/view/components/kanji/result/radical.dart | 4 +- lib/view/components/kanji/result/rank.dart | 4 +- .../kanji/result/stroke_order_gif.dart | 4 +- ...geSelector.dart => language_selector.dart} | 6 ++- lib/view/components/search/search_bar.dart | 5 +- .../parts/common_badge.dart | 4 +- .../search_result_page/parts/header.dart | 1 + .../search_result_page/parts/other_forms.dart | 4 +- .../search_result_page/parts/senses.dart | 1 + .../search_result_page/search_card.dart | 2 +- lib/view/screens/kanji/search/grid.dart | 2 - .../screens/{memorize.dart => saved.dart} | 0 lib/view/screens/search/view.dart | 52 +++++++++---------- 22 files changed, 77 insertions(+), 66 deletions(-) rename lib/bloc/history/{bloc => }/history_bloc.dart (100%) rename lib/bloc/history/{bloc => }/history_event.dart (100%) rename lib/bloc/history/{bloc => }/history_state.dart (100%) rename lib/view/components/search/{LanguageSelector.dart => language_selector.dart} (94%) rename lib/view/screens/{memorize.dart => saved.dart} (100%) diff --git a/lib/bloc/history/bloc/history_bloc.dart b/lib/bloc/history/history_bloc.dart similarity index 100% rename from lib/bloc/history/bloc/history_bloc.dart rename to lib/bloc/history/history_bloc.dart diff --git a/lib/bloc/history/bloc/history_event.dart b/lib/bloc/history/history_event.dart similarity index 100% rename from lib/bloc/history/bloc/history_event.dart rename to lib/bloc/history/history_event.dart diff --git a/lib/bloc/history/bloc/history_state.dart b/lib/bloc/history/history_state.dart similarity index 100% rename from lib/bloc/history/bloc/history_state.dart rename to lib/bloc/history/history_state.dart diff --git a/lib/view/components/kanji/kanji_search_options_bar.dart b/lib/view/components/kanji/kanji_search_options_bar.dart index 97c0dee..7ba4d49 100644 --- a/lib/view/components/kanji/kanji_search_options_bar.dart +++ b/lib/view/components/kanji/kanji_search_options_bar.dart @@ -43,6 +43,7 @@ class KanjiSearchOptionsBar extends StatelessWidget { class _IconButton extends StatelessWidget { final Widget icon; final void Function()? onPressed; + const _IconButton({ required this.icon, required this.onPressed, diff --git a/lib/view/components/kanji/result/grade.dart b/lib/view/components/kanji/result/grade.dart index 6eda527..a5c7c9d 100644 --- a/lib/view/components/kanji/result/grade.dart +++ b/lib/view/components/kanji/result/grade.dart @@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; class Grade extends StatelessWidget { final String grade; + const Grade(this.grade); + @override Widget build(BuildContext context) { return Container( @@ -20,6 +22,4 @@ class Grade extends StatelessWidget { ), ); } - - Grade(this.grade); } \ No newline at end of file diff --git a/lib/view/components/kanji/result/header.dart b/lib/view/components/kanji/result/header.dart index 1f35943..c20c94e 100644 --- a/lib/view/components/kanji/result/header.dart +++ b/lib/view/components/kanji/result/header.dart @@ -3,20 +3,24 @@ import 'package:flutter/material.dart'; class Header extends StatelessWidget { final String kanji; + const Header(this.kanji); + @override Widget build(BuildContext context) { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10.0), color: Colors.blue), - child: Padding( - padding: const EdgeInsets.all(10.0), - child: Text( - kanji, - style: TextStyle(fontSize: 80.0, color: Colors.white), + return AspectRatio( + aspectRatio: 1, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10.0), + color: Colors.blue, + ), + child: Center( + child: Text( + kanji, + style: TextStyle(fontSize: 70.0, color: Colors.white), + ), ), ), ); } - - Header(this.kanji); -} \ No newline at end of file +} diff --git a/lib/view/components/kanji/result/jlpt_level.dart b/lib/view/components/kanji/result/jlpt_level.dart index 0743c47..1c07ee4 100644 --- a/lib/view/components/kanji/result/jlpt_level.dart +++ b/lib/view/components/kanji/result/jlpt_level.dart @@ -4,6 +4,8 @@ import 'package:flutter/material.dart'; class JlptLevel extends StatelessWidget { final String jlptLevel; + const JlptLevel(this.jlptLevel); + @override Widget build(BuildContext context) { return Container( @@ -21,6 +23,4 @@ class JlptLevel extends StatelessWidget { ), ); } - - JlptLevel(this.jlptLevel); } \ No newline at end of file diff --git a/lib/view/components/kanji/result/meaning.dart b/lib/view/components/kanji/result/meaning.dart index b035dec..a54e0d4 100644 --- a/lib/view/components/kanji/result/meaning.dart +++ b/lib/view/components/kanji/result/meaning.dart @@ -5,6 +5,13 @@ class Meaning extends StatelessWidget { late final List<_MeaningCard> meaningCards; 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 Widget build(BuildContext context) { 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 { final String meaning; + const _MeaningCard(this.meaning); + @override Widget build(BuildContext context) { return Container( @@ -75,6 +77,4 @@ class _MeaningCard extends StatelessWidget { ), ); } - - _MeaningCard(this.meaning); } diff --git a/lib/view/components/kanji/result/onyomi.dart b/lib/view/components/kanji/result/onyomi.dart index bebfc1a..c9c1a1e 100644 --- a/lib/view/components/kanji/result/onyomi.dart +++ b/lib/view/components/kanji/result/onyomi.dart @@ -51,6 +51,7 @@ class Onyomi extends StatelessWidget { class _OnyomiCard extends StatelessWidget { final String onyomi; + const _OnyomiCard(this.onyomi); @override diff --git a/lib/view/components/kanji/result/radical.dart b/lib/view/components/kanji/result/radical.dart index 07d6d61..fd193f6 100644 --- a/lib/view/components/kanji/result/radical.dart +++ b/lib/view/components/kanji/result/radical.dart @@ -4,6 +4,8 @@ import 'package:unofficial_jisho_api/api.dart' as jisho; class Radical extends StatelessWidget { final jisho.Radical radical; + const Radical(this.radical); + @override Widget build(BuildContext context) { return Container( @@ -21,6 +23,4 @@ class Radical extends StatelessWidget { ), ); } - - Radical(this.radical); } \ No newline at end of file diff --git a/lib/view/components/kanji/result/rank.dart b/lib/view/components/kanji/result/rank.dart index 6a65b86..441af58 100644 --- a/lib/view/components/kanji/result/rank.dart +++ b/lib/view/components/kanji/result/rank.dart @@ -4,6 +4,8 @@ import 'package:flutter/material.dart'; class Rank extends StatelessWidget { final int rank; + const Rank(this.rank); + @override Widget build(BuildContext context) { return Container( @@ -21,6 +23,4 @@ class Rank extends StatelessWidget { ), ); } - - Rank(this.rank); } \ No newline at end of file diff --git a/lib/view/components/kanji/result/stroke_order_gif.dart b/lib/view/components/kanji/result/stroke_order_gif.dart index 615eb21..f3a85d8 100644 --- a/lib/view/components/kanji/result/stroke_order_gif.dart +++ b/lib/view/components/kanji/result/stroke_order_gif.dart @@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; class StrokeOrderGif extends StatelessWidget { final String uri; + const StrokeOrderGif(this.uri); + @override Widget build(BuildContext context) { return Container( @@ -18,6 +20,4 @@ class StrokeOrderGif extends StatelessWidget { ), ); } - - StrokeOrderGif(this.uri); } \ No newline at end of file diff --git a/lib/view/components/search/LanguageSelector.dart b/lib/view/components/search/language_selector.dart similarity index 94% rename from lib/view/components/search/LanguageSelector.dart rename to lib/view/components/search/language_selector.dart index 1da238b..c5d206d 100644 --- a/lib/view/components/search/LanguageSelector.dart +++ b/lib/view/components/search/language_selector.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; class LanguageSelector extends StatefulWidget { + const LanguageSelector(); + @override _LanguageSelectorState createState() => new _LanguageSelectorState(); } @@ -44,7 +46,7 @@ class _LanguageSelectorState extends State { isSelected: isSelected, children: [ _LanguageOption("Auto"), - _LanguageOption("Japanese"), + _LanguageOption("日本語"), _LanguageOption("English") ], selectedColor: Colors.blue, @@ -64,7 +66,7 @@ class _LanguageSelectorState extends State { class _LanguageOption extends StatelessWidget { final String language; - _LanguageOption(this.language); + const _LanguageOption(this.language); @override Widget build(BuildContext context) { diff --git a/lib/view/components/search/search_bar.dart b/lib/view/components/search/search_bar.dart index 9df9943..1ace9d0 100644 --- a/lib/view/components/search/search_bar.dart +++ b/lib/view/components/search/search_bar.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_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 { + + const SearchBar(); + @override Widget build(BuildContext context) { return Container( diff --git a/lib/view/components/search/search_result_page/parts/common_badge.dart b/lib/view/components/search/search_result_page/parts/common_badge.dart index 7255d9f..8bb6acb 100644 --- a/lib/view/components/search/search_result_page/parts/common_badge.dart +++ b/lib/view/components/search/search_result_page/parts/common_badge.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:jisho_study_tool/view/components/search/search_result_page/parts/badge.dart'; class CommonBadge extends StatelessWidget { - bool isCommon; + final bool isCommon; - CommonBadge(this.isCommon); + const CommonBadge(this.isCommon); @override Widget build(BuildContext context) { diff --git a/lib/view/components/search/search_result_page/parts/header.dart b/lib/view/components/search/search_result_page/parts/header.dart index c08eaa4..677ae37 100644 --- a/lib/view/components/search/search_result_page/parts/header.dart +++ b/lib/view/components/search/search_result_page/parts/header.dart @@ -3,6 +3,7 @@ import 'package:unofficial_jisho_api/api.dart'; class JapaneseHeader extends StatelessWidget { final JishoJapaneseWord word; + const JapaneseHeader(this.word); @override diff --git a/lib/view/components/search/search_result_page/parts/other_forms.dart b/lib/view/components/search/search_result_page/parts/other_forms.dart index fa397d1..598ab95 100644 --- a/lib/view/components/search/search_result_page/parts/other_forms.dart +++ b/lib/view/components/search/search_result_page/parts/other_forms.dart @@ -3,7 +3,8 @@ import 'package:unofficial_jisho_api/api.dart'; class OtherForms extends StatelessWidget { final List otherForms; - OtherForms(this.otherForms); + + const OtherForms(this.otherForms); @override Widget build(BuildContext context) { @@ -28,6 +29,7 @@ class OtherForms extends StatelessWidget { class _KanaBox extends StatelessWidget { final JishoJapaneseWord word; + const _KanaBox(this.word); @override diff --git a/lib/view/components/search/search_result_page/parts/senses.dart b/lib/view/components/search/search_result_page/parts/senses.dart index 728b3a6..510054d 100644 --- a/lib/view/components/search/search_result_page/parts/senses.dart +++ b/lib/view/components/search/search_result_page/parts/senses.dart @@ -3,6 +3,7 @@ import 'package:unofficial_jisho_api/parser.dart'; class Senses extends StatelessWidget { final List senses; + const Senses(this.senses); @override diff --git a/lib/view/components/search/search_result_page/search_card.dart b/lib/view/components/search/search_result_page/search_card.dart index 235047c..ea30552 100644 --- a/lib/view/components/search/search_result_page/search_card.dart +++ b/lib/view/components/search/search_result_page/search_card.dart @@ -31,7 +31,7 @@ class SearchResultCard extends StatelessWidget { children: [ WKBadge(result.tags.firstWhere((tag) => tag.contains("wanikani"), orElse: () => '')), JLPTBadge(result.jlpt.isNotEmpty ? result.jlpt[0] : ''), - CommonBadge(result.isCommon!) + CommonBadge(result.isCommon ?? false) ], ) ], diff --git a/lib/view/screens/kanji/search/grid.dart b/lib/view/screens/kanji/search/grid.dart index f1c6829..5aaca73 100644 --- a/lib/view/screens/kanji/search/grid.dart +++ b/lib/view/screens/kanji/search/grid.dart @@ -1,6 +1,4 @@ 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'; diff --git a/lib/view/screens/memorize.dart b/lib/view/screens/saved.dart similarity index 100% rename from lib/view/screens/memorize.dart rename to lib/view/screens/saved.dart diff --git a/lib/view/screens/search/view.dart b/lib/view/screens/search/view.dart index e4e47ad..c1fad0e 100644 --- a/lib/view/screens/search/view.dart +++ b/lib/view/screens/search/view.dart @@ -8,32 +8,30 @@ import 'package:jisho_study_tool/view/components/search/search_result_page/searc class SearchView extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocListener( - listener: (context, state) {}, - child: BlocBuilder( - builder: (context, state) { - if (state is SearchInitial) - return _InitialView(); - else if (state is SearchLoading) - return LoadingScreen(); - else if (state is SearchFinished) { - return WillPopScope( - child: ListView( - children: state.results - .map((result) => SearchResultCard(result)) - .toList(), - ), - onWillPop: () async { - BlocProvider.of(context) - .add(ReturnToInitialState()); - print('Popped'); - return false; - }, - ); - } - throw 'No such event found'; - }, - )); + return BlocConsumer( + listener: (context, state) {}, + builder: (context, state) { + if (state is SearchInitial) + return _InitialView(); + else if (state is SearchLoading) + return LoadingScreen(); + else if (state is SearchFinished) { + return WillPopScope( + child: ListView( + children: state.results + .map((result) => SearchResultCard(result)) + .toList(), + ), + onWillPop: () async { + BlocProvider.of(context).add(ReturnToInitialState()); + print('Popped'); + return false; + }, + ); + } + throw 'No such event found'; + }, + ); } } @@ -44,4 +42,4 @@ class _InitialView extends StatelessWidget { SearchBar(), ]); } -} \ No newline at end of file +}