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

Placed keyboard logic inside bloc listener

This commit is contained in:
Oystein Kristoffer Tveit 2020-07-22 14:13:53 +02:00
parent 76d2b090f3
commit 689983b848
2 changed files with 41 additions and 27 deletions

View File

@ -32,7 +32,6 @@ class _Suggestion extends StatelessWidget {
Widget build(BuildContext context) {
return InkWell(
onTap: () {
FocusScope.of(context).unfocus(); //Puts away the keyboard
BlocProvider.of<KanjiBloc>(context).add(GetKanji(_kanji));
},
child: Container(

View File

@ -9,23 +9,33 @@ import 'package:jisho_study_tool/components/loading.dart';
class KanjiView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<KanjiBloc, KanjiState>(
builder: (context, state) {
if (state is KanjiSearchInitial)
return Container();
else if (state is KanjiSearchInput)
return KanjiSuggestions(state.kanjiSuggestions);
else if (state is KanjiSearchLoading)
return LoadingScreen();
else if (state is KanjiSearchFinished)
return WillPopScope(
child: KanjiResultCard(state.kanji),
onWillPop: () async {
BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState());
return false;
});
throw 'No such event found';
return BlocListener<KanjiBloc, KanjiState>(
listener: (context, state) {
if (state is KanjiSearchInitial) {
FocusScope.of(context).unfocus();
} else if (state is KanjiSearchLoading) {
FocusScope.of(context).unfocus();
}
},
child: BlocBuilder<KanjiBloc, KanjiState>(
builder: (context, state) {
if (state is KanjiSearchInitial) {
return Container();
} else if (state is KanjiSearchInput)
return KanjiSuggestions(state.kanjiSuggestions);
else if (state is KanjiSearchLoading)
return LoadingScreen();
else if (state is KanjiSearchFinished)
return WillPopScope(
child: KanjiResultCard(state.kanji),
onWillPop: () async {
BlocProvider.of<KanjiBloc>(context)
.add(ReturnToInitialState());
return false;
});
throw 'No such event found';
},
),
);
}
}
@ -38,23 +48,28 @@ class KanjiViewBar extends StatelessWidget {
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => BlocProvider.of<KanjiBloc>(context)
.add(ReturnToInitialState()),
onPressed: () =>
BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState()),
),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
onChanged: (text) => BlocProvider.of<KanjiBloc>(context).add(GetKanjiSuggestions(text)),
onChanged: (text) => BlocProvider.of<KanjiBloc>(context)
.add(GetKanjiSuggestions(text)),
onSubmitted: (text) =>
BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
decoration: new InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'Search for kanji',
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(100.0)),
prefixIcon: Icon(Icons.search),
hintText: 'Search for kanji',
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(100.0),
),
contentPadding: EdgeInsets.symmetric(vertical: 10.0),
isDense: false),
style: TextStyle(
fontSize: 14.0,
),
),
),