copyWith method

AnticipateModel copyWith({
  1. String? value,
  2. int? selectedIndex,
  3. bool? focused,
  4. List<String>? filteredSuggestions,
})

Creates a copy with updated fields.

Implementation

AnticipateModel copyWith({
  String? value,
  int? selectedIndex,
  bool? focused,
  List<String>? filteredSuggestions,
}) {
  final newModel = AnticipateModel(
    prompt: prompt,
    placeholder: placeholder,
    suggestions: suggestions,
    defaultValue: defaultValue,
    config: config,
    keyMap: keyMap,
    promptStyle: _promptStyle,
    textStyle: _textStyle,
    placeholderStyle: _placeholderStyle,
    suggestionStyle: _suggestionStyle,
    selectedSuggestionStyle: _selectedSuggestionStyle,
  );
  newModel._value = value ?? _value;
  newModel._selectedIndex = selectedIndex ?? _selectedIndex;
  newModel._focused = focused ?? _focused;

  if (filteredSuggestions != null) {
    newModel._filteredSuggestions = filteredSuggestions;
  } else if (value != null) {
    // If the value changed, recompute suggestions deterministically.
    newModel._updateFilteredSuggestions();
  } else {
    newModel._filteredSuggestions = _filteredSuggestions;
  }
  return newModel;
}