2020-06-30 15:15:31 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-07-13 21:21:33 +02:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
|
|
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
|
|
|
|
import 'package:jisho_study_tool/components/kanji/kanji__search_page/kanji_search_page.dart';
|
2020-07-21 23:29:02 +02:00
|
|
|
import 'package:jisho_study_tool/components/kanji/kanji_suggestions.dart';
|
2020-07-13 21:21:33 +02:00
|
|
|
import 'package:jisho_study_tool/components/loading.dart';
|
2020-06-30 15:15:31 +02:00
|
|
|
|
2020-07-09 22:17:10 +02:00
|
|
|
class KanjiView extends StatelessWidget {
|
2020-07-13 21:21:33 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocBuilder<KanjiBloc, KanjiState>(
|
|
|
|
builder: (context, state) {
|
2020-07-14 14:33:21 +02:00
|
|
|
if (state is KanjiSearchInitial)
|
|
|
|
return Container();
|
2020-07-21 23:29:02 +02:00
|
|
|
else if (state is KanjiSearchInput)
|
|
|
|
return KanjiSuggestions(state.kanjiSuggestions);
|
2020-07-14 14:33:21 +02:00
|
|
|
else if (state is KanjiSearchLoading)
|
|
|
|
return LoadingScreen();
|
|
|
|
else if (state is KanjiSearchFinished)
|
2020-07-14 14:44:06 +02:00
|
|
|
return WillPopScope(
|
|
|
|
child: KanjiResultCard(state.kanji),
|
|
|
|
onWillPop: () async {
|
|
|
|
BlocProvider.of<KanjiBloc>(context).add(ReturnToInitialState());
|
|
|
|
return false;
|
|
|
|
});
|
2020-07-13 21:21:33 +02:00
|
|
|
throw 'No such event found';
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:52:48 +02:00
|
|
|
class KanjiViewBar extends StatelessWidget {
|
2020-07-13 21:21:33 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-07-16 14:08:02 +02:00
|
|
|
return Container(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.arrow_back),
|
|
|
|
onPressed: () => BlocProvider.of<KanjiBloc>(context)
|
|
|
|
.add(ReturnToInitialState()),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 10.0),
|
|
|
|
child: TextField(
|
2020-07-21 23:29:02 +02:00
|
|
|
onChanged: (text) => BlocProvider.of<KanjiBloc>(context).add(GetKanjiSuggestions(text)),
|
2020-07-16 14:08:02 +02:00
|
|
|
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)),
|
2020-07-14 14:33:21 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-07-16 14:08:02 +02:00
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.star_border),
|
|
|
|
onPressed: null,
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.add),
|
|
|
|
onPressed: null,
|
|
|
|
),
|
|
|
|
],
|
2020-07-13 21:21:33 +02:00
|
|
|
),
|
|
|
|
);
|
2020-06-30 15:15:31 +02:00
|
|
|
}
|
2020-07-14 14:33:21 +02:00
|
|
|
}
|