algolia / algolia/algoliasearch-helper-flutter

It is not updated immediately.

Open
#58 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Dart
Stars
27
Forks
21
Avg merge
1h 19m
Merged PRs (30d)
1

Description

When you add or modify record, it is not updated immediately.
Can you improve this?
Thank you.

flutter web
algolia_helper_flutter: ^0.2.3

```

late HitsSearcher hitSearcher;
final TextEditingController searchText = TextEditingController();
PagingController pagingController =
PagingController(firstPageKey: 0);
Stream get _searchPage =>
hitSearcher.responses.map(HitsPage.fromResponse);

@override
void initState() {
/// Algolia DB 검색
Account account = ref.read(Dependency.account);
hitSearcher = HitsSearcher.create(
applicationID: AlgoliaCredentials.applicationID,
apiKey: account.securedKey!,
state: const SearchState(
indexName: AlgoliaCredentials.addressLabelIndex,
//query: '',
));

searchText.addListener(() {
hitSearcher.query(searchText.text);
pagingController.refresh();
});

_searchPage.listen((HitsPage page) {
if (page.pageKey == 0) {
pagingController.refresh();
}
pagingController.appendPage(page.items, page.nextPageKey);
}).onError((error) => pagingController.error = error);

pagingController.addPageRequestListener((int pageKey) {
/// data fetch
hitSearcher
.applyState((SearchState state) => state.copyWith(page: pageKey));
});
super.initState();
}

@override
void dispose() {
hitSearcher.dispose();
searchText.dispose();
super.dispose();
}

Future _refresh() async {
hitSearcher.query('');
Future.delayed(const Duration(seconds: 1), () {
pagingController.refresh();
});

if (mounted) {
return Future.value();
}
}

@override
Widget build(BuildContext context) {
.....

PagedSliverList(
pagingController: pagingController,
builderDelegate: PagedChildBuilderDelegate(
noItemsFoundIndicatorBuilder: (_) =>
NoItemFoundMessageView(),
itemBuilder: (BuildContext context, LabelData item,
int index) =>
Center(
child: SizedBox(
width: 700.0,
child: ListTile(
leading: const Icon(FluentIcons.tag_24_regular),
title: Text(
item.name,
style: context.titleMedium,
), ),
),
),
),
)
```

https://user-images.githubusercontent.com/49754877/209442778-f8fd2739-3119-487b-86a0-4438a01bb4de.mov

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the delayed update in the provided Flutter web example, focusing on initState, the searchText listener, pagingController, and _refresh. Determine when a record is added or modified and when the displayed results refresh; done means the new or changed record appears immediately after the operation.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
frontend, search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.