selection property

SelectionModel<T> get selection
inherited

The selection model this container represents.

Implementation

late SelectionModel<T> selection;
  1. @override
set selection (SelectionModel<T> selection)
override

The selection model this container represents.

Implementation

@override
set selection(SelectionModel<T> selection) {
  super.selection = selection;
  activeModel.activateFirstItemByDefault =
      (isSingleSelect && accessibleItemActivation) ||
          (isMultiSelect && !accessibleItemActivation);

  if (isSingleSelect && selection.selectedValues.isNotEmpty) {
    _lastSelectedItem = selection.selectedValues.first;
    if (_isInitialized) {
      // Make sure input text is initialized correctly regardless of input
      // order. Specified input text should take precedence over selection
      // status.
      inputText = itemRenderer(_lastSelectedItem as T);
    }
  }
  _selectionListener?.cancel();
  _selectionListener = selection.selectionChanges.listen((_) {
    // If the input fields shows the selected value then update it if the
    // selection changes or clear it if the selection model is empty.
    if (shouldClearInputOnSelection) {
      inputText = '';
    } else if (isSingleSelect) {
      var selectedItem = selection.selectedValues.isNotEmpty
          ? selection.selectedValues.first
          : null;
      // Make sure that the change was not caused by this component.
      if (_lastSelectedItem != selectedItem) {
        _lastSelectedItem = selectedItem;
        inputText =
            _lastSelectedItem != null ? itemRenderer(_lastSelectedItem as T) : '';
      }
    }
    emitSelectionChange();
  });
}