SmartSearchMultiController<T, K> constructor

SmartSearchMultiController<T, K>({
  1. required SmartPaginationCubit<T> cubit,
  2. required PaginationRequest searchRequestBuilder(
    1. String query
    ),
  3. SmartSearchConfig config = const SmartSearchConfig(),
  4. void onSelected(
    1. List<T> items,
    2. List<K> keys
    )?,
  5. List<T>? initialSelectedValues,
  6. List<K>? selectedKeys,
  7. K keyExtractor(
    1. T item
    )?,
  8. String selectedKeyLabelBuilder(
    1. K key
    )?,
  9. int? maxSelections,
})

Implementation

SmartSearchMultiController({
  required SmartPaginationCubit<T> cubit,
  required PaginationRequest Function(String query) searchRequestBuilder,
  SmartSearchConfig config = const SmartSearchConfig(),
  void Function(List<T> items, List<K> keys)? onSelected,
  List<T>? initialSelectedValues,
  List<K>? selectedKeys,
  K Function(T item)? keyExtractor,
  String Function(K key)? selectedKeyLabelBuilder,
  int? maxSelections,
})  : _cubit = cubit,
      _searchRequestBuilder = searchRequestBuilder,
      _config = config,
      _onSelected = onSelected,
      _keyExtractor = keyExtractor,
      _selectedKeyLabelBuilder = selectedKeyLabelBuilder,
      _selectedItems = List<T>.from(initialSelectedValues ?? []),
      _selectedKeys = _initializeSelectedKeys(
        initialSelectedValues,
        selectedKeys,
        keyExtractor,
      ),
      _pendingKeys = selectedKeys != null && initialSelectedValues == null
          ? Set<K>.from(selectedKeys)
          : <K>{},
      _maxSelections = maxSelections {
  _textController = TextEditingController();
  _focusNode = FocusNode();
  _textController.addListener(_onTextChanged);
  _focusNode.addListener(_onFocusChanged);

  // Listen to cubit state changes to sync pending keys with loaded data
  if (_pendingKeys.isNotEmpty) {
    _cubitSubscription = _cubit.stream.listen(_onCubitStateChanged);
  }

  // Fetch initial data if configured
  if (_config.fetchOnInit && _config.searchOnEmpty) {
    _performSearch('', force: true);
  }
}