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';
|
|
|
|
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-06-30 15:15:31 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-07-13 21:21:33 +02:00
|
|
|
return BlocProvider(
|
|
|
|
create: (context) => KanjiBloc(),
|
|
|
|
child: _KanjiSearchPage(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _KanjiSearchPage extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocBuilder<KanjiBloc, KanjiState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is KanjiSearchInitial) return KanjiSearchBar();
|
|
|
|
else if (state is KanjiSearchLoading) return LoadingScreen();
|
|
|
|
else if (state is KanjiSearchFinished) return KanjiResultCard(state.kanji);
|
|
|
|
|
|
|
|
throw 'No such event found';
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class KanjiSearchBar extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Center(
|
|
|
|
child: TextField(
|
|
|
|
onSubmitted: (text) => BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
|
|
|
|
decoration: new InputDecoration(
|
|
|
|
prefixIcon: Icon(Icons.search),
|
|
|
|
hintText: 'Search for kanji'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-06-30 15:15:31 +02:00
|
|
|
}
|
2020-07-11 13:37:46 +02:00
|
|
|
}
|