TListController<T, K> class
A powerful controller for managing list state and operations.
TListController provides comprehensive list management with:
- Pagination: Client-side and server-side pagination
- Selection: Single and multiple item selection
- Expansion: Hierarchical item expansion/collapse
- Search: Debounced search with filtering
- Reordering: Drag-and-drop item reordering
- Loading: Async data loading with error handling
Client-Side Usage
final controller = TListController<Product, int>(
items: products,
itemsPerPage: 10,
itemKey: (product) => product.id,
selectionMode: TSelectionMode.multiple,
);
// Use with TList
TList<Product, int>(
controller: controller,
itemBuilder: (context, item, index) {
return ProductCard(product: item.data);
},
)
Server-Side Usage
final controller = TListController<User, int>(
itemsPerPage: 25,
itemKey: (user) => user.id,
onLoad: (options) async {
final response = await api.getUsers(
page: options.page,
limit: options.itemsPerPage,
search: options.search,
);
return TLoadResult(
response.users,
response.total,
);
},
);
With Selection
// Select items
controller.selectItem(product);
controller.selectAll();
// Get selected items
final selected = controller.selectedItems;
print('Selected: ${controller.selectedCount}');
With Search
controller.handleSearchChange('query');
Type parameters:
T: The type of items in the listK: The type of the item key (must be String, int, double, num, or bool)
See also:
- TList for the list widget
- TDataTable for tabular data display
- TListState for the state model
- Inheritance
-
- Object
- ChangeNotifier
- ValueNotifier<
TListState< T, K> > - TListController
- Available extensions
Constructors
-
TListController({List<
T> items = const [], int itemsPerPage = 0, String search = '', int? searchDelay, TSelectionMode selectionMode = TSelectionMode.none, TExpansionMode expansionMode = TExpansionMode.none, TLoadListener<T> ? onLoad, ItemKeyAccessor<T, K> ? itemKey, ItemToString<T> ? itemToString, ItemChildrenAccessor<T> ? itemChildren, bool reorderable = false, void onReorder(int oldIndex, int newIndex)?, bool autoSelectFirst = false, bool autoExpandFirst = false, Iterable<K> ? initialSelectedKeys, Iterable<K> ? initialExpandedKeys, bool loading = false, bool hasMoreItems = true, bool loadOnSearchOnly = false}) - Creates a list controller.
Properties
-
advancedSearch
→ Map<
String, dynamic> ? -
Available on TListController<
Current advanced search filters.T, K> , provided by the TListControllerPagination extensionno setter - autoExpandFirst → bool
-
Whether to automatically expand the first item when items are loaded.
final
- autoSelectFirst → bool
-
Whether to automatically select the first item when items are loaded.
final
- canGoToNextPage → bool
-
Available on TListController<
Whether there is a next page. For cursor pagination, checks hasMoreItems (from server's hasNextPage). For offset pagination, checks if page < totalPages.T, K> , provided by the TListControllerPagination extensionno setter - canGoToPreviousPage → bool
-
Available on TListController<
Whether there is a previous page. For cursor pagination, checks if there's cursor history. For offset pagination, checks if page > 1.T, K> , provided by the TListControllerPagination extensionno setter - computedItemsPerPage → int
-
Available on TListController<
The computed items per page (adjusted for last page).T, K> , provided by the TListControllerPagination extensionno setter - currentCursor → String?
-
Available on TListController<
Current cursor for cursor-based pagination.T, K> , provided by the TListControllerPagination extensionno setter -
cursorHistory
→ List<
String> -
Available on TListController<
Cursor history stack for backward navigation.T, K> , provided by the TListControllerPagination extensionno setter -
displayItemKeys
→ List<
K> -
Keys of currently displayed items.
no setter
-
displayItems
→ List<
TListItem< T, K> > -
List of currently displayed items (paginated/filtered).
no setter
- editingItemKey → K?
-
Available on TListController<
Key of the item currently being edited.T, K> , provided by the TListControllerDetailExpansion extensionno setter - expandable → bool
-
Available on TListController<
Whether tree node expansion is enabled.T, K> , provided by the TListControllerExpansion extensionno setter - expandedCount → int
-
Available on TListController<
The number of expanded tree items.T, K> , provided by the TListControllerExpansion extensionno setter - expandedDetailKey → K?
-
Available on TListController<
Key of the currently expanded detail content item.T, K> , provided by the TListControllerDetailExpansion extensionno setter -
expandedItems
→ List<
T> -
Available on TListController<
List of expanded data items.T, K> , provided by the TListControllerItems extensionno setter -
expandedKeys
→ UnmodifiableSetView<
K> -
The set of expanded tree parent item keys.
no setter
- expansionInfo → String
-
Available on TListController<
Human-readable expansion information.T, K> , provided by the TListControllerExpansion extensionno setter - expansionMode → TExpansionMode
-
The expansion mode for hierarchical lists.
final
- expansionTristate → bool?
-
Available on TListController<
Tristate expansion value (true/null/false).T, K> , provided by the TListControllerExpansion extensionno setter -
flatItems
→ List<
T> -
Available on TListController<
Flat list of all item data values (across all levels).T, K> , provided by the TListControllerItems extensionno setter - hasError → bool
-
no setter
- hasExpandedContent → bool
-
Available on TListController<
Whether any row detail content is currently expanded.T, K> , provided by the TListControllerDetailExpansion extensionno setter - hasExpansion → bool
-
Available on TListController<
Whether any tree items are expanded.T, K> , provided by the TListControllerExpansion extensionno setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- hasMoreItems → bool
-
Available on TListController<
Whether there are more items to load.T, K> , provided by the TListControllerPagination extensionno setter - hasMultipleSelection → bool
-
Available on TListController<
Whether multiple items are selected.T, K> , provided by the TListControllerSelection extensionno setter - hasSelection → bool
-
Available on TListController<
Whether any items are selected.T, K> , provided by the TListControllerSelection extensionno setter - isAllExpanded → bool
-
Available on TListController<
Whether all tree items are expanded.T, K> , provided by the TListControllerExpansion extensionno setter - isAllSelected → bool
-
Available on TListController<
Whether all items are selected.T, K> , provided by the TListControllerSelection extensionno setter - isCursorPagination → bool
-
Available on TListController<
T, K> , provided by the TListControllerPagination extensionno setter - isEmpty → bool
-
Available on TListController<
Whether the display list is empty.T, K> , provided by the TListControllerItems extensionno setter - isFetching → bool
-
no setter
- isFirstPage → bool
-
Available on TListController<
Whether this is the first page.T, K> , provided by the TListControllerPagination extensionno setter - isHierarchical → bool
-
no setter
- isLastPage → bool
-
Available on TListController<
Whether this is the last page.T, K> , provided by the TListControllerPagination extensionno setter - isLoading → bool
-
no setter
- isMultiSelect → bool
-
Available on TListController<
Whether multiple selection is enabled.T, K> , provided by the TListControllerSelection extensionno setter - isNotEmpty → bool
-
Available on TListController<
Whether the display list is not empty.T, K> , provided by the TListControllerItems extensionno setter - isServerSide → bool
-
Whether this controller uses server-side data loading.
final
-
itemChildren
→ ItemChildrenAccessor<
T> ? -
Function to extract child items for hierarchical lists.
final
-
itemKey
→ ItemKeyAccessor<
T, K> -
Function to extract a unique key from an item.
final
-
itemsMap
→ Map<
K, TListItem< T, K> > -
Available on TListController<
Map of all items by key.T, K> , provided by the TListControllerItems extensionno setter - itemsPerPage → int
-
Available on TListController<
The number of items per page.T, K> , provided by the TListControllerPagination extensionno setter -
itemToString
→ ItemToString<
T> -
Function to convert an item to a string for search filtering.
final
- loadOnSearchOnly → bool
-
Whether to only load data when a search query is present.
final
-
localItems
→ List<
T> -
Available on TListController<
The items available for local pagination.T, K> , provided by the TListControllerItems extensionno setter - mounted → bool
-
no setter
- nextCursor → String?
-
Available on TListController<
Next cursor for cursor-based pagination.T, K> , provided by the TListControllerPagination extensionno setter -
onLoad
→ TLoadListener<
T> ? -
Callback for loading data from a server.
final
- onReorder → void Function(int oldIndex, int newIndex)?
-
Callback fired when items are reordered.
final
- page → int
-
Available on TListController<
The current page number (1-indexed).T, K> , provided by the TListControllerPagination extensionno setter - pageEndedAt → int
-
Available on TListController<
The ending index of the current page.T, K> , provided by the TListControllerPagination extensionno setter - pageStartedAt → int
-
Available on TListController<
The starting index of the current page.T, K> , provided by the TListControllerPagination extensionno setter - paginationInfo → String
-
Available on TListController<
Human-readable pagination information. For cursor pagination (when totalItems is 0 or unavailable), shows current page info. For offset pagination, shows range and total.T, K> , provided by the TListControllerPagination extensionno setter - reorderable → bool
-
Whether items can be reordered.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selectable → bool
-
Available on TListController<
Whether selection is enabled.T, K> , provided by the TListControllerSelection extensionno setter - selectedCount → int
-
Available on TListController<
The number of selected items.T, K> , provided by the TListControllerSelection extensionno setter -
selectedItems
→ List<
T> -
Available on TListController<
List of selected data items.T, K> , provided by the TListControllerItems extensionno setter -
selectedKeys
→ UnmodifiableSetView<
K> -
The set of selected item keys.
no setter
- selectionInfo → String
-
Available on TListController<
Human-readable selection information.T, K> , provided by the TListControllerSelection extensionno setter - selectionMode → TSelectionMode
-
The selection mode for the list.
final
- selectionTristate → bool?
-
Available on TListController<
Tristate selection value (true/null/false).T, K> , provided by the TListControllerSelection extensionno setter - totalDisplayItems → int
-
Available on TListController<
The number of items currently displayed.T, K> , provided by the TListControllerPagination extensionno setter - totalItems → int
-
Available on TListController<
The total number of items.T, K> , provided by the TListControllerPagination extensionno setter - totalPages → int
-
Available on TListController<
The total number of pages.T, K> , provided by the TListControllerPagination extensionno setter -
value
↔ TListState<
T, K> -
The current value stored in this notifier.
getter/setter pairinherited
Methods
-
addItem(
T item, {K? parentKey, bool prepend = true}) → void -
Available on TListController<
Adds a single item.T, K> , provided by the TListControllerItems extension -
addItems(
List< T> newItems, {K? parentKey, bool prepend = true}) → void -
Available on TListController<
Adds multiple items.T, K> , provided by the TListControllerItems extension -
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
beginCreateItem(
{bool clearEditingItem = true}) → void -
Available on TListController<
Puts the list into a state ready to create a new item.T, K> , provided by the TListControllerActions extension -
beginEditItem(
T item) → void -
Available on TListController<
Puts the list into a state ready to edit an item.T, K> , provided by the TListControllerActions extension -
beginEditItemKey(
K key) → void -
Available on TListController<
Puts the list into a state ready to edit an item key.T, K> , provided by the TListControllerActions extension -
bindAsync(
WidgetRef ref, ProviderListenable< AsyncValue< provider) → voidList< >T> > -
Available on TListController<
T, K> , provided by the TListControllerRiverpod extension -
bindAsyncMap<
S> (WidgetRef ref, ProviderListenable< AsyncValue< provider, {required List<S> >T> map(S v)}) → void -
Available on TListController<
T, K> , provided by the TListControllerRiverpod extension -
cancelCreateItem(
) → void -
Available on TListController<
Cancels the create item state.T, K> , provided by the TListControllerActions extension -
cancelEditItem(
) → void -
Available on TListController<
Cancels the edit item state.T, K> , provided by the TListControllerActions extension -
cancelPendingOperations(
) → void -
Available on TListController<
Cancels all pending debouncer timers and network requests.T, K> , provided by the TListControllerActions extension -
canExpand(
K key) → bool -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
clear(
) → void -
Available on TListController<
Clears all items and resets state.T, K> , provided by the TListControllerItems extension -
clearAdditionalState(
) → void -
Available on TListController<
Clears the additional state and notifies listeners.T, K> , provided by the TListControllerActions extension -
clearError(
) → void -
Available on TListController<
Clears any error state.T, K> , provided by the TListControllerActions extension -
clearSelection(
) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
collapse(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
collapseAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
collapseDetail(
) → void -
Available on TListController<
Collapses expanded detail content.T, K> , provided by the TListControllerDetailExpansion extension -
computeItemsPerPageOptions(
List< int> options) → List<int> -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
copyKeySet(
Iterable< K> keys) → LinkedHashSet<K> -
createEmptyKeySet(
) → LinkedHashSet< K> -
deselect(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
dispose(
) → void -
Discards any resources used by the object.
override
-
expand(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
expandAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
expandDetail(
K key, {Map< String, dynamic> ? additional, bool clearEditingItem = true}) → void -
Available on TListController<
Expands detail content for a specific item key. Automatically clears any active edit item key, ensuring only one view/edit mode is active.T, K> , provided by the TListControllerDetailExpansion extension -
expandKeys(
Iterable< K> keys) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
getAncestorsOfKey(
K key) → List< K> - Retrieves all ancestor item keys for a given item key in tree hierarchy.
-
getChildren(
T item) → List< T> ? - Safely retrieves child items for an item using itemChildren.
-
getDescendantsOfKey(
K key) → Set< K> - Retrieves all descendant item keys for a given item key in tree hierarchy.
-
getItem(
K key) → TListItem< T, K> ? - Retrieves a TListItem by key, or null if not found.
-
getItems(
Iterable< K> keys) → List<T> -
Available on TListController<
Retrieves a list of items corresponding to the provided keys.T, K> , provided by the TListControllerItems extension -
getOrRegisterItem(
T item) → TListItem< T, K> -
Available on TListController<
Safely retrieves an item fromT, K> , provided by the TListControllerItems extension_itemsMapor registers it if not present. -
goToFirstPage(
) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
goToLastPage(
) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
goToNextPage(
) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
goToPreviousPage(
) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
handleAdvancedSearchChange(
Map< String, dynamic> filters) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
handleAsyncValue(
AsyncValue< List< next) → voidT> > -
Available on TListController<
T, K> , provided by the TListControllerRiverpod extension -
handleAsyncValueMap<
S> (AsyncValue< S> next, List<T> map(S v)) → void -
Available on TListController<
T, K> , provided by the TListControllerRiverpod extension -
handleError(
TListError error) → void -
Available on TListController<
Sets an error state on the list.T, K> , provided by the TListControllerActions extension -
handleItemsPerPageChange(
int newItemsPerPage) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
handleLoadMore(
) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
handlePageChange(
int newPage) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
handleRefresh(
) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
handleSearchChange(
String search) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
handleSearchImmediate(
String search) → void -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
isDetailExpanded(
K key) → bool -
Available on TListController<
T, K> , provided by the TListControllerDetailExpansion extension -
isExpanded(
K key) → bool -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
isSelected(
K key) → bool -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
itemFactory(
T data, {K? parentKey, List< K> ? childrenKeys, int level = 0}) → TListItem<T, K> - The single canonical factory for creating a TListItem from raw data.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
registerItem(
T item) → void -
Available on TListController<
Registers an item in the items map if not already present.T, K> , provided by the TListControllerItems extension -
removeItem(
T item) → void -
Available on TListController<
Removes a specific item.T, K> , provided by the TListControllerItems extension -
removeItemByKey(
K key) → void -
Available on TListController<
Removes an item by key.T, K> , provided by the TListControllerItems extension -
removeItems(
List< T> items) → void -
Available on TListController<
Removes multiple items.T, K> , provided by the TListControllerItems extension -
removeItemsByKeys(
Set< K> keys) → void -
Available on TListController<
Removes multiple items by keys.T, K> , provided by the TListControllerItems extension -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
removeSelectedItems(
) → void -
Available on TListController<
Removes all currently selected items.T, K> , provided by the TListControllerItems extension -
reorder(
int oldIndex, int newIndex) → void -
Available on TListController<
Reorders items in the list.T, K> , provided by the TListControllerItems extension -
select(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
selectAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
selectKeys(
Iterable< K> keys) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
setAdditionalState(
String key, dynamic value) → void -
Available on TListController<
Sets a value in the additional state and notifies listeners if it changed.T, K> , provided by the TListControllerActions extension -
toggleContentKey(
K key, {Map< String, dynamic> ? additional}) → void -
Available on TListController<
Toggles detail content expansion for a specific item key.T, K> , provided by the TListControllerDetailExpansion extension -
toggleExpandAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
toggleExpansion(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
toggleSelectAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
toggleSelection(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
toString(
) → String -
A string representation of this object.
inherited
-
updateError(
Object e, StackTrace st) → void -
Available on TListController<
Helper to wrap exception and stacktrace into a TListError.T, K> , provided by the TListControllerActions extension -
updateExpansionState(
LinkedHashSet< K> expandedKeys) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
updateItem(
T oldItem, T newItem) → void -
Available on TListController<
Updates an existing item by value equality on its key.T, K> , provided by the TListControllerItems extension -
updateItemByKey(
K key, T newItem) → void -
Available on TListController<
Updates an item by its key.T, K> , provided by the TListControllerItems extension -
updateItems(
List< T> items, {bool append = false}) → void -
Available on TListController<
Updates the entire list of items.T, K> , provided by the TListControllerItems extension -
updateLoading(
) → void -
Available on TListController<
Puts the list into a loading state.T, K> , provided by the TListControllerActions extension -
updateSelectionState(
LinkedHashSet< K> newSelectedKeys) → void -
Available on TListController<
Replaces the entire selected key set withT, K> , provided by the TListControllerSelection extensionnewSelectedKeys. -
updateState(
{required String who, LinkedHashSet< K> ? selectedKeys, LinkedHashSet<K> ? expandedKeys, List<TListItem< ? displayItems, K? expandedDetailKey, bool clearExpandedDetail = false, K? editingItemKey, bool clearEditingItem = false, int? page, int? itemsPerPage, int? totalItems, bool? loading, bool? fetching, bool? hasMoreItems, bool? isCreatingItem, String? search, TSelectionMode? selectionMode, TExpansionMode? expansionMode, TListError? error, String? currentCursor, String? nextCursor, List<T, K> >String> ? cursorHistory, Map<String, dynamic> ? advancedSearch, Map<String, dynamic> ? additional}) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
defaultItemKey<
T, K> (T item) → K
Constants
-
allowedKeyTypes
→ const List<
Type>