1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 21:47:29 +01:00

Add willpopscope to search page

This commit is contained in:
Oystein Kristoffer Tveit 2020-08-24 23:46:04 +02:00
parent c7f6f8c4b2
commit afe9243607
2 changed files with 38 additions and 31 deletions

View File

@ -28,7 +28,7 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
yield SearchError('Something went wrong'); yield SearchError('Something went wrong');
} }
} else if (event is ReturnToInitialState) { } else if (event is ReturnToInitialState) {
yield SearchInitial();
} }
} }
} }

View File

@ -8,33 +8,40 @@ class SearchView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocListener<SearchBloc, SearchState>( return BlocListener<SearchBloc, SearchState>(
listener: (context, state) { listener: (context, state) {},
},
child: BlocBuilder<SearchBloc, SearchState>( child: BlocBuilder<SearchBloc, SearchState>(
builder: (context, state) { builder: (context, state) {
if (state is SearchInitial) return _InitialView(); if (state is SearchInitial)
else if (state is SearchLoading) return LoadingScreen(); return _InitialView();
else if (state is SearchLoading)
return LoadingScreen();
else if (state is SearchFinished) { else if (state is SearchFinished) {
return ListView( return WillPopScope(
children: state.results.map((result) => SearchResultCard(result)).toList(), 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';
}, },
) ));
);
} }
} }
class _InitialView extends StatelessWidget { class _InitialView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
mainAxisAlignment: MainAxisAlignment.center,
children: [
SearchBar(), SearchBar(),
] ]);
);
} }
} }
@ -53,8 +60,7 @@ class _LanguageOption extends StatelessWidget {
color: Colors.black, color: Colors.black,
width: 1.0, width: 1.0,
), ),
color: _color color: _color),
),
), ),
); );
} }
@ -70,7 +76,8 @@ class SearchBar extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
TextField( TextField(
onSubmitted: (text) => BlocProvider.of<SearchBloc>(context).add(GetSearchResults(text)), onSubmitted: (text) => BlocProvider.of<SearchBloc>(context)
.add(GetSearchResults(text)),
controller: TextEditingController(), controller: TextEditingController(),
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Search', labelText: 'Search',