Skip to content

Commit

Permalink
Update with Necessary changes in file autocomplete.dart and removed u…
Browse files Browse the repository at this point in the history
…nnecessary changes
  • Loading branch information
AshutoshKhadse23 authored Jan 8, 2025
1 parent d9f88f3 commit c8c4abe
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/widgets/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class AutocompleteField<QueryT extends AutocompleteQuery, ResultT exten

class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends AutocompleteResult> extends State<AutocompleteField<QueryT, ResultT>> with PerAccountStoreAwareStateMixin<AutocompleteField<QueryT, ResultT>> {
AutocompleteView<QueryT, ResultT>? _viewModel;
final ScrollController _scrollController = ScrollController();

void _initViewModel(QueryT query) {
_viewModel = widget.initViewModel(context, query)
Expand All @@ -57,7 +58,13 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
_initViewModel(newQuery);
} else {
assert(_viewModel!.acceptsQuery(newQuery));
final oldQuery = _viewModel!.query;
_viewModel!.query = newQuery;
// Reset scroll when query content changes
if (oldQuery.toString() != newQuery.toString() &&
_scrollController.hasClients) {
_scrollController.jumpTo(0);
}
}
}
}
Expand Down Expand Up @@ -91,6 +98,7 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
void dispose() {
widget.controller.removeListener(_handleControllerChange);
_viewModel?.dispose(); // removes our listener
_scrollController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -133,6 +141,7 @@ class _AutocompleteFieldState<QueryT extends AutocompleteQuery, ResultT extends
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 300), // TODO not hard-coded
child: ListView.builder(
controller: _scrollController,
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: _resultsToDisplay.length,
Expand Down

0 comments on commit c8c4abe

Please sign in to comment.