getSuggestedPosition<T> static method

int getSuggestedPosition<T>(
  1. T query,
  2. List<T>? list
)

Gets the suggested position of the given query in the provided list.

The method iterates through the list and returns the index of the first occurrence of the query. If the query is not found, it returns the default index, which is the length of the list.

Parameters:

  • query: The item to search for in the list.
  • list: The list of items where the query will be searched.

Returns: The suggested position (index) of the query in the list.

Implementation

static int getSuggestedPosition<T>(T query, List<T>? list) {
  int index = 0;
  if (list != null && list.isNotEmpty) {
    for (index = 0; index < list.length; index++) {
      if (query == list[index]) {
        return index;
      }
    }
  }
  return index;
}