mirror of
https://github.com/h7x4/Jisho-Study-Tool.git
synced 2024-12-21 13:37:29 +01:00
Add willpopscope to search page
This commit is contained in:
parent
c7f6f8c4b2
commit
afe9243607
@ -28,7 +28,7 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
|
||||
yield SearchError('Something went wrong');
|
||||
}
|
||||
} else if (event is ReturnToInitialState) {
|
||||
|
||||
yield SearchInitial();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,33 +8,40 @@ class SearchView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<SearchBloc, SearchState>(
|
||||
listener: (context, state) {
|
||||
},
|
||||
child: BlocBuilder<SearchBloc, SearchState>(
|
||||
builder: (context, state) {
|
||||
if (state is SearchInitial) return _InitialView();
|
||||
else if (state is SearchLoading) return LoadingScreen();
|
||||
else if (state is SearchFinished) {
|
||||
return ListView(
|
||||
children: state.results.map((result) => SearchResultCard(result)).toList(),
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
);
|
||||
listener: (context, state) {},
|
||||
child: BlocBuilder<SearchBloc, SearchState>(
|
||||
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';
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class _InitialView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SearchBar(),
|
||||
]
|
||||
);
|
||||
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
SearchBar(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,12 +56,11 @@ class _LanguageOption extends StatelessWidget {
|
||||
padding: EdgeInsets.symmetric(vertical: 10.0),
|
||||
child: Center(child: Text(_language)),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.black,
|
||||
width: 1.0,
|
||||
),
|
||||
color: _color
|
||||
),
|
||||
border: Border.all(
|
||||
color: Colors.black,
|
||||
width: 1.0,
|
||||
),
|
||||
color: _color),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -70,7 +76,8 @@ class SearchBar extends StatelessWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
onSubmitted: (text) => BlocProvider.of<SearchBloc>(context).add(GetSearchResults(text)),
|
||||
onSubmitted: (text) => BlocProvider.of<SearchBloc>(context)
|
||||
.add(GetSearchResults(text)),
|
||||
controller: TextEditingController(),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Search',
|
||||
|
Loading…
Reference in New Issue
Block a user