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(
items: response.users,
totalItems: 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, ListItemFactory<T, K> ? itemFactory, ItemChildrenAccessor<T> ? itemChildren, bool reorderable = false, void onReorder(int oldIndex, int newIndex)?}) - Creates a list controller.
Properties
- canGoToNextPage → bool
-
Available on TListController<
Whether there is a next page.T, K> , provided by the TListControllerPagination extensionno setter - canGoToPreviousPage → bool
-
Available on TListController<
Whether there is a previous page.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 - expandable → bool
-
Available on TListController<
Whether expansion is enabled.T, K> , provided by the TListControllerExpansion extensionno setter - expandedCount → int
-
Available on TListController<
The number of expanded items.T, K> , provided by the TListControllerExpansion extensionno setter -
expandedItems
→ List<
T> -
Available on TListController<
The list of expanded items.T, K> , provided by the TListControllerExpansion extensionno setter -
expandedKeys
→ LinkedHashSet<
K> -
Available on TListController<
The set of expanded item keys.T, K> , provided by the TListControllerExpansion extensionno 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
-
flatItems
→ List<
T> -
Available on TListController<
List of all items (flattened).T, K> , provided by the TListControllerItems extensionno setter - hasError → bool
-
no setter
- hasExpansion → bool
-
Available on TListController<
Whether any 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 - hasMultipleExpansion → bool
-
Available on TListController<
Whether multiple items are expanded.T, K> , provided by the TListControllerExpansion 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 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 - isEmpty → bool
-
Available on TListController<
Whether the display list is empty.T, K> , provided by the TListControllerItems extensionno 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
- isSomeExpanded → bool
-
Available on TListController<
Whether some (but not all) items are expanded.T, K> , provided by the TListControllerExpansion extensionno setter - isSomeSelected → bool
-
Available on TListController<
Whether some (but not all) items are selected.T, K> , provided by the TListControllerSelection extensionno setter -
itemChildren
→ ItemChildrenAccessor<
T> ? -
Function to extract child items for hierarchical lists.
final
-
itemFactory
→ ListItemFactory<
T, K> -
Factory function to create list items.
final
-
itemKey
→ ItemKeyAccessor<
T, K> -
Function to extract a unique key from an item.
final
-
itemsMap
→ Map<
K, T> -
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
-
listItemKeys
→ List<
K> -
Available on TListController<
Keys of currently displayed items.T, K> , provided by the TListControllerItems extensionno setter -
listItems
→ List<
TListItem< T, K> > -
Available on TListController<
List of currently displayed items (paginated/filtered).T, K> , provided by the TListControllerItems extensionno setter -
localItems
→ List<
T> -
Available on TListController<
The items available for local pagination.T, K> , provided by the TListControllerItems extensionno setter - mounted → bool
-
no 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.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<
The list of selected items.T, K> , provided by the TListControllerSelection extensionno setter -
selectedKeys
→ LinkedHashSet<
K> -
Available on TListController<
The set of selected item keys.T, K> , provided by the TListControllerSelection extensionno 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, [bool prepend = true]) → void -
Available on TListController<
Adds a single item.T, K> , provided by the TListControllerItems extension -
addItems(
List< T> newItems, {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
-
cancelPendingOperations(
) → void -
clear(
) → void -
Available on TListController<
Clears all items and resets state.T, K> , provided by the TListControllerItems extension -
clearError(
) → void -
clearSelection(
) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
collapseAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
collapseItem(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
collapseItemKey(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
computeItemsPerPageOptions(
List< int> options) → List<int> -
Available on TListController<
T, K> , provided by the TListControllerPagination extension -
deselectItem(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
deselectItemKey(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
expandAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
expandItem(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
expandItemKey(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
expandItemKeys(
Iterable< K> keys) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
expandItems(
Iterable< T> items) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
getItemsFromKeys(
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 -
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 -
handleError(
TListError error) → void -
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 -
isItemExpanded(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
isItemKeyExpanded(
K key) → bool -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
isItemKeySelected(
K key) → bool -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
isItemSelected(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
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 -
selectAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
selectItem(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
selectItemKey(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
selectItemKeys(
Iterable< K> keys) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
selectItems(
Iterable< T> items) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
toggleExpandAll(
) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
toggleExpansion(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
toggleExpansionByKey(
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(
T item) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
toggleSelectionByKey(
K key) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
toString(
) → String -
A string representation of this object.
inherited
-
updateExpansionState(
LinkedHashSet< K> expandedKeys) → void -
Available on TListController<
T, K> , provided by the TListControllerExpansion extension -
updateItem(
T oldItem, T item) → void -
Available on TListController<
Updates an existing item.T, K> , provided by the TListControllerItems extension -
updateItemByKey(
K key, T item) → void -
Available on TListController<
Updates an item by its key.T, K> , provided by the TListControllerItems extension -
updateItems(
List< T> items) → void -
Available on TListController<
Updates the entire list of items.T, K> , provided by the TListControllerItems extension -
updateSelectionState(
LinkedHashSet< K> selectedKeys, {String who = ''}) → void -
Available on TListController<
T, K> , provided by the TListControllerSelection extension -
updateState(
{required String who, LinkedHashSet< K> ? selectedKeys, LinkedHashSet<K> ? expandedKeys, List<TListItem< ? displayItems, int? page, int? itemsPerPage, int? totalItems, bool? loading, bool? hasMoreItems, String? search, TSelectionMode? selectionMode, TExpansionMode? expansionMode, TListError? error}) → voidT, K> >
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
allowedKeyTypes
→ const List<
Type>