DirectoryTreeController<T> constructor
DirectoryTreeController<T> ({
- DirectoryTree<
T> ? tree, - ExpansionState expansion = const ExpansionState.collapsed(),
- SelectionState selection = const SelectionState.empty(mode: SelectionMode.multiple),
- SelectionState checks = const SelectionState.empty(mode: SelectionMode.multiple),
- bool selectable(
- TreeNode<
T> node
- TreeNode<
- String query = '',
- bool caseSensitiveQuery = false,
- TreeFilter? filter,
- bool revealMatches = true,
- bool compactFolders = false,
- bool showRoots = true,
- DirectoryChildrenLoader<
T> ? loadChildren, - DirectoryLoadErrorCallback? onLoadError,
Creates a controller for tree (an empty tree when null).
expansionis the initial requested expansion; every directory starts collapsed by default. With an activequeryorfilter, the rows show it plus the ancestors of the matches.selectionandchecksare the initial highlight selection and checkbox state, both in SelectionMode.multiple by default. Ids thattreedoes not contain are dropped, and a selected directory inside a compacted chain is stored as the chain's deepest directory, asselectionsays.selectabledecides which nodes the selection commands may select; every node by default. It does not affectchecks. It must be pure and cheap, since selectAll and extendSelection call it per row.query,caseSensitiveQuery,filter, andrevealMatches: see the properties of the same names.- compactFolders and showRoots: see the properties of the same names.
loadChildrenmakes directories without children lazily loadable; see DirectoryChildrenLoader.onLoadErroris told about failed loads (see DirectoryLoadErrorCallback).
With a loader and showRoots false, every top-level directory without children starts loading right away.
Implementation
DirectoryTreeController({
DirectoryTree<T>? tree,
ExpansionState expansion = const ExpansionState.collapsed(),
SelectionState selection = const SelectionState.empty(
mode: SelectionMode.multiple,
),
SelectionState checks = const SelectionState.empty(
mode: SelectionMode.multiple,
),
this._selectable,
String query = '',
bool caseSensitiveQuery = false,
TreeFilter? filter,
bool revealMatches = true,
this._compactFolders = false,
this._showRoots = true,
DirectoryChildrenLoader<T>? loadChildren,
this._onLoadError,
}) : _tree = tree ?? DirectoryTree<T>.empty(),
_requested = expansion,
_query = query,
_caseSensitiveQuery = caseSensitiveQuery,
_filter = filter,
_revealMatches = revealMatches,
_loader = loadChildren {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
_selection = selection.prune(_tree);
_checks = checks.prune(_tree);
_parsedQuery = _parseQuery(query, caseSensitive: caseSensitiveQuery);
_effectiveFilter = _combineFilters(_parsedQuery, filter);
_rows = _flatten(
expansion,
expandMatches: _effectiveFilter != null && revealMatches,
);
_lastRowsChange = const TreeRowsChange.reset(previous: null);
_selectChainEnds();
_loadHiddenRoots();
// Nobody listens yet, so the statuses set above need no notification.
_dirty = false;
}