Placed keyboard logic inside bloc listener
This commit is contained in:
parent
76d2b090f3
commit
689983b848
|
@ -32,7 +32,6 @@ class _Suggestion extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
FocusScope.of(context).unfocus(); //Puts away the keyboard
|
|
||||||
BlocProvider.of<KanjiBloc>(context).add(GetKanji(_kanji));
|
BlocProvider.of<KanjiBloc>(context).add(GetKanji(_kanji));
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
|
|
|
@ -9,11 +9,19 @@ import 'package:jisho_study_tool/components/loading.dart';
|
||||||
class KanjiView extends StatelessWidget {
|
class KanjiView extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<KanjiBloc, KanjiState>(
|
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) {
|
builder: (context, state) {
|
||||||
if (state is KanjiSearchInitial)
|
if (state is KanjiSearchInitial) {
|
||||||
return Container();
|
return Container();
|
||||||
else if (state is KanjiSearchInput)
|
} else if (state is KanjiSearchInput)
|
||||||
return KanjiSuggestions(state.kanjiSuggestions);
|
return KanjiSuggestions(state.kanjiSuggestions);
|
||||||
else if (state is KanjiSearchLoading)
|
else if (state is KanjiSearchLoading)
|
||||||
return LoadingScreen();
|
return LoadingScreen();
|
||||||
|
@ -21,11 +29,13 @@ class KanjiView extends StatelessWidget {
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
child: KanjiResultCard(state.kanji),
|
child: KanjiResultCard(state.kanji),
|
||||||
onWillPop: () async {
|
onWillPop: () async {
|
||||||
BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState());
|
BlocProvider.of<KanjiBloc>(context)
|
||||||
|
.add(ReturnToInitialState());
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
throw 'No such event found';
|
throw 'No such event found';
|
||||||
},
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,14 +48,14 @@ class KanjiViewBar extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.arrow_back),
|
icon: Icon(Icons.arrow_back),
|
||||||
onPressed: () => BlocProvider.of<KanjiBloc>(context)
|
onPressed: () =>
|
||||||
.add(ReturnToInitialState()),
|
BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState()),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.symmetric(vertical: 10.0),
|
|
||||||
child: TextField(
|
child: TextField(
|
||||||
onChanged: (text) => BlocProvider.of<KanjiBloc>(context).add(GetKanjiSuggestions(text)),
|
onChanged: (text) => BlocProvider.of<KanjiBloc>(context)
|
||||||
|
.add(GetKanjiSuggestions(text)),
|
||||||
onSubmitted: (text) =>
|
onSubmitted: (text) =>
|
||||||
BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
|
BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
|
||||||
decoration: new InputDecoration(
|
decoration: new InputDecoration(
|
||||||
|
@ -54,7 +64,12 @@ class KanjiViewBar extends StatelessWidget {
|
||||||
fillColor: Colors.white,
|
fillColor: Colors.white,
|
||||||
filled: true,
|
filled: true,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(100.0)),
|
borderRadius: BorderRadius.circular(100.0),
|
||||||
|
),
|
||||||
|
contentPadding: EdgeInsets.symmetric(vertical: 10.0),
|
||||||
|
isDense: false),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue