Skip to content

Bug: searchFilter overrides input and sessionToken, completely breaking autocomplete search #70

@CaptainRiley

Description

@CaptainRiley

Description
When passing a custom searchFilter into the widget (for example, to restrict search results to a specific region or language), the autocomplete search stops working altogether and returns no results.

Steps to Reproduce
Pass any custom searchFilter parameter to the location picker widget. For example:

dart

searchFilter: AutocompleteSearchFilter(
  regionCode: 'ro',
  languageCode: 'ro_RO',
  includedRegionCodes: ['ro'],
),

When you type a query into the search field, no suggestions are returned.

Expected Behavior
The custom filter rules (like regionCode) should be applied alongside the user's typed search query (input) and the generated sessionToken.

Actual Behavior
The location search returns no results because the Google Places API is never fed the user's actual text query.

Root Cause
In src/autocomplete_service.dart, the autocomplete request receives its parameters like this:

filter: filter ??
  AutocompleteSearchFilter(
    input: query,
    sessionToken: sessionToken.token,
  ),

If a filter is provided by the user, the ?? operator completely skips the right side of the expression. This means the input (the text the user typed) and sessionToken are never attached to the request. Because input is empty, the Google Places API does not know what to search for and fails.

Proposed Fix
The existing filter needs to be merged with the required input and sessionToken for the query. Assuming AutocompleteSearchFilter has (or can be given) a .copyWith method, the code should be updated to:

filter: (filter ?? AutocompleteSearchFilter()).copyWith(
  input: query,
  sessionToken: sessionToken.token,
),

This guarantees that user-defined filters (like regions or languages) are kept intact, while always safely injecting the typed query and sessionToken needed to perform the API call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions