kopia lustrzana https://gitlab.com/mysocialportal/relatica
Fix search screen not properly clearing results on profile swap
rodzic
034343936e
commit
a536576a83
|
@ -35,11 +35,12 @@ class SearchScreen extends StatefulWidget {
|
|||
class _SearchScreenState extends State<SearchScreen> {
|
||||
static const limit = 50;
|
||||
static final _logger = Logger('$SearchScreen');
|
||||
var searchText = '';
|
||||
var searchTextController = TextEditingController();
|
||||
var searchType = SearchTypes.statusesText;
|
||||
var searching = false;
|
||||
PagingData nextPage = PagingData(limit: limit);
|
||||
var searchResult = SearchResults.empty();
|
||||
Profile? profileOfSearchRequest;
|
||||
|
||||
PagingData genNextPageData() {
|
||||
late final int offset;
|
||||
|
@ -71,13 +72,14 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
searching = true;
|
||||
});
|
||||
|
||||
print('Search $searchType on $searchText');
|
||||
final result =
|
||||
await SearchClient(profile).search(searchType, searchText, nextPage);
|
||||
print('Search $searchType on ${searchTextController.text}');
|
||||
final result = await SearchClient(profile)
|
||||
.search(searchType, searchTextController.text, nextPage);
|
||||
result.match(
|
||||
onSuccess: (result) {
|
||||
searchResult = reset ? result.data : searchResult.merge(result.data);
|
||||
nextPage = result.next ?? genNextPageData();
|
||||
profileOfSearchRequest = profile;
|
||||
},
|
||||
onError: (error) =>
|
||||
buildSnackbar(context, 'Error getting search result: $error'),
|
||||
|
@ -88,6 +90,15 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
print('Ending update');
|
||||
}
|
||||
|
||||
clearSearchResults() {
|
||||
print('Clearing results');
|
||||
setState(() {
|
||||
searchResult = SearchResults.empty();
|
||||
searchTextController.text = '';
|
||||
searching = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_logger.info('Build');
|
||||
|
@ -96,13 +107,17 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
final profile = profileService.currentProfile;
|
||||
late Widget body;
|
||||
|
||||
if (profile != profileOfSearchRequest) {
|
||||
clearSearchResults();
|
||||
}
|
||||
|
||||
if (searchResult.isEmpty && searching) {
|
||||
body = Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'Searching for ${searchType.toLabel()} on: $searchText',
|
||||
'Searching for ${searchType.toLabel()} on: ${searchTextController.text}',
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -112,7 +127,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
}
|
||||
|
||||
return Scaffold(
|
||||
drawer: const StandardAppDrawer(skipPopDismiss: true),
|
||||
drawer: const StandardAppDrawer(skipPopDismiss: false),
|
||||
body: SafeArea(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
|
@ -132,11 +147,9 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
onChanged: (value) {
|
||||
searchText = value;
|
||||
},
|
||||
controller: searchTextController,
|
||||
onSubmitted: (value) {
|
||||
searchText = value;
|
||||
searchTextController.text = value;
|
||||
updateSearchResults(profile);
|
||||
},
|
||||
onTapOutside: (event) {
|
||||
|
@ -293,9 +306,9 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(searchText.isEmpty
|
||||
Text(searchTextController.text.isEmpty
|
||||
? 'Type search text to search'
|
||||
: 'No results for ${searchType.toLabel()} search on: $searchText'),
|
||||
: 'No results for ${searchType.toLabel()} search on: ${searchTextController.text}'),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
Ładowanie…
Reference in New Issue