Jisho-Study-Tool/lib/view/screens/kanji/view.dart

72 lines
2.1 KiB
Dart
Raw Normal View History

2021-07-17 12:19:03 +02:00
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';
2021-03-02 22:26:59 +01:00
import 'package:jisho_study_tool/view/screens/loading.dart';
2021-07-17 12:19:03 +02:00
2021-07-19 01:47:12 +02:00
import 'search.dart';
2021-07-17 12:19:03 +02:00
import 'result.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 BlocListener<KanjiBloc, KanjiState>(
listener: (context, state) {
2021-07-17 12:19:03 +02:00
if (state is KanjiSearch && state.type == KanjiSearchType.Initial) {
FocusScope.of(context).unfocus();
} else if (state is KanjiSearchLoading) {
FocusScope.of(context).unfocus();
}
2020-07-13 21:21:33 +02:00
},
child: BlocBuilder<KanjiBloc, KanjiState>(
builder: (context, state) {
2021-07-17 12:19:03 +02:00
if (state is KanjiSearch) {
2021-07-19 01:47:12 +02:00
if (state.type == KanjiSearchType.Initial) return SearchScreen();
else if (state is KanjiSearchKeyboard) return SearchScreen();
2021-07-17 12:19:03 +02:00
}
2020-08-19 18:25:45 +02:00
else if (state is KanjiSearchLoading) return LoadingScreen();
else if (state is KanjiSearchFinished)
return WillPopScope(
2021-07-26 21:39:17 +02:00
child: KanjiResultCard(result: state.kanji),
onWillPop: () async {
BlocProvider.of<KanjiBloc>(context)
.add(ReturnToInitialState());
return false;
});
throw 'No such event found';
},
),
2020-07-13 21:21:33 +02:00
);
}
}
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()),
2020-07-16 14:08:02 +02:00
),
2021-07-17 12:19:03 +02:00
// Expanded(
// child: Container(
// child: KanjiSearchBar(),
// ),
// ),
// IconButton(
// icon: Icon(Icons.star_border),
// onPressed: null,
// ),
// IconButton(
// icon: Icon(Icons.add),
// onPressed: null,
// ),
2020-07-16 14:08:02 +02:00
],
2020-07-13 21:21:33 +02:00
),
);
2020-06-30 15:15:31 +02:00
}
2021-03-05 22:08:34 +01:00
}