SmartSearchMultiController<T, K> constructor
SmartSearchMultiController<T, K> ({
- required SmartPaginationCubit<
T> cubit, - required PaginationRequest searchRequestBuilder(
- String query
- SmartSearchConfig config = const SmartSearchConfig(),
- void onSelected()?,
- List<
T> ? initialSelectedValues, - List<
K> ? selectedKeys, - K keyExtractor(
- T item
- String selectedKeyLabelBuilder(
- K key
- 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);
}
}