Clean up variable naming

This commit is contained in:
Oystein Kristoffer Tveit 2021-03-03 00:24:25 +01:00
parent 16ca1d2a69
commit ac8572da9b
22 changed files with 168 additions and 170 deletions

View File

@ -22,8 +22,8 @@ class KanjiBloc extends Bloc<KanjiEvent, KanjiState> {
yield KanjiSearchLoading(); yield KanjiSearchLoading();
try { try {
final _kanji = await fetchKanji(event.kanjiSearchString); final kanji = await fetchKanji(event.kanjiSearchString);
if (_kanji.found) yield KanjiSearchFinished(kanji: _kanji); if (kanji.found) yield KanjiSearchFinished(kanji: kanji);
else yield KanjiSearchError('Something went wrong'); else yield KanjiSearchError('Something went wrong');
} on Exception { } on Exception {
yield KanjiSearchError('Something went wrong'); yield KanjiSearchError('Something went wrong');

View File

@ -22,8 +22,8 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
yield SearchLoading(); yield SearchLoading();
try { try {
final _searchResults = await fetchJishoResults(event.searchString); final searchResults = await fetchJishoResults(event.searchString);
if (_searchResults.meta.status == 200) yield SearchFinished(_searchResults.data); if (searchResults.meta.status == 200) yield SearchFinished(searchResults.data);
} on Exception { } on Exception {
yield SearchError('Something went wrong'); yield SearchError('Something went wrong');
} }

View File

@ -34,21 +34,21 @@ class Home extends StatefulWidget {
} }
class _HomeState extends State<Home> { class _HomeState extends State<Home> {
int _selectedPage = 0; int selectedPage = 0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: pages[_selectedPage].titleBar, title: pages[selectedPage].titleBar,
centerTitle: true, centerTitle: true,
), ),
body: pages[_selectedPage].content, body: pages[selectedPage].content,
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedPage, currentIndex: selectedPage,
onTap: (int index) { onTap: (int index) {
setState(() { setState(() {
_selectedPage = index; selectedPage = index;
}); });
}, },
items: navBar, items: navBar,
@ -63,55 +63,55 @@ class _HomeState extends State<Home> {
final List<BottomNavigationBarItem> navBar = [ final List<BottomNavigationBarItem> navBar = [
BottomNavigationBarItem( BottomNavigationBarItem(
title: Text('Search'), label: 'Search',
icon: Icon(Icons.search), icon: Icon(Icons.search),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
title: Text('Kanji'), label: 'Kanji',
icon: Text( icon: Text(
'', '',
style: TextStyle(fontSize: 18), style: TextStyle(fontSize: 18),
), ),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
title: Text('History'), label: 'History',
icon: Icon(Icons.bookmark), icon: Icon(Icons.bookmark),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
title: Text('Memorize'), label: 'Memorize',
icon: Icon(Icons.local_offer), icon: Icon(Icons.local_offer),
), ),
BottomNavigationBarItem( BottomNavigationBarItem(
title: Text('Settings'), label: 'Settings',
icon: Icon(Icons.settings), icon: Icon(Icons.settings),
), ),
]; ];
class Page { class _Page {
Widget content; Widget content;
Widget titleBar; Widget titleBar;
Page({ _Page({
this.content, this.content,
this.titleBar, this.titleBar,
}); });
} }
final List<Page> pages = [ final List<_Page> pages = [
Page(content: SearchView(), titleBar: Text('Search')), _Page(content: SearchView(), titleBar: Text('Search')),
Page( _Page(
content: KanjiView(), content: KanjiView(),
titleBar: KanjiViewBar(), titleBar: KanjiViewBar(),
), ),
Page( _Page(
content: HistoryView(), content: HistoryView(),
titleBar: Text("History"), titleBar: Text("History"),
), ),
Page( _Page(
content: Container(), content: Container(),
titleBar: Text("Memorization"), titleBar: Text("Memorization"),
), ),
Page( _Page(
content: Container(), content: Container(),
titleBar: Text("Settings"), titleBar: Text("Settings"),
), ),

View File

@ -1,7 +1,7 @@
import 'package:unofficial_jisho_api/api.dart' as jisho; import 'package:unofficial_jisho_api/api.dart' as jisho;
String _convertGrade(String grade) { String _convertGrade(String grade) {
const _conversionTable = { const conversionTable = {
"grade 1": "小1", "grade 1": "小1",
"grade 2": "小2", "grade 2": "小2",
"grade 3": "小3", "grade 3": "小3",
@ -11,9 +11,9 @@ String _convertGrade(String grade) {
"junior high": "" "junior high": ""
}; };
print('conversion run: $grade -> ${_conversionTable[grade]}'); print('conversion run: $grade -> ${conversionTable[grade]}');
return _conversionTable[grade]; return conversionTable[grade];
} }
Future<jisho.KanjiResult> fetchKanji(String kanji) async { Future<jisho.KanjiResult> fetchKanji(String kanji) async {

View File

@ -14,7 +14,7 @@ import 'parts/kunyomi.dart';
import 'parts/examples.dart'; import 'parts/examples.dart';
class KanjiResultCard extends StatelessWidget { class KanjiResultCard extends StatelessWidget {
final jisho.KanjiResult _result; final jisho.KanjiResult result;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -33,26 +33,26 @@ class KanjiResultCard extends StatelessWidget {
Flexible( Flexible(
flex: 1, flex: 1,
fit: FlexFit.tight, fit: FlexFit.tight,
child: Center(child: Header(_result.query)), child: Center(child: Header(result.query)),
), ),
Flexible( Flexible(
flex: 1, flex: 1,
fit: FlexFit.tight, fit: FlexFit.tight,
child: Center( child: Center(
child: Radical(_result.radical), child: Radical(result.radical),
), ),
), ),
], ],
), ),
), ),
Meaning(_result.meaning), Meaning(result.meaning),
_result.onyomi.length != 0 ? Onyomi(_result.onyomi) : SizedBox.shrink(), result.onyomi.length != 0 ? Onyomi(result.onyomi) : SizedBox.shrink(),
_result.kunyomi.length != 0 ? Kunyomi(_result.kunyomi) : SizedBox.shrink(), result.kunyomi.length != 0 ? Kunyomi(result.kunyomi) : SizedBox.shrink(),
IntrinsicHeight( IntrinsicHeight(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
StrokeOrderGif(_result.strokeOrderGifUri), StrokeOrderGif(result.strokeOrderGifUri),
Container( Container(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
@ -61,19 +61,19 @@ class KanjiResultCard extends StatelessWidget {
Row( Row(
children: [ children: [
Text("JLPT: ", style: TextStyle(fontSize: 20.0)), Text("JLPT: ", style: TextStyle(fontSize: 20.0)),
JlptLevel(_result.jlptLevel ?? ""), JlptLevel(result.jlptLevel ?? ""),
], ],
), ),
Row( Row(
children: [ children: [
Text("Grade: ", style: TextStyle(fontSize: 20.0)), Text("Grade: ", style: TextStyle(fontSize: 20.0)),
Grade(_result.taughtIn ?? ""), Grade(result.taughtIn ?? ""),
], ],
), ),
Row( Row(
children: [ children: [
Text("Rank: ", style: TextStyle(fontSize: 20.0)), Text("Rank: ", style: TextStyle(fontSize: 20.0)),
Rank(_result.newspaperFrequencyRank ?? -1), Rank(result.newspaperFrequencyRank ?? -1),
], ],
), ),
], ],
@ -82,10 +82,10 @@ class KanjiResultCard extends StatelessWidget {
], ],
), ),
), ),
Examples(_result.onyomiExamples, _result.kunyomiExamples), Examples(result.onyomiExamples, result.kunyomiExamples),
], ],
); );
} }
KanjiResultCard(this._result); KanjiResultCard(this.result);
} }

View File

@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart'; import 'package:unofficial_jisho_api/api.dart';
class Examples extends StatelessWidget { class Examples extends StatelessWidget {
final List<YomiExample> _onyomiExamples; final List<YomiExample> onyomiExamples;
final List<YomiExample> _kunyomiExamples; final List<YomiExample> kunyomiExamples;
const Examples( const Examples(
this._onyomiExamples, this.onyomiExamples,
this._kunyomiExamples, this.kunyomiExamples,
); );
@override @override
@ -30,10 +30,10 @@ class Examples extends StatelessWidget {
), ),
), ),
children: [ children: [
_onyomiExamples onyomiExamples
.map((onyomiExample) => _Example(onyomiExample, _KanaType.onyomi)) .map((onyomiExample) => _Example(onyomiExample, _KanaType.onyomi))
.toList(), .toList(),
_kunyomiExamples kunyomiExamples
.map((kunyomiExample) => .map((kunyomiExample) =>
_Example(kunyomiExample, _KanaType.kunyomi)) _Example(kunyomiExample, _KanaType.kunyomi))
.toList(), .toList(),
@ -44,10 +44,10 @@ class Examples extends StatelessWidget {
enum _KanaType { kunyomi, onyomi } enum _KanaType { kunyomi, onyomi }
class _Example extends StatelessWidget { class _Example extends StatelessWidget {
final _KanaType _kanaType; final _KanaType kanaType;
final YomiExample _yomiExample; final YomiExample yomiExample;
const _Example(this._yomiExample, this._kanaType); const _Example(this.yomiExample, this.kanaType);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -67,7 +67,7 @@ class _Example extends StatelessWidget {
horizontal: 10.0, horizontal: 10.0,
), ),
decoration: BoxDecoration( decoration: BoxDecoration(
color: (_kanaType == _KanaType.kunyomi) color: (kanaType == _KanaType.kunyomi)
? Colors.lightBlue ? Colors.lightBlue
: Colors.orange, : Colors.orange,
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
@ -79,7 +79,7 @@ class _Example extends StatelessWidget {
children: [ children: [
Container( Container(
child: Text( child: Text(
_yomiExample.reading, yomiExample.reading,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 15.0, fontSize: 15.0,
@ -91,7 +91,7 @@ class _Example extends StatelessWidget {
), ),
Container( Container(
child: Text( child: Text(
_yomiExample.example, yomiExample.example,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 20.0, fontSize: 20.0,
@ -109,7 +109,7 @@ class _Example extends StatelessWidget {
children: [ children: [
Container( Container(
child: Text( child: Text(
_yomiExample.meaning, yomiExample.meaning,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
), ),

View File

@ -1,14 +1,14 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Grade extends StatelessWidget { class Grade extends StatelessWidget {
final String _grade; final String grade;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
child: Text( child: Text(
_grade, grade,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 20.0, fontSize: 20.0,
@ -21,5 +21,5 @@ class Grade extends StatelessWidget {
); );
} }
Grade(this._grade); Grade(this.grade);
} }

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Header extends StatelessWidget { class Header extends StatelessWidget {
final String _kanji; final String kanji;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -11,12 +11,12 @@ class Header extends StatelessWidget {
child: Padding( child: Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Text( child: Text(
_kanji, kanji,
style: TextStyle(fontSize: 80.0, color: Colors.white), style: TextStyle(fontSize: 80.0, color: Colors.white),
), ),
), ),
); );
} }
Header(this._kanji); Header(this.kanji);
} }

View File

@ -2,14 +2,14 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class JlptLevel extends StatelessWidget { class JlptLevel extends StatelessWidget {
final String _jlptLevel; final String jlptLevel;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
child: Text( child: Text(
_jlptLevel, jlptLevel,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 20.0, fontSize: 20.0,
@ -22,5 +22,5 @@ class JlptLevel extends StatelessWidget {
); );
} }
JlptLevel(this._jlptLevel); JlptLevel(this.jlptLevel);
} }

View File

@ -1,13 +1,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Kunyomi extends StatelessWidget { class Kunyomi extends StatelessWidget {
final List<String> _kunyomi; final List<String> kunyomi;
List<_KunyomiCard> _kunyomiCards; List<_KunyomiCard> kunyomiCards;
bool _expandable; bool expandable;
Kunyomi(this._kunyomi) { Kunyomi(this.kunyomi) {
_kunyomiCards = _kunyomi.map((kunyomi) => _KunyomiCard(kunyomi)).toList(); kunyomiCards = kunyomi.map((kunyomi) => _KunyomiCard(kunyomi)).toList();
_expandable = (_kunyomi.length > 6); expandable = (kunyomi.length > 6);
} }
@override @override
@ -23,7 +23,7 @@ class Kunyomi extends StatelessWidget {
} }
Widget _KunyomiWrapper(BuildContext context) { Widget _KunyomiWrapper(BuildContext context) {
if (_expandable) { if (expandable) {
return ExpansionTile( return ExpansionTile(
initiallyExpanded: false, initiallyExpanded: false,
title: Center(child: _KunyomiCard('Kunyomi')), title: Center(child: _KunyomiCard('Kunyomi')),
@ -33,7 +33,7 @@ class Kunyomi extends StatelessWidget {
), ),
Wrap( Wrap(
runSpacing: 10.0, runSpacing: 10.0,
children: _kunyomiCards, children: kunyomiCards,
), ),
SizedBox( SizedBox(
height: 25.0, height: 25.0,
@ -43,15 +43,15 @@ class Kunyomi extends StatelessWidget {
} else { } else {
return Wrap( return Wrap(
runSpacing: 10.0, runSpacing: 10.0,
children: _kunyomiCards, children: kunyomiCards,
); );
} }
} }
} }
class _KunyomiCard extends StatelessWidget { class _KunyomiCard extends StatelessWidget {
final String _kunyomi; final String kunyomi;
const _KunyomiCard(this._kunyomi); const _KunyomiCard(this.kunyomi);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -62,7 +62,7 @@ class _KunyomiCard extends StatelessWidget {
horizontal: 10.0, horizontal: 10.0,
), ),
child: Text( child: Text(
_kunyomi, kunyomi,
style: TextStyle( style: TextStyle(
fontSize: 20.0, fontSize: 20.0,
color: Colors.white, color: Colors.white,

View File

@ -1,9 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Meaning extends StatelessWidget { class Meaning extends StatelessWidget {
List<String> _meanings; List<String> meanings;
List<_MeaningCard> _meaningCards; List<_MeaningCard> meaningCards;
bool _expandable; bool expandable;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -18,7 +18,7 @@ class Meaning extends StatelessWidget {
} }
Widget _MeaningWrapper(BuildContext context) { Widget _MeaningWrapper(BuildContext context) {
if (_expandable) { if (expandable) {
return ExpansionTile( return ExpansionTile(
initiallyExpanded: false, initiallyExpanded: false,
title: Center(child: _MeaningCard('Meanings')), title: Center(child: _MeaningCard('Meanings')),
@ -28,7 +28,7 @@ class Meaning extends StatelessWidget {
), ),
Wrap( Wrap(
runSpacing: 10.0, runSpacing: 10.0,
children: _meaningCards, children: meaningCards,
), ),
SizedBox( SizedBox(
height: 25.0, height: 25.0,
@ -38,21 +38,21 @@ class Meaning extends StatelessWidget {
} else { } else {
return Wrap( return Wrap(
runSpacing: 10.0, runSpacing: 10.0,
children: _meaningCards, children: meaningCards,
); );
} }
} }
Meaning(_meaning) { Meaning(meaning) {
this._meanings = _meaning.split(', '); this.meanings = meaning.split(', ');
this._meaningCards = this.meaningCards =
_meanings.map((meaning) => _MeaningCard(meaning)).toList(); meanings.map((m) => _MeaningCard(m)).toList();
this._expandable = (this._meanings.length > 6); this.expandable = (this.meanings.length > 6);
} }
} }
class _MeaningCard extends StatelessWidget { class _MeaningCard extends StatelessWidget {
final String _meaning; final String meaning;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -63,7 +63,7 @@ class _MeaningCard extends StatelessWidget {
vertical: 10.0, vertical: 10.0,
), ),
child: Text( child: Text(
_meaning, meaning,
style: TextStyle( style: TextStyle(
fontSize: 20.0, fontSize: 20.0,
color: Colors.white, color: Colors.white,
@ -76,5 +76,5 @@ class _MeaningCard extends StatelessWidget {
); );
} }
_MeaningCard(this._meaning); _MeaningCard(this.meaning);
} }

View File

@ -1,13 +1,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Onyomi extends StatelessWidget { class Onyomi extends StatelessWidget {
final List<String> _onyomi; final List<String> onyomi;
List<_OnyomiCard> _onyomiCards; List<_OnyomiCard> onyomiCards;
bool _expandable; bool expandable;
Onyomi(this._onyomi) { Onyomi(this.onyomi) {
_onyomiCards = _onyomi.map((onyomi) => _OnyomiCard(onyomi)).toList(); onyomiCards = onyomi.map((onyomi) => _OnyomiCard(onyomi)).toList();
_expandable = (_onyomi.length > 6); expandable = (onyomi.length > 6);
} }
@override @override
@ -23,7 +23,7 @@ class Onyomi extends StatelessWidget {
} }
Widget _OnyomiWrapper(BuildContext context) { Widget _OnyomiWrapper(BuildContext context) {
if (_expandable) { if (expandable) {
return ExpansionTile( return ExpansionTile(
initiallyExpanded: false, initiallyExpanded: false,
title: Center(child: _OnyomiCard('Onyomi')), title: Center(child: _OnyomiCard('Onyomi')),
@ -33,7 +33,7 @@ class Onyomi extends StatelessWidget {
), ),
Wrap( Wrap(
runSpacing: 10.0, runSpacing: 10.0,
children: _onyomiCards, children: onyomiCards,
), ),
SizedBox( SizedBox(
height: 25.0, height: 25.0,
@ -43,15 +43,15 @@ class Onyomi extends StatelessWidget {
} else { } else {
return Wrap( return Wrap(
runSpacing: 10.0, runSpacing: 10.0,
children: _onyomiCards, children: onyomiCards,
); );
} }
} }
} }
class _OnyomiCard extends StatelessWidget { class _OnyomiCard extends StatelessWidget {
final String _onyomi; final String onyomi;
const _OnyomiCard(this._onyomi); const _OnyomiCard(this.onyomi);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -62,7 +62,7 @@ class _OnyomiCard extends StatelessWidget {
horizontal: 10.0, horizontal: 10.0,
), ),
child: Text( child: Text(
_onyomi, onyomi,
style: TextStyle( style: TextStyle(
fontSize: 20.0, fontSize: 20.0,
color: Colors.white, color: Colors.white,

View File

@ -2,14 +2,14 @@ import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho; 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;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
child: Text( child: Text(
_radical.symbol, radical.symbol,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 40.0, fontSize: 40.0,
@ -22,5 +22,5 @@ class Radical extends StatelessWidget {
); );
} }
Radical(this._radical); Radical(this.radical);
} }

View File

@ -2,14 +2,14 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Rank extends StatelessWidget { class Rank extends StatelessWidget {
final int _rank; final int rank;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
child: Text( child: Text(
'${_rank.toString()} / 2500', '${rank.toString()} / 2500',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 20.0, fontSize: 20.0,
@ -22,5 +22,5 @@ class Rank extends StatelessWidget {
); );
} }
Rank(this._rank); Rank(this.rank);
} }

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class StrokeOrderGif extends StatelessWidget { class StrokeOrderGif extends StatelessWidget {
final String _uri; final String uri;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -9,7 +9,7 @@ class StrokeOrderGif extends StatelessWidget {
margin: EdgeInsets.symmetric(vertical: 20.0), margin: EdgeInsets.symmetric(vertical: 20.0),
padding: EdgeInsets.all(5.0), padding: EdgeInsets.all(5.0),
child: ClipRRect( child: ClipRRect(
child: Image.network(_uri), child: Image.network(uri),
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
), ),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -19,5 +19,5 @@ class StrokeOrderGif extends StatelessWidget {
); );
} }
StrokeOrderGif(this._uri); StrokeOrderGif(this.uri);
} }

View File

@ -3,8 +3,8 @@ 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 KanjiSuggestions extends StatelessWidget {
final List<String> _suggestions; final List<String> suggestions;
const KanjiSuggestions(this._suggestions); const KanjiSuggestions(this.suggestions);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -18,21 +18,21 @@ class KanjiSuggestions extends StatelessWidget {
crossAxisCount: 3, crossAxisCount: 3,
mainAxisSpacing: 20.0, mainAxisSpacing: 20.0,
crossAxisSpacing: 40.0, crossAxisSpacing: 40.0,
children: _suggestions.map((kanji) => _Suggestion(kanji)).toList(), children: suggestions.map((kanji) => _Suggestion(kanji)).toList(),
), ),
); );
} }
} }
class _Suggestion extends StatelessWidget { class _Suggestion extends StatelessWidget {
final String _kanji; final String kanji;
const _Suggestion(this._kanji); const _Suggestion(this.kanji);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InkWell( return InkWell(
onTap: () { onTap: () {
BlocProvider.of<KanjiBloc>(context).add(GetKanji(_kanji)); BlocProvider.of<KanjiBloc>(context).add(GetKanji(kanji));
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -43,7 +43,7 @@ class _Suggestion extends StatelessWidget {
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.white),
), ),
), ),

View File

@ -2,13 +2,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class LanguageSelector extends StatefulWidget { class LanguageSelector extends StatefulWidget {
@override @override
LanguageSelectorState createState() => new LanguageSelectorState(); _LanguageSelectorState createState() => new _LanguageSelectorState();
} }
class LanguageSelectorState extends State<LanguageSelector> { class _LanguageSelectorState extends State<LanguageSelector> {
List<bool> isSelected; List<bool> isSelected;
@override @override
@ -22,9 +20,9 @@ class LanguageSelectorState extends State<LanguageSelector> {
return ToggleButtons( return ToggleButtons(
isSelected: isSelected, isSelected: isSelected,
children: <Widget> [ children: <Widget> [
LanguageOption("Auto"), _LanguageOption("Auto"),
LanguageOption("Japanese"), _LanguageOption("Japanese"),
LanguageOption("English") _LanguageOption("English")
], ],
selectedColor: Colors.blue, selectedColor: Colors.blue,
onPressed: (int buttonIndex) { onPressed: (int buttonIndex) {
@ -39,17 +37,17 @@ class LanguageSelectorState extends State<LanguageSelector> {
} }
class LanguageOption extends StatelessWidget { class _LanguageOption extends StatelessWidget {
final String _language; final String language;
LanguageOption(this._language); _LanguageOption(this.language);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Expanded( return Expanded(
child: Container( child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0), padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
child: Center(child: Text(_language)), child: Center(child: Text(language)),
), ),
); );
} }

View File

@ -2,20 +2,20 @@ import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart'; 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
Widget build(BuildContext context) { Widget build(BuildContext context) {
final hasFurigana = (_word.word != null); final hasFurigana = (word.word != null);
return Container( return Container(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left: 10.0), padding: EdgeInsets.only(left: 10.0),
child: Column( child: Column(
children: [ children: [
(hasFurigana) ? Text(_word.reading) : Text(''), (hasFurigana) ? Text(word.reading) : Text(''),
(hasFurigana) ? Text(_word.word) : Text(_word.reading), (hasFurigana) ? Text(word.word) : Text(word.reading),
], ],
), ),
); );

View File

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart'; 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); OtherForms(this.otherForms);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -15,7 +15,7 @@ class OtherForms extends StatelessWidget {
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(fontWeight: FontWeight.bold),
), ),
Row( Row(
children: _otherForms.map((form) => _KanaBox(form)).toList(), children: otherForms.map((form) => _KanaBox(form)).toList(),
), ),
], ],
), ),
@ -24,18 +24,18 @@ 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
Widget build(BuildContext context) { Widget build(BuildContext context) {
final hasFurigana = (_word.word != null); final hasFurigana = (word.word != null);
return Container( return Container(
child: Column( child: Column(
children: [ children: [
(hasFurigana) ? Text(_word.reading) : Text(''), (hasFurigana) ? Text(word.reading) : Text(''),
(hasFurigana) ? Text(_word.word) : Text(_word.reading), (hasFurigana) ? Text(word.word) : Text(word.reading),
], ],
), ),
margin: EdgeInsets.symmetric( margin: EdgeInsets.symmetric(

View File

@ -2,24 +2,24 @@ import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/parser.dart'; 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
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<Widget> _senseWidgets = final List<Widget> senseWidgets =
_senses.map((sense) => _Sense(sense)).toList(); senses.map((sense) => _Sense(sense)).toList();
return Container( return Container(
child: Column( child: Column(
children: _senseWidgets, children: senseWidgets,
)); ));
} }
} }
class _Sense extends StatelessWidget { class _Sense extends StatelessWidget {
final JishoWordSense _sense; final JishoWordSense sense;
const _Sense(this._sense); const _Sense(this.sense);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -27,13 +27,13 @@ class _Sense extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
Text( Text(
_sense.parts_of_speech.join(', '), sense.parts_of_speech.join(', '),
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.left, textAlign: TextAlign.left,
), ),
Column( Column(
children: children:
_sense.english_definitions.map((def) => Text(def)).toList(), sense.english_definitions.map((def) => Text(def)).toList(),
) )
], ],
), ),

View File

@ -7,22 +7,22 @@ import './parts/senses.dart';
import './parts/other_forms.dart'; import './parts/other_forms.dart';
class SearchResultCard extends StatelessWidget { class SearchResultCard extends StatelessWidget {
final JishoResult _result; final JishoResult result;
JishoJapaneseWord _mainWord; JishoJapaneseWord mainWord;
List<JishoJapaneseWord> _otherForms; List<JishoJapaneseWord> otherForms;
SearchResultCard(this._result) { SearchResultCard(this.result) {
this._mainWord = _result.japanese[0]; this.mainWord = result.japanese[0];
this._otherForms = _result.japanese.sublist(1); this.otherForms = result.japanese.sublist(1);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ExpansionTile( return ExpansionTile(
title: JapaneseHeader(_mainWord), title: JapaneseHeader(mainWord),
children: [ children: [
Senses(_result.senses), Senses(result.senses),
OtherForms(_otherForms), OtherForms(otherForms),
], ],
); );
} }

View File

@ -76,60 +76,60 @@ class _KanjiTextField extends StatefulWidget {
enum TextFieldButton {clear, paste} enum TextFieldButton {clear, paste}
class _KanjiTextFieldState extends State<_KanjiTextField> { class _KanjiTextFieldState extends State<_KanjiTextField> {
FocusNode _focus = new FocusNode(); FocusNode focus = new FocusNode();
TextEditingController _textController = new TextEditingController(); TextEditingController textController = new TextEditingController();
TextFieldButton _button = TextFieldButton.paste; TextFieldButton button = TextFieldButton.paste;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_focus.addListener(_onFocusChange); focus.addListener(_onFocusChange);
} }
void _getKanjiSuggestions(String text) => void _getKanjiSuggestions(String text) =>
BlocProvider.of<KanjiBloc>(context).add(GetKanjiSuggestions(text)); BlocProvider.of<KanjiBloc>(context).add(GetKanjiSuggestions(text));
void updateSuggestions() => _getKanjiSuggestions(_textController.text); void updateSuggestions() => _getKanjiSuggestions(textController.text);
void _onFocusChange() { void _onFocusChange() {
debugPrint('TextField Focus Changed: ${_focus.hasFocus.toString()}'); debugPrint('TextField Focus Changed: ${focus.hasFocus.toString()}');
setState(() { setState(() {
_button = _focus.hasFocus ? TextFieldButton.clear : TextFieldButton.paste; button = focus.hasFocus ? TextFieldButton.clear : TextFieldButton.paste;
}); });
if (_focus.hasFocus) if (focus.hasFocus)
updateSuggestions(); updateSuggestions();
else else
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
} }
void _clearText() { void _clearText() {
_textController.text = ''; textController.text = '';
updateSuggestions(); updateSuggestions();
} }
void _pasteText() async { void _pasteText() async {
ClipboardData clipboardData = await Clipboard.getData('text/plain'); ClipboardData clipboardData = await Clipboard.getData('text/plain');
_textController.text = clipboardData.text; textController.text = clipboardData.text;
updateSuggestions(); updateSuggestions();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
IconButton _clearButton = IconButton( IconButton clearButton = IconButton(
icon: Icon(Icons.clear), icon: Icon(Icons.clear),
onPressed: () => _clearText(), onPressed: () => _clearText(),
); );
IconButton _pasteButton = IconButton( IconButton pasteButton = IconButton(
icon: Icon(Icons.content_paste), icon: Icon(Icons.content_paste),
onPressed: () => _pasteText(), onPressed: () => _pasteText(),
); );
return TextField( return TextField(
focusNode: _focus, focusNode: focus,
controller: _textController, controller: textController,
onChanged: (text) => _getKanjiSuggestions(text), onChanged: (text) => _getKanjiSuggestions(text),
onSubmitted: (text) => onSubmitted: (text) =>
BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)), BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
@ -143,7 +143,7 @@ class _KanjiTextFieldState extends State<_KanjiTextField> {
), ),
contentPadding: EdgeInsets.symmetric(vertical: 10.0), contentPadding: EdgeInsets.symmetric(vertical: 10.0),
isDense: false, isDense: false,
suffixIcon: (_button == TextFieldButton.clear) ? _clearButton : _pasteButton, suffixIcon: (button == TextFieldButton.clear) ? clearButton : pasteButton,
), ),
style: TextStyle( style: TextStyle(
fontSize: 14.0, fontSize: 14.0,