2020-07-09 22:17:10 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-08-19 18:25:45 +02:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:jisho_study_tool/bloc/search/search_bloc.dart';
|
2021-03-05 22:12:04 +01:00
|
|
|
import 'package:jisho_study_tool/view/components/search/search_bar.dart';
|
2021-03-02 22:26:59 +01:00
|
|
|
import 'package:jisho_study_tool/view/screens/loading.dart';
|
2021-03-02 23:09:56 +01:00
|
|
|
import 'package:jisho_study_tool/view/components/search/search_result_page/search_card.dart';
|
2020-07-09 22:17:10 +02:00
|
|
|
|
|
|
|
class SearchView extends StatelessWidget {
|
2020-08-19 18:25:45 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-08-03 22:13:50 +02:00
|
|
|
return BlocConsumer<SearchBloc, SearchState>(
|
|
|
|
listener: (context, state) {},
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is SearchInitial)
|
|
|
|
return _InitialView();
|
|
|
|
else if (state is SearchLoading)
|
|
|
|
return LoadingScreen();
|
|
|
|
else if (state is SearchFinished) {
|
|
|
|
return WillPopScope(
|
|
|
|
child: ListView(
|
|
|
|
children: state.results
|
|
|
|
.map((result) => SearchResultCard(result))
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
onWillPop: () async {
|
|
|
|
BlocProvider.of<SearchBloc>(context).add(ReturnToInitialState());
|
|
|
|
print('Popped');
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
throw 'No such event found';
|
|
|
|
},
|
|
|
|
);
|
2020-08-19 18:25:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _InitialView extends StatelessWidget {
|
2020-07-09 22:17:10 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-08-24 23:46:04 +02:00
|
|
|
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
|
|
|
SearchBar(),
|
|
|
|
]);
|
2020-07-09 22:17:10 +02:00
|
|
|
}
|
2021-08-03 22:13:50 +02:00
|
|
|
}
|